From dd20c89b9c333f356927ed0bfed9a4dd9121b964 Mon Sep 17 00:00:00 2001 From: QYF-GitLab1 <1940665526@qq.com> Date: 星期三, 16 七月 2025 22:26:07 +0800 Subject: [PATCH] 优化 --- packageDomain/pages/resourceDetails/document/index.js | 394 +++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 263 insertions(+), 131 deletions(-) diff --git a/packageDomain/pages/resourceDetails/document/index.js b/packageDomain/pages/resourceDetails/document/index.js index 00cbcfa..ae51bb6 100644 --- a/packageDomain/pages/resourceDetails/document/index.js +++ b/packageDomain/pages/resourceDetails/document/index.js @@ -4,8 +4,8 @@ import { loginInfo } from '../../../../assets/js/login'; +import XLSX from '../../../../utils/xlsx.mini.min'; Page({ - /** * 椤甸潰鐨勫垵濮嬫暟鎹� */ @@ -26,21 +26,41 @@ 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: '', + promptVisable: false, + showMd5: '', + confirmBtn: { + content: '纭畾', + variant: 'base', + }, }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 @@ -49,7 +69,6 @@ wx.setNavigationBarTitle({ title: '璧勬簮璇︽儏' }); - console.log(options); const systInfo = wx.getSystemInfoSync(); const menu = wx.getMenuButtonBoundingClientRect(); // 鑳跺泭淇℃伅 const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 瀵艰埅鏍忛珮搴� @@ -65,30 +84,21 @@ parentProductLinkPath: options.parentProductLinkPath, productLinkPath: options.productLinkPath, applyState: options.applyState, - deadline: options.deadline + deadline: options.deadline, + formPath: options.formPath, }) - const token = wx.getStorageSync(app.config.tokenKey) - if (!token) { - loginInfo(app, (data) => { - if (data) { - this.resourceDetailsData() - } else { - this.resourceDetailsData() - } + if (options.formPath == 'jsek_cloudLearning') { + this.setData({ + learnStartTime: Date.now(), }) - } else { - this.resourceDetailsData() + this.getLearnTime() } - + this.getBookInfo(this.data.bookId) }, - /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚 */ - onReady() { - - }, - + onReady() {}, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず */ @@ -97,7 +107,6 @@ startTime: Date.now() }) }, - /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰闅愯棌 */ @@ -105,12 +114,15 @@ 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) + } } }, - /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍗歌浇 */ @@ -118,12 +130,15 @@ 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) + } } }, - count(timeStr) { const data = { appRefCode: app.config.appRefCode, @@ -142,20 +157,55 @@ } 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, '瀛︿範鏃堕暱') + }) + }, /** * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 */ - onPullDownRefresh() { - - }, - + onPullDownRefresh() {}, /** * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁� */ - onReachBottom() { - - }, - + onReachBottom() {}, /** * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜� */ @@ -163,6 +213,37 @@ 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) => { + this.setData({ + bookDetail: res.datas + }) + this.resourceDetailsData(); + }); + }, + + // 鍒ゆ柇褰撳墠鐩爣鏄惁宸茶喘涔� + async getCmsDataByQrcode() { + const query = { + cmsItemId: Number(this.data.activeId) + }; + return app.MG.file.checkCmsItem(query) }, resourceDetailsData() { @@ -172,11 +253,10 @@ let query = { path: '*', queryType: '*', + cmsType: '*', productId: this.data.bookId, - cmsPath: this.data.parentProductLinkPath, + cmsPath: this.data.bookDetail.rootCmsItemId, itemFields: { - SysType: 'CmsFolder', - // 璧勬簮绫诲瀷锛岃瘯璇绘枃浠讹紝鏄惁鍏佽涓嬭浇绛夊弬鏁� selectType: [], freeFile: [], file: [], @@ -196,17 +276,53 @@ 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({ - titleName: item.name, - selectType: item.selectType + app.MG.store.getProductDetail(query).then(async (res) => { + let linkData = this.data.productLinkPath.split("\\"); + linkData.reverse() + let dataList = linkData.map(item => { + let data = res.datas.cmsDatas[0].datas.find(citem => citem.id == item); + if (data) return data; + }) + let isBuy = 1; + for (let i = 0; i < dataList.length; i++) { + const dataItem = dataList[i]; + if (dataItem) { + if (dataItem.saleMethod.length > 0) { + isBuy = 2; + if (this.data.bookDetail.purchasedSaleMethodIdList.indexOf(dataItem.saleMethod[0].Id) > -1) { + isBuy = 3; + break; + } else { + break; + } + } + } + } + if (isBuy == 2) { + // 鏈喘涔� + if (dataList[0].freeFile) { + this.handleTeachData(dataList[0], true) + } else { + wx.hideLoading(); + wx.showModal({ + title: '娓╅Θ鎻愮ず', + content: '璇ヨ祫婧愭湭璐拱锛屽皢杩斿洖璐拱', + success: (res) => { + if (res.confirm) { + if (this.data.source == 'qrcode') { + wx.navigateTo({ + url: `/packageBookService/pages/bookServices/detail/index?id=${this.data.bookDetail.id}&name=${this.data.bookDetail.name}&tabValue=${this.data.formPath}`, + }); + } else { + wx.navigateBack() + } + } + } }) } - }) + } else { + this.handleTeachData(dataList[0], false) + } }) }, //zpi鏂囦欢涓嬭浇 @@ -221,14 +337,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湪涓嬭浇...', }); @@ -284,57 +401,87 @@ }); }, //鍒氳繘鏉ョ殑鏃跺�欒皟鐢� - handleTeachData(item) { + handleTeachData(item, isTry) { + this.setData({ + titleName: item.name, + selectType: item.selectType, + learnSelectType: item.learnSelectType, + }) + let that = this //鍥剧墖 - if (item.selectType == 'picture') { + if (item.selectType == 'picture' || item.learnSelectType == 'picture') { + let file = isTry ? item.freeFile : item.protectedFile || item.file 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, }) 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' || item.selectType == 'document') { - let md5 = item.file ? item.file : item.freeFile - 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) - } - } + if (item.selectType == 'document' || item.selectType == 'pdf' || item.learnSelectType == 'document' || item.learnSelectType == 'pdf') { + let md5 = isTry ? item.freeFile : item.protectedFile || item.file || item.freeFile + if (item.fileMap[md5]?.extension == 'xlsx' || item.fileMap[md5]?.extension == 'xls') { this.setData({ - naturalResources + selectTypeData: 'excel', + showMd5: md5, }) - wx.hideLoading(); - }) + 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() { this.setData({ images: [ @@ -351,24 +498,20 @@ } = 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, }); @@ -380,56 +523,45 @@ 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绉诲姩鍚庣殑鍧愭爣鍜寉绉诲姩鍚庣殑鍧愭爣 - // 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 - // }) - // } - // }, + // 鍒ゆ柇褰撳墠鐐瑰嚮鐨勬暟鎹槸鍚﹁喘涔� + cmsItemIsBuy(item) { + let flag = false + // 涔颁簡 + if (this.data.buyList.length) { + if (this.data.buyList.some(citem => item.productLinkPath.includes(citem.productLinkPath))) + flag = true + } else { + // 娌′拱涓旀棤閿�鍞柟寮� + if (!item.saleMethod.length) { + flag = true + } else { + // 娌′拱涓旈攢鍞柟寮忚繃鏈�//娌′拱锛岄攢鍞柟寮忎环鏍间负0 + const itemSaleMethod = item.saleMethod.find(citem => citem.SaleType == 'Normal') + if (new Date().getTime() > new Date(itemSaleMethod.EndDate).getTime() || itemSaleMethod.Price == 0) flag = true + } + } + return flag + }, + // + scrolltolower(e) { + const activeData = this.data.threeLeveData.find(item => item.id == this.data.activeId) + const flag = this.data.naturalResources.some(item => item.includes(activeData.freeFile)) + if ((this.data.showMd5 == activeData.freeFile || flag) && activeData.protectedFile) + this.setData({ + promptVisable: true + }) + }, + // 鎻愮ず寮圭獥鍏抽棴 + closePromapDialog() { + this.setData({ + promptVisable: false + }) + if (this.data.source == 'qrcode') { + wx.navigateTo({ + url: `/packageBookService/pages/bookServices/detail/index?id=${this.data.bookDetail.id}&name=${this.data.bookDetail.name}&tabValue=${this.data.formPath}`, + }); + } else { + wx.navigateBack() + } + } }) \ No newline at end of file -- Gitblit v1.9.1