const util = require("../../utils/util"); const app = getApp() Page({ data: { postId:0, info:{}, content:'' }, onLoad: function (options) { let postId = +options.postId||7356; this.setData({postId}) }, onShow: function(){ this.loadData() }, preview( e ){ var imgs = []; let content = this.data.info.content||'' content.replace(/]*src=['"]([^'"]+)[^>]*>/gi, function (match, capture) { imgs.push(capture); }); console.log("url",content, imgs) if( imgs.length > 0 ){ wx.previewImage({ current: imgs[0], urls: imgs }) } }, download( ){ let url = this.data.info.sourceUrl; if( !url ){ util.showModel("下载失败", "无附件内容") return } wx.downloadFile({ url: url, timeout: 0, success: (res) => { var rr=res.tempFilePath; wx.openDocument({ filePath:rr, showMenu: true, success(res) { wx.showToast({ title: '保存成功', icon: 'success', duration: 2000 }) } }) }, fail: (res) => { console.log("res_fail", res) }, complete: (res) => { console.log("res_complete", res) }, }) }, loadData(){ let postId = this.data.postId app.formPost( "Post.getPostInfo", {postId}).then( res=>{ if( res.code == 200 ){ let info = res.data this.setData({info}) } }) }, onReady(res) { this.videoContext = wx.createVideoContext('myVideo') }, onShareAppMessage: function () { let {postId, title} = this.data.info; return { title: title, path: `/pages/post/post?postId=${postId}` } } })