| | |
| | | // pages/resourceDetails/document/index.js |
| | | import Toast from 'tdesign-miniprogram/toast/index'; |
| | | const app = getApp() |
| | | Page({ |
| | | |
| | |
| | | * 页面的初始数据 |
| | | */ |
| | | data: { |
| | | visible: false, |
| | | showIndex: false, |
| | | closeBtn: false, |
| | | deleteBtn: false, |
| | | images: [], |
| | | webpageSrc: '', |
| | | navBarHeight: '', |
| | | barHeight: '', |
| | |
| | | naturalResources: [], |
| | | titleName: '', |
| | | pdfDatA: [], |
| | | startTime: "", //进入页面当前时间 |
| | | pauseTime: 0, //暂停时间 |
| | | applyState: '', |
| | | deadline: '', |
| | | }, |
| | | /** |
| | | * 生命周期函数--监听页面加载 |
| | | */ |
| | | onLoad(options) { |
| | | |
| | | wx.setNavigationBarTitle({ |
| | | title: '资源详情' |
| | | }); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | console.log(options); |
| | | const systInfo = wx.getSystemInfoSync(); |
| | | const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息 |
| | |
| | | cmsId: options.cmsId, |
| | | parentName: options.parentName, |
| | | parentProductLinkPath: options.parentProductLinkPath, |
| | | productLinkPath: options.productLinkPath |
| | | productLinkPath: options.productLinkPath, |
| | | applyState: options.applyState, |
| | | deadline: options.deadline |
| | | }) |
| | | this.resourceDetailsData() |
| | | }, |
| | |
| | | * 生命周期函数--监听页面显示 |
| | | */ |
| | | onShow() { |
| | | |
| | | this.setData({ |
| | | startTime: Date.now() |
| | | }) |
| | | }, |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面隐藏 |
| | | */ |
| | | onHide() { |
| | | |
| | | this.setData({ |
| | | pauseTime: Date.now() |
| | | }) |
| | | if (wx.getStorageSync(app.config.tokenKey) && epubObj.bookBuy) { |
| | | let duration = this.data.pauseTime - this.data.startTime |
| | | this.count(duration) |
| | | } |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面卸载 |
| | | */ |
| | | onUnload() { |
| | | |
| | | this.setData({ |
| | | pauseTime: Date.now() |
| | | }) |
| | | if (wx.getStorageSync(app.config.tokenKey) && epubObj.bookBuy) { |
| | | let duration = this.data.pauseTime - this.data.startTime |
| | | this.count(duration) |
| | | } |
| | | }, |
| | | |
| | | count(timeStr) { |
| | | const data = { |
| | | appRefCode: app.config.appRefCode, |
| | | type: 'LearningTime', //统计类型--阅读时长 |
| | | data: timeStr + '', //统计内容--时长毫秒 |
| | | event: 'LearningTime', |
| | | sysType: 'App' |
| | | } |
| | | //阅读商品的id |
| | | if (this.data.bookId) { |
| | | data.productId = this.data.bookId |
| | | } |
| | | //阅读资源的id |
| | | if (this.data.cmsId) { |
| | | data.cmsItemId = this.data.cmsId |
| | | } |
| | | app.MG.job.newJobWithApiNewEvent(data).then((res) => {}) |
| | | }, |
| | | /** |
| | | * 页面相关事件处理函数--监听用户下拉动作 |
| | | */ |
| | |
| | | //zpi文件下载 |
| | | onDownloadButton() { |
| | | const item = this.data.zipData; |
| | | if (this.data.applyState !== 'Normal') { |
| | | return wx.showToast({ |
| | | icon: 'none', |
| | | title: '请先申请下载', |
| | | }) |
| | | } else { |
| | | const flag = new Date(this.data.deadline) > new Date() |
| | | if (!flag) return wx.showToast({ |
| | | icon: 'none', |
| | | title: '请先申请下载', |
| | | }) |
| | | } |
| | | if (!item || !item.file) { |
| | | wx.showToast({ |
| | | title: '文件信息缺失', |
| | |
| | | }); |
| | | return; |
| | | } |
| | | |
| | | const downloadUrl = app.config.requestCtx + '/file/api/ApiDownload?md5=' + item.file; |
| | | wx.showLoading({ |
| | | title: '正在下载...', |
| | |
| | | //刚进来的时候调用 |
| | | handleTeachData(item) { |
| | | //图片 |
| | | console.log(item, 'item11111'); |
| | | if (item.selectType == 'picture') { |
| | | this.setData({ |
| | | showData: app.config.requestCtx + '/file/api/ApiDownload?md5=' + item.file, |
| | | |
| | | showData: item.file ? app.config.requestCtx + '/file/api/ApiDownload?md5=' + item.file : app.config.requestCtx + '/file/api/ApiDownload?md5=' + item.freeFile, |
| | | |
| | | }) |
| | | console.log(this.data.showData, 'showData'); |
| | | } |
| | | // 下载文件zip |
| | | if (item.selectType == 'zip') { |
| | |
| | | |
| | | //文档等 |
| | | if (item.selectType == 'pdf' || item.selectType == 'document') { |
| | | app.MG.file.getPdfInfo({ md5: item.file }).then((res) => { |
| | | app.MG.file.getPdfInfo({ |
| | | md5: item.file |
| | | }).then((res) => { |
| | | if (res && res.totalPages) { |
| | | for (let i = 0; i < res.totalPages; i++) { |
| | | const src = app.config.requestCtx + '/file/GetPdfPageImage?md5=' + item.file + '&index=' + (i + 1) + '&dpi=300' |
| | |
| | | naturalResources.forEach(function (item) { |
| | | // console.log(item); |
| | | }); |
| | | } |
| | | }, |
| | | |
| | | |
| | | |
| | | onClick() { |
| | | this.setData({ |
| | | images: [ |
| | | this.data.showData, |
| | | // 'https://tdesign.gtimg.com/mobile/demos/swiper2.png', |
| | | ], |
| | | showIndex: true, |
| | | visible: true, |
| | | }); |
| | | }, |
| | | onChange(e) { |
| | | const { |
| | | index |
| | | } = e.detail; |
| | | |
| | | console.log('change', index); |
| | | }, |
| | | |
| | | onDelete(e) { |
| | | const { |
| | | index |
| | | } = e.detail; |
| | | |
| | | Toast({ |
| | | context: this, |
| | | selector: '#t-toast', |
| | | message: `删除第${index + 1}个`, |
| | | }); |
| | | }, |
| | | |
| | | onClose(e) { |
| | | const { |
| | | trigger |
| | | } = e.detail; |
| | | console.log(trigger); |
| | | this.setData({ |
| | | visible: false, |
| | | }); |
| | | }, |
| | | //预览图片,放大预览 |
| | | preview(event) { |
| | | console.log(event.currentTarget.dataset.src) |
| | | let currentUrl = event.currentTarget.dataset.src |
| | | |
| | | wx.previewImage({ |
| | | current: currentUrl, // 当前显示图片的http链接 |
| | | // urls: this.data.showData // 需要预览的图片http链接列表 |
| | | }) |
| | | }, |
| | | |
| | | }) |