// packageBookService/pages/components/webView/index.js const app = getApp() Component({ /** * 组件的属性列表 */ properties: { fileInfo: { type: Object, value: {} } }, /** * 页面的初始数据 */ data: { src: "", link: false, epubObj: null, currentPage: '', }, methods: { onLoadWeb(e) { console.log(e, "load") }, onError(e) { console.log(e, "err") }, setWebViewSrc() { var url = app.config.epubUrl + "?md5=" + this.properties.fileInfo.md5 + "&bookName=" + this.properties.fileInfo.bookName + "&url=" + app.config.requestCtx + "&token=" + wx.getStorageSync(app.config.tokenKey) + "&recordLocation=" + this.data.currentPage this.setData({ src: url }) }, // 获取UserKey getProgress() { app.MG.identity .getUserKey({ domain: "bookReadProgress", keys: [this.properties.fileInfo.md5], }) .then((res) => { if (res.length) { try { this.setData({ currentPage: JSON.parse(res[0].value).page, }); } catch (error) { this.setData({ currentPage: "", }); } if (this.data.currentPage > this.properties.fileInfo.freePage) { this.setData({ currentPage: "", }); } } this.setWebViewSrc(); }); }, // 设置userKey setProgress(data) { if (data.page && data.page != this.data.currentPage) { app.MG.identity .setUserKey({ setKeyRequests: [{ domain: "bookReadProgress", key: this.properties.fileInfo.md5, value: JSON.stringify(data), },], }) .then((res) => { }); } }, drawBack(e) { let { currentLocation, percentage, type } = e.detail.data[0]; if (type == "progress" && type != "backDetail") { this.setProgress({ page: currentLocation, progress: percentage, }); } else if (type == "backDetail") { this.setProgress({ page: 1, progress: "0%", }); } }, } })