litian
2024-09-07 89d33476c7ab9bf7a4fbad399685652eabd478de
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// pages/index/resourceCover.js
const app = getApp()
import {
  loginInfo
} from '../../assets/js/login';
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    webpageSrc: "",
    bookId: 0,
    bookName: '',
    cmsId: '',
    productLinkPath: '',
    parentProductLinkPath: '',
    formPath: '',
    copyUrl: '',
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const token = wx.getStorageSync(app.config.tokenKey)
    if (!token) {
      loginInfo(app, (data) => {
        // 如果不是第一次登录,会执行回调
        if (data) {
          if (options.scene) {
            this.getBookInfo(options.scene)
          }
        }
      })
    } else {
      if (options.scene) {
        this.getBookInfo(options.scene)
      }
    }
 
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
 
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
 
  },
 
  getBookInfo(refcode) {
    const obj = {
      storeInfo: app.config.goodsStore,
      path: app.config.goodsStore,
      queryType: 'ProductCmsItem',
      SysType: "CmsItem",
      RefCode: refcode,
      // CmsItemType: 'jsek_resource',
      paging: {
        start: 0,
        size: 99,
      },
      coverSize: {
        width: 260
      },
      fields: {
        ProductLinkInfo: [],
        productLinkPath: [],
        selectType: [],
        freeFile: [],
        file: [],
        protectedFile: [],
        resourcesClassification: [],
        isDownload: [],
        jsek_resourceBrief: [],
        jsek_link: [],
        jsek_questionBank: [],
        learnSelectType: [],
      }
    }
    app.MG.resource.getItem(obj).then((res) => {
      let book = res.datas.length > 0 ? res.datas[0] : {}
      console.log(book, '资源信息')
      let url;
      if (book.selectType == "video" || book.learnSelectType == "video") {
        url = "/packageDomain/pages/resourceDetails/myVideo/index";
      } else if (
        book.selectType == "audio" ||
        book.learnSelectType == "audio"
      ) {
        url = "/packageDomain/pages/resourceDetails/myAudio/index";
      } else if (book.selectType == "picture") {
        url = "/packageDomain/pages/resourceDetails/document/index";
      }
      this.setData({
        bookId: book.productLinkInfo.ProductId,
        bookName: book.productLinkInfo.Name,
        productLinkPath: book.productLinkInfo.LinkPath + "\\" + book.id,
        parentProductLinkPath: book.productLinkInfo.LinkPath,
        cmsId: book.id,
        formPath: book.learnSelectType ? 'jsek_cloudLearning' : ''
      })
      wx.redirectTo({
        url: `${url}?productLinkPath=${this.data.productLinkPath}&parentProductLinkPath=${this.data.parentProductLinkPath}&bookId=${book.productLinkInfo.ProductId}&activeId=${book.id}&bookName=${book.productLinkInfo.Name}&cmsId=${book.id}&formPath=${this.data.formPath}`,
      });
 
      if (book.selectType == "pdf" || book.selectType == 'document') {
        const fileLink = book.file ? book.file : book.freeFile
        console.log(fileLink);
        wx.redirectTo({
          url: "/packageBookService/pages/components/webView/index?md5=" +
            fileLink +
            "&fileName=" +
            book.name +
            "&fileType=pdf" + "&bookBuy=true"
        });
      }
      if (book.selectType == 'zip') {
        const fileLink = book.file ?
          app.config.requestCtx + "/file/api/ApiDownload?md5=" + book.file :
          app.config.requestCtx +
          "/file/api/ApiDownload?md5=" +
          book.freeFile;
        console.log(fileLink, "fileLink");
        this.setData({
          copyUrl: fileLink
        })
        // wx.redirectTo({
        //   url: "/packageBookService/pages/bookServices/webView/index?url=" + fileLink
        // });
        //提示加载中
        // 单次下载允许的最大文件为 200MB
 
      }
    })
  },
 
  copyUrl(e) {
 
    let url = e.currentTarget.dataset.value
    console.log(url)
    // wx.setClipboardData(url)
    wx.setClipboardData({
      data: `${e.currentTarget.dataset.value}`,
      success(res) {
        console.log(res.data) // data
      },
      fail(err) {
        reject(err);
      }
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
 
  }
})