mini-system-examination-signup/pages/notices/noticedetail.js
2021-07-23 11:18:54 +08:00

52 lines
1.5 KiB
JavaScript

// 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(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, function (match, capture) {
console.log(capture);
return '<img src=' + app.baseUrls.cardUrl + capture + ' style="max-width:100%;height:auto;display:block;margin:10px 0;"/>';
});
return result
} else {
return content
}
}
})