| | |
| | | // pages/resourceDetails/document/index.js |
| | | import Toast from 'tdesign-miniprogram/toast/index'; |
| | | const app = getApp() |
| | | import { |
| | | loginInfo |
| | | } from '../../../../assets/js/login'; |
| | | Page({ |
| | | |
| | | /** |
| | |
| | | navBarHeight: '', |
| | | barHeight: '', |
| | | activeId: '', |
| | | storeInfo: '', |
| | | bookId: '', |
| | | bookName: '', |
| | | cmsId: '', |
| | | parentName: '', |
| | | parentProductLinkPath: '', |
| | | productLinkPath: '', |
| | | isBuy: false, |
| | | showData: '', |
| | | titleName: '', |
| | | selectType: '', |
| | | learnSelectType: '', |
| | | zipData: '', |
| | | naturalResources: [], |
| | | titleName: '', |
| | | pdfDatA: [], |
| | | startTime: "", //进入页面当前时间 |
| | | pauseTime: 0, //暂停时间 |
| | | formPath: '', |
| | | applyState: '', |
| | | deadline: '', |
| | | lzoomFlag: false, //定义 缩放事件 节流阀,防止一次缩放触发两次缩放事件 |
| | | distance: 0, //记录手指移动距离 |
| | | scale: 1, //定义初始化的页面缩放大小 |
| | | newScale: 1, //记录新的页面缩放大小 |
| | | pdfSrc: '', |
| | | buyIdList: [], |
| | | buyList: [], |
| | | learnClassData: null, |
| | | isLearnDataBuy: false, |
| | | bookDetail: null, |
| | | learnStartTime: 0, |
| | | learnTimeList: [], |
| | | learnTimeData: 0, |
| | | threeLeveData: [] |
| | | }, |
| | | /** |
| | | * 生命周期函数--监听页面加载 |
| | |
| | | wx.setNavigationBarTitle({ |
| | | title: '资源详情' |
| | | }); |
| | | console.log(options); |
| | | const systInfo = wx.getSystemInfoSync(); |
| | | const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息 |
| | | const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度 |
| | |
| | | activeId: options.activeId, |
| | | bookId: options.bookId, |
| | | bookName: options.bookName, |
| | | storeInfo: options.storeInfo, |
| | | cmsId: options.cmsId, |
| | | parentName: options.parentName, |
| | | parentProductLinkPath: options.parentProductLinkPath, |
| | | productLinkPath: options.productLinkPath, |
| | | applyState: options.applyState, |
| | | deadline: options.deadline |
| | | deadline: options.deadline, |
| | | formPath: options.formPath, |
| | | }) |
| | | this.resourceDetailsData() |
| | | const token = wx.getStorageSync(app.config.tokenKey) |
| | | if (!token) { |
| | | loginInfo(app, (data) => { |
| | | if (options.formPath == 'jsek_cloudLearning') { |
| | | this.setData({ |
| | | learnStartTime: Date.now(), |
| | | }) |
| | | this.getLearnTime() |
| | | } |
| | | this.getBookInfo(this.data.bookId) |
| | | // if (data) { |
| | | // this.resourceDetailsData() |
| | | // } else { |
| | | // this.resourceDetailsData() |
| | | // } |
| | | }) |
| | | } else { |
| | | if (options.formPath == 'jsek_cloudLearning') { |
| | | this.setData({ |
| | | learnStartTime: Date.now(), |
| | | }) |
| | | this.getLearnTime() |
| | | } |
| | | this.getBookInfo(this.data.bookId) |
| | | // this.resourceDetailsData() |
| | | } |
| | | }, |
| | | |
| | | /** |
| | |
| | | this.setData({ |
| | | pauseTime: Date.now() |
| | | }) |
| | | if (wx.getStorageSync(app.config.tokenKey) && epubObj && epubObj.bookBuy) { |
| | | if (wx.getStorageSync(app.config.tokenKey)) { |
| | | let duration = this.data.pauseTime - this.data.startTime |
| | | this.count(duration) |
| | | if (this.data.formPath == 'jsek_cloudLearning') { |
| | | let cloudDuration = this.data.pauseTime - this.data.learnStartTime |
| | | this.cloudCount(cloudDuration) |
| | | } |
| | | } |
| | | }, |
| | | |
| | |
| | | this.setData({ |
| | | pauseTime: Date.now() |
| | | }) |
| | | if (wx.getStorageSync(app.config.tokenKey) && epubObj && epubObj.bookBuy) { |
| | | if (wx.getStorageSync(app.config.tokenKey)) { |
| | | let duration = this.data.pauseTime - this.data.startTime |
| | | this.count(duration) |
| | | if (this.data.formPath == 'jsek_cloudLearning') { |
| | | let cloudDuration = this.data.pauseTime - this.data.learnStartTime |
| | | this.cloudCount(cloudDuration) |
| | | } |
| | | } |
| | | }, |
| | | |
| | |
| | | } |
| | | app.MG.job.newJobWithApiNewEvent(data).then((res) => {}) |
| | | }, |
| | | getLearnTime() { |
| | | app.MG.identity |
| | | .getUserKey({ |
| | | domain: 'cloudLearningTime', |
| | | keys: [this.data.bookId] |
| | | }) |
| | | .then((res) => { |
| | | if (res.length > 0) { |
| | | if (JSON.parse(res[0].value) && JSON.parse(res[0].value).length > 0) { |
| | | this.setData({ |
| | | learnTimeList: JSON.parse(res[0].value), |
| | | learnTimeData: JSON.parse(res[0].value)[0].learnTime, |
| | | }) |
| | | } else { |
| | | this.setData({ |
| | | learnTimeList: [], |
| | | learnTimeData: 0 |
| | | }) |
| | | } |
| | | } |
| | | }) |
| | | }, |
| | | cloudCount(timeStr) { |
| | | let time = Number(this.data.learnTimeData) + Number(timeStr) |
| | | this.setData({ |
| | | learnTimeList: [{ |
| | | learnTime: time |
| | | }], |
| | | }) |
| | | app.MG.identity |
| | | .setUserKey({ |
| | | setKeyRequests: [{ |
| | | domain: 'cloudLearningTime', |
| | | key: this.data.bookId, |
| | | value: JSON.stringify(this.data.learnTimeList) |
| | | }] |
| | | }) |
| | | .then((res) => { |
| | | console.log(timeStr, '学习时长') |
| | | }) |
| | | }, |
| | | /** |
| | | * 页面相关事件处理函数--监听用户下拉动作 |
| | | */ |
| | |
| | | /** |
| | | * 页面上拉触底事件的处理函数 |
| | | */ |
| | | onReachBottom() { |
| | | |
| | | }, |
| | | onReachBottom() {}, |
| | | |
| | | /** |
| | | * 用户点击右上角分享 |
| | | */ |
| | | onShareAppMessage() { |
| | | |
| | | }, |
| | | onShareAppMessage() {}, |
| | | onShareTimeline() {}, |
| | | goBack() { |
| | | wx.navigateBack() |
| | | }, |
| | | |
| | | // 获取图书详情 |
| | | getBookInfo(id) { |
| | | const query = { |
| | | path: "*", |
| | | queryType: "*", |
| | | productId: id, |
| | | favoriteTypes: "FavoriteBookCity", |
| | | itemFields: { |
| | | "SysType=": "CmsFolder", |
| | | }, |
| | | coverSize: { |
| | | height: 1, |
| | | }, |
| | | fields: {}, |
| | | }; |
| | | if (this.data.storeInfo) query['storeInfo'] = this.data.storeInfo |
| | | app.MG.store.getProductDetail(query).then(async (res) => { |
| | | try { |
| | | this.setData({ |
| | | bookDetail: res.datas, |
| | | buyIdList: res.datas.purchasedSaleMethodIdList, |
| | | learnClassData: res.datas.cmsDatas[0].datas.length > 0 ? res.datas.cmsDatas[0].datas.find(item => item.refCode == "jsek_cloudLearning") : null |
| | | }) |
| | | } catch (error) {} |
| | | if (this.data.learnClassData) { |
| | | this.getResourceDataList(this.data.learnClassData) |
| | | } else { |
| | | this.resourceDetailsData() |
| | | } |
| | | }); |
| | | }, |
| | | // 教学资源 云学习 获取 |
| | | getResourceDataList(type) { |
| | | let query = { |
| | | path: '*', |
| | | queryType: '*', |
| | | productId: this.data.bookDetail.id, |
| | | cmsPath: type.productLinkPath, |
| | | cmsType: '*', |
| | | itemFields: { |
| | | SysType: 'CmsFolder', |
| | | }, |
| | | pading: { |
| | | start: 0, |
| | | size: 999 |
| | | }, |
| | | } |
| | | app.MG.store.getProductDetailNoChildren(query).then((res) => { |
| | | const buyList = res.datas.cmsDatas[0].datas.filter(item => item.saleMethod.length && this.data.buyIdList.includes(item.saleMethod.find(citem => citem.SaleType == 'Normal').Id)) |
| | | if (this.data.learnClassData && this.data.learnClassData.saleMethod.length) { |
| | | const learnSaleMethod = this.data.learnClassData.saleMethod.find(citem => citem.SaleType == 'Normal') |
| | | if (this.data.buyIdList.includes(learnSaleMethod.Id)) { |
| | | buyList.push(this.data.learnClassData) |
| | | } else { |
| | | if (new Date().getTime() > new Date(learnSaleMethod.EndDate).getTime() || learnSaleMethod.Price == 0) { |
| | | this.setData({ |
| | | isLearnDataBuy: true |
| | | }) |
| | | } else { |
| | | this.setData({ |
| | | isLearnDataBuy: false |
| | | }) |
| | | } |
| | | } |
| | | } else { |
| | | this.setData({ |
| | | isLearnDataBuy: true |
| | | }) |
| | | } |
| | | this.setData({ |
| | | buyList: buyList |
| | | }) |
| | | this.resourceDetailsData() |
| | | }) |
| | | }, |
| | | |
| | | resourceDetailsData() { |
| | | wx.showLoading({ |
| | | title: '正在加载...', |
| | | }); |
| | | let query = { |
| | | path: '*', |
| | | queryType: '*', |
| | |
| | | size: 999 |
| | | } |
| | | } |
| | | if (this.data.storeInfo) { |
| | | query.storeInfo = this.data.storeInfo |
| | | } |
| | | app.MG.store.getProductDetail(query).then((res) => { |
| | | console.log(res); |
| | | this.setData({ |
| | | isBuy: res.datas.purchasedSaleMethodIdList.includes(res.datas.defaultSaleMethodId) |
| | | }) |
| | | res.datas.cmsDatas[0].datas.forEach((item) => { |
| | | if (this.data.productLinkPath == item.productLinkPath) { |
| | | this.handleTeachData(item) |
| | | this.setData({ |
| | | titleName: item.name, |
| | | selectType: item.selectType |
| | | }) |
| | | // if (this.data.productLinkPath == item.productLinkPath) { |
| | | // this.handleTeachData(item) |
| | | // this.setData({ |
| | | // titleName: item.name, |
| | | // selectType: item.selectType, |
| | | // learnSelectType: item.learnSelectType |
| | | // }) |
| | | // } else { |
| | | // return wx.showToast({ |
| | | // icon: 'none', |
| | | // title: '暂无资源', |
| | | // }) |
| | | // } |
| | | if (this.data.storeInfo == 'jsek_digitalCourses') { |
| | | if (this.data.isBuy) { |
| | | if (this.data.productLinkPath == item.productLinkPath) { |
| | | this.data.threeLeveData.push(item) |
| | | } |
| | | } else { |
| | | if (this.data.productLinkPath == item.productLinkPath && item.freeFile) { |
| | | this.data.threeLeveData.push(item) |
| | | } |
| | | } |
| | | } else { |
| | | // 买了 |
| | | if (this.data.buyList.length) { |
| | | if (this.data.buyList.some(citem => item.productLinkPath.includes(citem.productLinkPath))) { |
| | | if (this.data.productLinkPath == item.productLinkPath) { |
| | | this.data.threeLeveData.push(item) |
| | | } |
| | | } |
| | | } else { |
| | | if (!item.saleMethod.length) { |
| | | // 没买且无销售方式 |
| | | if (this.data.productLinkPath == item.productLinkPath) { |
| | | this.data.threeLeveData.push(item) |
| | | } |
| | | } else { |
| | | // 没买且销售方式过期//没买,销售方式价格为0 |
| | | const itemSaleMethod = item.saleMethod.find(citem => citem.SaleType == 'Normal') |
| | | if (new Date().getTime() > new Date(itemSaleMethod.EndDate).getTime() || itemSaleMethod.Price == 0) { |
| | | if (this.data.productLinkPath == item.productLinkPath) { |
| | | this.data.threeLeveData.push(item) |
| | | } |
| | | } |
| | | // 没买且只有试读资源 |
| | | if (!item.file && item.freeFile) { |
| | | if (this.data.productLinkPath == item.productLinkPath) { |
| | | this.data.threeLeveData.push(item) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }) |
| | | if (this.data.source == 'qrcode') { |
| | | let qrData = this.data.threeLeveData.find(ditem => ditem.id == this.data.activeId) |
| | | if (qrData && this.data.isLearnDataBuy) { |
| | | if (qrData) { |
| | | this.setData({ |
| | | threeLeveData: [qrData] |
| | | }) |
| | | } |
| | | } else { |
| | | this.setData({ |
| | | threeLeveData: [] |
| | | }) |
| | | } |
| | | } else { |
| | | this.setData({ |
| | | threeLeveData: this.data.threeLeveData |
| | | }) |
| | | } |
| | | if (this.data.threeLeveData.length > 0) { |
| | | let item = this.data.threeLeveData[0] |
| | | this.handleTeachData(item) |
| | | this.setData({ |
| | | titleName: item.name, |
| | | selectType: item.selectType, |
| | | learnSelectType: item.learnSelectType, |
| | | }) |
| | | } else { |
| | | wx.showToast({ |
| | | icon: 'none', |
| | | title: '请先返回资源所在图书详情购买视频资源', |
| | | }) |
| | | wx.navigateTo({ |
| | | url: `/packageBookService/pages/bookServices/detail/index?id=${this.data.bookDetail.id}&name=${this.data.bookDetail.name}&tabValue=jsek_cloudLearning`, |
| | | }); |
| | | } |
| | | }) |
| | | }, |
| | | //zpi文件下载 |
| | |
| | | }) |
| | | } |
| | | } |
| | | if (!item || !item.file) { |
| | | if (!item || !item.file || !item.protectedFile) { |
| | | wx.showToast({ |
| | | title: '文件信息缺失', |
| | | icon: 'none' |
| | | }); |
| | | return; |
| | | } |
| | | const downloadUrl = app.config.requestCtx + '/file/api/ApiDownload?md5=' + item.file; |
| | | let file = item.file ? item.file : item.protectedFile |
| | | const downloadUrl = app.config.requestCtx + '/file/api/ApiDownload?md5=' + file; |
| | | wx.showLoading({ |
| | | title: '正在下载...', |
| | | }); |
| | |
| | | }, |
| | | //刚进来的时候调用 |
| | | handleTeachData(item) { |
| | | |
| | | //图片 |
| | | console.log(item, 'item11111'); |
| | | if (item.selectType == 'picture') { |
| | | if (item.selectType == 'picture' || item.learnSelectType == 'picture') { |
| | | let file = item.file ? item.file : item.protectedFile ? item.protectedFile : item.freeFile |
| | | this.setData({ |
| | | showData: item.file ? app.config.requestCtx + '/file/api/ApiDownload?md5=' + item.file : app.config.requestCtx + '/file/api/ApiDownload?md5=' + item.freeFile, |
| | | showData: app.config.requestCtx + '/file/api/ApiDownload?md5=' + file, |
| | | }) |
| | | console.log(this.data.showData, 'showData'); |
| | | wx.hideLoading(); |
| | | } |
| | | // 下载文件zip |
| | | if (item.selectType == 'zip') { |
| | | if (item.selectType == 'zip' || item.learnSelectType == 'zip') { |
| | | this.setData({ |
| | | zipData: item |
| | | }) |
| | | wx.hideLoading(); |
| | | } |
| | | //网页 |
| | | if (item.selectType == 'webpage') { |
| | | if (item.selectType == 'webpage' || item.learnSelectType == 'webpage') { |
| | | this.setData({ |
| | | webpageSrc: item.jsek_link |
| | | }) |
| | | wx.hideLoading(); |
| | | } |
| | | // if (item.selectType == 'pdf') { |
| | | // console.log('pdf', item); |
| | | // wx.hideLoading() |
| | | // let md5 = item.file ? item.file : item.freeFile |
| | | // let pdfSrc = app.config.pdfUrl + "?MD5=" + md5 + "&url=" + app.config.requestCtx + '¤tPage=' + "1" + "&isPreview=" + false + "&warterMark=" + "北京师范大学出版社" + "&previewPages=" + 30 + "&token=" + wx.getStorageSync(app.config.tokenKey) |
| | | // this.setData({ |
| | | // pdfSrc: pdfSrc |
| | | // }) |
| | | // } |
| | | //文档等 |
| | | if (item.selectType == 'pdf' || item.selectType == 'document') { |
| | | if (item.selectType == 'document' || item.selectType == 'pdf' || item.learnSelectType == 'document' || item.learnSelectType == 'pdf') { |
| | | let md5 = item.file ? item.file : item.protectedFile ? item.protectedFile : item.freeFile |
| | | app.MG.file.getPdfInfo({ |
| | | md5: item.file |
| | | md5: md5 |
| | | }).then((res) => { |
| | | let naturalResources = [] |
| | | 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' |
| | | this.data.naturalResources.push(src) |
| | | // console.log(this.data.naturalResources, ' this.data.naturalResources'); |
| | | const src = app.config.requestCtx + '/file/GetPdfPageImage?md5=' + md5 + '&index=' + (i + 1) + '&dpi=300' |
| | | naturalResources.push(src) |
| | | } |
| | | } |
| | | this.setData({ |
| | | naturalResources |
| | | }) |
| | | wx.hideLoading(); |
| | | }) |
| | | } |
| | | |
| | | }, |
| | | |
| | | handleTap: function () { |
| | | const naturalResources = this.data.naturalResources; |
| | | naturalResources.forEach(function (item) { |
| | | // console.log(item); |
| | | }); |
| | | naturalResources.forEach(function (item) {}); |
| | | }, |
| | | |
| | | onClick() { |
| | |
| | | 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 |
| | | let urls = [event.currentTarget.dataset.src] |
| | | wx.previewImage({ |
| | | current: currentUrl, // 当前显示图片的http链接 |
| | | // urls: this.data.showData // 需要预览的图片http链接列表 |
| | | 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 |
| | | // }) |
| | | // } |
| | | // }, |
| | | }) |