// pages/index/resourceCover.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { webpageSrc: "", bookId: 0, bookName: '', cmsId: '', productLinkPath: '', parentProductLinkPath: '', formPath: '' }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { if (options.scene) { this.getBookInfo(options.scene) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, getBookInfo(refcode) { const obj = { storeInfo: app.config.jslx, path: app.config.jslx, queryType: 'ProductCmsItem', SysType: "CmsItem", RefCode: refcode, // CmsItemType: 'jsek_resource', paging: { start: 0, size: 99, }, coverSize: { width: 260 }, fields: { ProductLinkInfo: [], productLinkPath: [], selectType: [], freeFile: [], file: [], protectedFile: [], resourcesClassification: [], isDownload: [], jsek_resourceBrief: [], jsek_link: [], jsek_questionBank: [], learnSelectType: [], } } app.MG.resource.getItem(obj).then((res) => { let book = res.datas.length > 0 ? res.datas[0] : {} console.log(book, '资源信息') let url; if (book.selectType == "video" || book.learnSelectType == "video") { url = "/packageDomain/pages/resourceDetails/myVideo/index"; } else if ( book.selectType == "audio" || book.learnSelectType == "audio" ) { url = "/packageDomain/pages/resourceDetails/myAudio/index"; } else if (book.selectType == "picture") { url = "/packageDomain/pages/resourceDetails/document/index"; } this.setData({ bookId: book.productLinkInfo.ProductId, bookName: book.productLinkInfo.Name, productLinkPath: book.productLinkInfo.LinkPath + "\\" + book.id, parentProductLinkPath: book.productLinkInfo.LinkPath, cmsId: book.id, formPath: book.learnSelectType ? 'jsek_cloudLearning' : '' }) wx.redirectTo({ url: `${url}?productLinkPath=${this.data.productLinkPath}&parentProductLinkPath=${this.data.parentProductLinkPath}&bookId=${book.productLinkInfo.ProductId}&activeId=${book.id}&bookName=${book.productLinkInfo.Name}&cmsId=${book.id}&storeInfo=${book.storeInfo}&formPath=${this.data.formPath}`, }); if (book.selectType == "pdf" || book.selectType == 'document') { const fileLink = book.file ? book.file : book.freeFile console.log(fileLink); wx.redirectTo({ url: "/packageBookService/pages/components/webView/index?md5=" + fileLink + "&fileName=" + book.name + "&fileType=pdf" + "&bookBuy=true" }); } if (book.selectType == 'zip') { const fileLink = book.file ? app.config.requestCtx + "/file/api/ApiDownload?md5=" + book.file : app.config.requestCtx + "/file/api/ApiDownload?md5=" + book.freeFile; console.log(fileLink, "fileLink"); //提示加载中 // 单次下载允许的最大文件为 200MB wx.downloadFile({ url: fileLink, filePath: wx.env.USER_DATA_PATH + `/${book.name}.${book.selectType}`, success: function (res) { console.log(res, "wx.downloadFile success res"); if (res.statusCode != 200) { return false; } } }); } }) }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })