From 1530f605190069e45b5e31a7ec2bf7a6dc691f39 Mon Sep 17 00:00:00 2001 From: QYF-GitLab1 <1940665526@qq.com> Date: 星期四, 02 一月 2025 14:09:22 +0800 Subject: [PATCH] 1 --- packageBookService/pages/components/webView/index.js | 117 +++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 98 insertions(+), 19 deletions(-) diff --git a/packageBookService/pages/components/webView/index.js b/packageBookService/pages/components/webView/index.js index 02bafaa..2a1ac76 100644 --- a/packageBookService/pages/components/webView/index.js +++ b/packageBookService/pages/components/webView/index.js @@ -1,5 +1,8 @@ // packageBookService/pages/components/webView/index.js const app = getApp() +import { + loginInfo +} from '../../../../assets/js/login'; Page({ /** @@ -10,12 +13,18 @@ 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), @@ -29,9 +38,21 @@ if (options) { wx.setNavigationBarTitle({ title: options.fileName, + skeletonLoding: true }) - this.getProgress(options) } + } + const token = wx.getStorageSync(app.config.tokenKey) + if (!token) { + loginInfo(app, (data) => { + if (data) { + this.getProgress(options) + } else { + this.getProgress(options) + } + }) + } else { + this.getProgress(options) } }, @@ -44,9 +65,10 @@ }, setWebViewSrc: function (data) { + let that = this; var url = ""; if (data.fileType == 'epub') { - if (data.bookBuy) { + if (data.bookBuy == "true") { url = app.config.epubUrl + "?md5=" + data.md5 + @@ -67,25 +89,36 @@ "&token=" + wx.getStorageSync(app.config.tokenKey) + "&recordLocation=" + - this.data.currentPage + "&freeEpubPage=" + data.freePage + that.data.currentPage + "&isPreview=true&freeEpubPage=" + data.freePage } + that.setData({ + src: url, + skeletonLoding: false, + }) } else { - url = app.config.pdfUrl + - "?md5=" + - data.md5 + - "&bookName=" + - data.fileName + - "&url=" + app.config.requestCtx + - "&token=" + - wx.getStorageSync(app.config.tokenKey) + - "&recordLocation=" + - this.data.currentPage; + 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) + } + that.setData({ + pdfList: list, + skeletonLoding: false, + }) + } + }) } - this.setData({ - src: url - }) - }, + }, // 鑾峰彇UserKey getProgress: function (dataObj) { @@ -159,21 +192,62 @@ * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず */ 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) => {}) + }, + + //棰勮鍥剧墖锛屾斁澶ч瑙� + preview(event) { + let urls = [event.currentTarget.dataset.src] + wx.previewImage({ + urls: urls // 闇�瑕侀瑙堢殑鍥剧墖http閾炬帴鍒楄〃 + }) }, /** @@ -189,4 +263,9 @@ onReachBottom() { }, + /** + * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜� + */ + onShareAppMessage() {}, + onShareTimeline() {}, }) \ No newline at end of file -- Gitblit v1.9.1