const app = getApp() /** * 守法学习材料的获取和打开 */ module.exports = Behavior({ data: { resources: [], }, methods: { /** * 守法学习材料内容跳转 */ behaviorOpenFile: function (f) { var url = "" switch (f.lrResourcefiletype) { //文档 case 1: let bodyUrl = f.lrBodyurl wx.showLoading({ title: ' 文件下载中', mask: true, }) wx.downloadFile({ url: bodyUrl, success: function (res) { wx.hideLoading() const filePath = res.tempFilePath wx.openDocument({ filePath: filePath, success: function (res) { console.log('打开文档成功') }, fail(error) { console.log(error); } }) } }) break; //链接 case 2: url = "" break; //图片 case 3: url = "" break; //视频 case 4: url = "/pages/m_common/pagevideo/pagevideo" break; } if (url != "") { wx.navigateTo({ url: url, success: (res) => { // 通过 eventChannel 向被打开页面传送数据 res.eventChannel.emit('acceptDataFromOpenerPage', f) }, }) } } } })