2021-04-29 10:08:41 +08:00
|
|
|
// pages/notices/noticedetail.js
|
|
|
|
const app = getApp()
|
|
|
|
Page({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面的初始数据
|
|
|
|
*/
|
|
|
|
data: {
|
2021-07-23 11:18:54 +08:00
|
|
|
noticeContent: '',
|
|
|
|
articleId: '',
|
|
|
|
detailBean: null
|
2021-04-29 10:08:41 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
*/
|
|
|
|
onLoad: function (options) {
|
2021-07-23 11:18:54 +08:00
|
|
|
this.setData({
|
|
|
|
articleId: options.id
|
|
|
|
})
|
|
|
|
this.getArticleDetail()
|
2021-04-29 10:08:41 +08:00
|
|
|
},
|
2021-07-23 11:18:54 +08:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2021-04-29 10:08:41 +08:00
|
|
|
})
|