| | |
| | | // pages/index/resourceCover.js |
| | | const app = getApp() |
| | | import { |
| | | loginInfo |
| | | } from '../../assets/js/login'; |
| | | Page({ |
| | | |
| | | /** |
| | |
| | | cmsId: '', |
| | | productLinkPath: '', |
| | | parentProductLinkPath: '', |
| | | formPath: '' |
| | | formPath: '', |
| | | copyUrl: '', |
| | | }, |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面加载 |
| | | */ |
| | | onLoad(options) { |
| | | if (options.scene) { |
| | | this.getBookInfo(options.scene) |
| | | const token = wx.getStorageSync(app.config.tokenKey) |
| | | if (!token) { |
| | | loginInfo(app, (data) => { |
| | | // 如果不是第一次登录,会执行回调 |
| | | if (data) { |
| | | if (options.scene) { |
| | | this.getBookInfo(options.scene) |
| | | } |
| | | } |
| | | }) |
| | | } else { |
| | | if (options.scene) { |
| | | this.getBookInfo(options.scene) |
| | | } |
| | | } |
| | | |
| | | }, |
| | | |
| | | /** |
| | |
| | | book.learnSelectType == "audio" |
| | | ) { |
| | | url = "/packageDomain/pages/resourceDetails/myAudio/index"; |
| | | } else if (book.selectType == "picture" || book.selectType == "zip") { |
| | | } else if (book.selectType == "picture") { |
| | | url = "/packageDomain/pages/resourceDetails/document/index"; |
| | | } |
| | | this.setData({ |
| | |
| | | formPath: book.learnSelectType ? 'jsek_cloudLearning' : '' |
| | | }) |
| | | wx.redirectTo({ |
| | | url: `${url}?productLinkPath=${this.data.productLinkPath}&parentProductLinkPath=${this.data.parentProductLinkPath}&bookId=${book.productLinkInfo.ProductId}&bookName=${book.productLinkInfo.Name}&cmsId=${book.id}&storeInfo=${book.storeInfo}&formPath=${this.data.formPath}`, |
| | | 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") { |
| | | if (book.selectType == "pdf" || book.selectType == 'document') { |
| | | const fileLink = book.file ? book.file : book.freeFile |
| | | console.log(fileLink); |
| | | wx.navigateTo({ |
| | | wx.redirectTo({ |
| | | url: "/packageBookService/pages/components/webView/index?md5=" + |
| | | fileLink + |
| | | "&fileName=" + |
| | | book.name + |
| | | "&fileType=" + |
| | | book.selectType + "&bookBuy=true" |
| | | "&fileType=pdf" + "&bookBuy=true" |
| | | }); |
| | | } |
| | | if (book.selectType == 'document') { |
| | | 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"); |
| | | this.setData({ |
| | | copyUrl: fileLink |
| | | }) |
| | | // wx.redirectTo({ |
| | | // url: "/packageBookService/pages/bookServices/webView/index?url=" + 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) { |
| | | util.hideLoadingWithErrorTips(); |
| | | return false; |
| | | } |
| | | var Path = res.tempFilePath; //返回的文件临时地址,用于后面打开本地预览所用 |
| | | let data = res.filePath; |
| | | wx.openDocument({ |
| | | filePath: data, |
| | | showMenu: true, |
| | | success: function (res) { |
| | | console.log("打开成功"); |
| | | util.hideLoading(); |
| | | }, |
| | | }); |
| | | }, |
| | | fail: function (err) { |
| | | console.log(err, "wx.downloadFile fail err"); |
| | | util.hideLoadingWithErrorTips(); |
| | | }, |
| | | }); |
| | | |
| | | } |
| | | }) |
| | | }, |
| | | |
| | | copyUrl(e) { |
| | | |
| | | let url = e.currentTarget.dataset.value |
| | | console.log(url) |
| | | // wx.setClipboardData(url) |
| | | wx.setClipboardData({ |
| | | data: `${e.currentTarget.dataset.value}`, |
| | | success(res) { |
| | | console.log(res.data) // data |
| | | }, |
| | | fail(err) { |
| | | reject(err); |
| | | } |
| | | }) |
| | | }, |
| | | /** |
| | | * 用户点击右上角分享 |
| | | */ |