// pages/notices/noticedetail.js
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
noticeContent: '',
articleId: '',
detailBean: null
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
articleId: options.id
})
this.getArticleDetail()
},
getArticleDetail() {
var _self = this
wx.showLoading({
title: '加载中...',
})
app.restAjax.get(app.restAjax.path(app.apis.getArticleDetailById, [app.baseUrls.cardUrl, _self.data.articleId]), {}, {},
(code, data) => {
wx.hideLoading({})
if (code == 200) {
data.content = _self.checkImgSrc(data.content)
_self.setData({
detailBean: data
})
}
}, (code, err) => {
wx.hideLoading({})
})
},
checkImgSrc(content) {
if (content.indexOf('img') != -1) { //判断img是否存在
var result = content.replace(/
]*src=['"]([^'"]+)[^>]*>/gi, function (match, capture) {
console.log(capture);
return '
';
});
return result
} else {
return content
}
}
})