| | |
| | | // 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: '', |
| | | activeId: '', |
| | | storeInfo: '', |
| | | bookId: '', |
| | | bookName: '', |
| | | cmsId: '', |
| | |
| | | pauseTime: 0, //暂停时间 |
| | | applyState: '', |
| | | deadline: '', |
| | | lzoomFlag: false, //定义 缩放事件 节流阀,防止一次缩放触发两次缩放事件 |
| | | distance: 0, //记录手指移动距离 |
| | | scale: 1, //定义初始化的页面缩放大小 |
| | | newScale: 1, //记录新的页面缩放大小 |
| | | }, |
| | | /** |
| | | * 生命周期函数--监听页面加载 |
| | | */ |
| | | onLoad(options) { |
| | | |
| | | wx.setNavigationBarTitle({ |
| | | title: '资源详情' |
| | | }); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | console.log(options); |
| | | const systInfo = wx.getSystemInfoSync(); |
| | | const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息 |
| | | const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度 |
| | | |
| | | this.setData({ |
| | | navBarHeight: navBarHeight, |
| | | barHeight: systInfo.statusBarHeight, |
| | | activeId: options.activeId, |
| | | bookId: options.bookId, |
| | | bookName: options.bookName, |
| | | storeInfo: options.storeInfo, |
| | | cmsId: options.cmsId, |
| | | parentName: options.parentName, |
| | | parentProductLinkPath: options.parentProductLinkPath, |
| | |
| | | applyState: options.applyState, |
| | | deadline: options.deadline |
| | | }) |
| | | const token = wx.getStorageSync(app.config.tokenKey) |
| | | if (!token) { |
| | | loginInfo(app, (data) => { |
| | | if (data) {} else {} |
| | | }) |
| | | } |
| | | this.resourceDetailsData() |
| | | }, |
| | | |
| | |
| | | this.setData({ |
| | | pauseTime: Date.now() |
| | | }) |
| | | if (wx.getStorageSync(app.config.tokenKey) && epubObj.bookBuy) { |
| | | if (wx.getStorageSync(app.config.tokenKey) && epubObj && epubObj.bookBuy) { |
| | | let duration = this.data.pauseTime - this.data.startTime |
| | | this.count(duration) |
| | | } |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面卸载 |
| | |
| | | this.setData({ |
| | | pauseTime: Date.now() |
| | | }) |
| | | if (wx.getStorageSync(app.config.tokenKey) && epubObj.bookBuy) { |
| | | if (wx.getStorageSync(app.config.tokenKey) && epubObj && epubObj.bookBuy) { |
| | | let duration = this.data.pauseTime - this.data.startTime |
| | | this.count(duration) |
| | | } |
| | |
| | | size: 999 |
| | | } |
| | | } |
| | | if (this.data.storeInfo) { |
| | | query.storeInfo = this.data.storeInfo |
| | | } |
| | | app.MG.store.getProductDetail(query).then((res) => { |
| | | console.log(res); |
| | | res.datas.cmsDatas[0].datas.forEach((item) => { |
| | | |
| | | |
| | | |
| | | |
| | | //刚刚进来的时候 |
| | | if (this.data.productLinkPath == item.productLinkPath) { |
| | | this.handleTeachData(item) |
| | | this.setData({ |
| | |
| | | selectType: item.selectType |
| | | }) |
| | | } |
| | | |
| | | |
| | | }) |
| | | }) |
| | | }, |
| | |
| | | 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 (!this.data.deadline == '永久') { |
| | | const flag = new Date(this.data.deadline) > new Date() |
| | | return wx.showToast({ |
| | | icon: 'none', |
| | | title: '请先申请下载', |
| | | }) |
| | | } |
| | | } |
| | | if (!item || !item.file) { |
| | | wx.showToast({ |
| | |
| | | wx.showLoading({ |
| | | title: '正在下载...', |
| | | }); |
| | | |
| | | wx.downloadFile({ |
| | | url: downloadUrl, |
| | | success(res) { |
| | |
| | | console.log(item, 'item11111'); |
| | | if (item.selectType == 'picture') { |
| | | this.setData({ |
| | | |
| | | 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') { |
| | |
| | | webpageSrc: item.jsek_link |
| | | }) |
| | | } |
| | | |
| | | //文档等 |
| | | if (item.selectType == 'pdf' || item.selectType == 'document') { |
| | | app.MG.file.getPdfInfo({ |
| | |
| | | } |
| | | } |
| | | }) |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | }, |
| | | |
| | | |
| | | |
| | | handleTap: function () { |
| | | const naturalResources = this.data.naturalResources; |
| | | 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) { |
| | | let urls = [event.currentTarget.dataset.src] |
| | | wx.previewImage({ |
| | | urls: urls // 需要预览的图片http链接列表 |
| | | }) |
| | | }, |
| | | |
| | | // myTouchStart(e) { |
| | | // //---------------------记录缩放事件信息--------------------- |
| | | // // 当两根手指放上去的时候,将距离(distance)初始化。 |
| | | // let xMove = e.touches[1].clientX - e.touches[0].clientX; |
| | | // let yMove = e.touches[1].clientY - e.touches[0].clientY; |
| | | // //计算开始触发两个手指坐标的距离 |
| | | // const distance = Math.sqrt(xMove * xMove + yMove * yMove); |
| | | // this.setData({ |
| | | // distance: distance |
| | | // }) |
| | | // //---------------------记录缩放事件信息end--------------------- |
| | | // }, |
| | | // myTouchMove(e) { |
| | | // // ----------------监听手势缩小放大事件---------------- |
| | | // // 单手指缩放不做任何操作 |
| | | // if (e.touches.length != 1) { |
| | | // //双手指运动 x移动后的坐标和y移动后的坐标 |
| | | // let xMove = e.touches[1].clientX - e.touches[0].clientX; |
| | | // let yMove = e.touches[1].clientY - e.touches[0].clientY; |
| | | // //双手指运动新的 ditance |
| | | // let newDistance = Math.sqrt(xMove * xMove + yMove * yMove); |
| | | // //计算移动的过程中实际移动了多少的距离 |
| | | // let distanceDiff = newDistance - this.data.distance; |
| | | // // newScale = scale + 0.005 * distanceDiff |
| | | // console.log('移动距离', distanceDiff); |
| | | // this.setData({ |
| | | // newScale: this.data.newScale + 0.005 * distanceDiff |
| | | // }) |
| | | // // 打开缩放监听 |
| | | // // zoomFlag = true |
| | | // this.setData({ |
| | | // lzoomFlag: true |
| | | // }) |
| | | // return |
| | | // } |
| | | // // ----------------监听手势缩小放大事件end---------------- |
| | | // }, |
| | | // myTouchEnd() { |
| | | // if (this.data.lzoomFlag) { |
| | | // if (this.data.newScale > 1.3) { |
| | | // console.log("放大了", this.data.newScale); |
| | | // } else if (this.data.newScale < 0.7, this.data.newScale) { |
| | | // console.log("缩小了"); |
| | | // } |
| | | // // 关闭缩放监听 |
| | | // // zoomFlag = false |
| | | // this.setData({ |
| | | // lzoomFlag: false |
| | | // }) |
| | | // } |
| | | // }, |
| | | }) |