From 04c7b0163caeae4ab1c5da62e301fa993101cfad Mon Sep 17 00:00:00 2001 From: 闫增涛 <1829501689@qq.com> Date: 星期一, 31 三月 2025 10:40:45 +0800 Subject: [PATCH] bug修改 --- packageDomain/pages/resourceDetails/document/index.js | 349 +++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 309 insertions(+), 40 deletions(-) diff --git a/packageDomain/pages/resourceDetails/document/index.js b/packageDomain/pages/resourceDetails/document/index.js index 839ba57..dac4ffc 100644 --- a/packageDomain/pages/resourceDetails/document/index.js +++ b/packageDomain/pages/resourceDetails/document/index.js @@ -1,6 +1,10 @@ // pages/resourceDetails/document/index.js import Toast from 'tdesign-miniprogram/toast/index'; const app = getApp() +import { + loginInfo +} from '../../../../assets/js/login'; +import XLSX from '../../../../utils/xlsx.mini.min'; Page({ /** @@ -23,21 +27,35 @@ 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: [], + selectTypeData: '' }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 @@ -46,7 +64,6 @@ wx.setNavigationBarTitle({ title: '璧勬簮璇︽儏' }); - console.log(options); const systInfo = wx.getSystemInfoSync(); const menu = wx.getMenuButtonBoundingClientRect(); // 鑳跺泭淇℃伅 const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 瀵艰埅鏍忛珮搴� @@ -62,9 +79,16 @@ parentProductLinkPath: options.parentProductLinkPath, productLinkPath: options.productLinkPath, applyState: options.applyState, - deadline: options.deadline + deadline: options.deadline, + formPath: options.formPath, }) - this.resourceDetailsData() + if (options.formPath == 'jsek_cloudLearning') { + this.setData({ + learnStartTime: Date.now(), + }) + this.getLearnTime() + } + this.getBookInfo(this.data.bookId) }, /** @@ -90,9 +114,13 @@ 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) + } } }, @@ -103,9 +131,13 @@ 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) + } } }, @@ -127,6 +159,47 @@ } 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, '瀛︿範鏃堕暱') + }) + }, /** * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 */ @@ -137,21 +210,97 @@ /** * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁� */ - 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: '姝e湪鍔犺浇...', + }); let query = { path: '*', queryType: '*', @@ -180,16 +329,95 @@ 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 + selectType: item.selectType, + learnSelectType: item.learnSelectType }) } + 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鏂囦欢涓嬭浇 @@ -204,14 +432,15 @@ }) } } - 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: '姝e湪涓嬭浇...', }); @@ -268,47 +497,88 @@ }, //鍒氳繘鏉ョ殑鏃跺�欒皟鐢� handleTeachData(item) { + let that = this //鍥剧墖 - 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') { - 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' - this.data.naturalResources.push(src) - // console.log(this.data.naturalResources, ' this.data.naturalResources'); + 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 + if (item.fileMap[md5]?.extension == 'xlsx' || item.fileMap[md5]?.extension == 'xls') { + this.setData({ + selectTypeData: 'excel' + }) + wx.request({ + url: app.config.requestCtx + '/file/api/ApiDownload?md5=' + md5, + method: 'GET', // 璇锋眰鏂瑰紡 + responseType: 'arraybuffer', // 鎸囧畾杩斿洖绫诲瀷涓� arraybuffer + success: (res) => { + if (res.statusCode === 200) { + let data = new Uint8Array(res.data) + let workbook = XLSX.read(data, { + type: 'array' + }) + let worksheet = workbook.Sheets[workbook.SheetNames[0]] + let innerHTML = XLSX.utils.sheet_to_json(worksheet) + console.log(innerHTML) + that.setData({ + naturalResources: innerHTML + }) + wx.hideLoading(); + } else { + console.error('璇锋眰澶辫触', res.statusCode); + } + }, + fail: function (err) { + console.error('璇锋眰澶辫触', err); } - } - }) + }); + } else { + app.MG.file.getPdfInfo({ + 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=' + 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); - }); }, onClick() { @@ -344,7 +614,6 @@ const { trigger } = e.detail; - console.log(trigger); this.setData({ visible: false, }); -- Gitblit v1.9.1