1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
| // 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%",
| });
| }
| },
| }
| })
|
|