From 3d73fb33c46aada16a6060adcd4ea14bb33b6b2a Mon Sep 17 00:00:00 2001 From: 闫增涛 <1829501689@qq.com> Date: 星期二, 09 四月 2024 10:39:11 +0800 Subject: [PATCH] 详情页tabs样式优化,答题添加页面退出拦截,合并代码 --- packageBookService/pages/components/webView/index.js | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 100 insertions(+), 18 deletions(-) diff --git a/packageBookService/pages/components/webView/index.js b/packageBookService/pages/components/webView/index.js index 452b945..fba1875 100644 --- a/packageBookService/pages/components/webView/index.js +++ b/packageBookService/pages/components/webView/index.js @@ -10,12 +10,17 @@ link: false, epubObj: null, currentPage: '', + pdfList: [], + skeletonLoding: true, + startTime: "", //杩涘叆椤甸潰褰撳墠鏃堕棿 + pauseTime: 0 //鏆傚仠鏃堕棿 }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 */ onLoad(options) { + console.log(options) if (options && options.link) { this.setData({ src: decodeURIComponent(options.link), @@ -27,8 +32,10 @@ src: '' }) if (options) { + console.log(options) wx.setNavigationBarTitle({ title: options.fileName, + skeletonLoding: true }) this.getProgress(options) } @@ -44,19 +51,61 @@ }, setWebViewSrc: function (data) { - var url = app.config.epubUrl + - "?md5=" + - data.md5 + - "&bookName=" + - data.fileName + - "&url=" + app.config.requestCtx + - "&token=" + - wx.getStorageSync(app.config.tokenKey) + - "&recordLocation=" + - this.data.currentPage - this.setData({ - src: url - }) + let that = this; + var url = ""; + if (data.fileType == 'epub') { + if (data.bookBuy == "true") { + url = app.config.epubUrl + + "?md5=" + + data.md5 + + "&bookName=" + + data.fileName + + "&url=" + app.config.requestCtx + + "&token=" + + wx.getStorageSync(app.config.tokenKey) + + "&recordLocation=" + + this.data.currentPage + } else { + url = app.config.epubUrl + + "?md5=" + + data.md5 + + "&bookName=" + + data.fileName + + "&url=" + app.config.requestCtx + + "&token=" + + wx.getStorageSync(app.config.tokenKey) + + "&recordLocation=" + + that.data.currentPage + "&isPreview=true&freeEpubPage=" + data.freePage + } + that.setData({ + src: url, + skeletonLoding: false, + }) + } else { + that.setData({ + navigationBarTitleText: data.fileName + }) + app.MG.file.getPdfInfo({ + md5: data.md5 + }).then((res) => { + let pageCount = data.bookBuy == "true" ? res.totalPages : Number(data.freePage) + console.log(pageCount, "connt") + if (pageCount) { + let list = []; + for (let i = 0; i < pageCount; i++) { + const src = app.config.requestCtx + '/file/GetPdfPageImage?md5=' + data.md5 + '&index=' + (i + 1) + '&dpi=300' + list.push(src) + } + console.log(list) + that.setData({ + pdfList: list, + skeletonLoding: false, + }) + + } + }) + } + }, @@ -96,9 +145,9 @@ domain: "bookReadProgress", key: this.data.epubObj.md5, value: JSON.stringify(data), - },], + }, ], }) - .then((res) => { }); + .then((res) => {}); } }, @@ -108,7 +157,7 @@ percentage, type } = - e.detail.data[0]; + e.detail.data[0]; if (type == "progress" && type != "backDetail") { this.setProgress({ page: currentLocation, @@ -132,21 +181,54 @@ * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず */ onShow() { - + this.setData({ + startTime: Date.now() + }) }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰闅愯棌 */ onHide() { - + this.setData({ + pauseTime: Date.now() + }) + if (wx.getStorageSync(app.config.tokenKey) && this.data.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) && this.data.epubObj.bookBuy == 'true') { + 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' + } + //闃呰鍟嗗搧鐨刬d + if (this.data.epubObj.bookId) { + data.productId = this.data.epubObj.bookId + } + //闃呰璧勬簮鐨刬d + // if (product.cmsItemId) { + // data.cmsItemId = product.cmsItemId + // } + app.MG.job.newJobWithApiNewEvent(data).then((res) => {}) }, /** -- Gitblit v1.9.1