litian
2024-07-10 81c23f9c2f5bdfbe962d0b19a5a80ea7c12f043d
pages/index/resourceCover.js
@@ -1,5 +1,8 @@
// pages/index/resourceCover.js
const app = getApp()
import {
  loginInfo
} from '../../assets/js/login';
Page({
  /**
@@ -12,16 +15,30 @@
    cmsId: '',
    productLinkPath: '',
    parentProductLinkPath: '',
    formPath: ''
    formPath: '',
    copyUrl: '',
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if (options.scene) {
      this.getBookInfo(options.scene)
    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)
      }
    }
  },
  /**
@@ -40,8 +57,8 @@
  getBookInfo(refcode) {
    const obj = {
      storeInfo: app.config.jslx,
      path: app.config.jslx,
      storeInfo: app.config.goodsStore,
      path: app.config.goodsStore,
      queryType: 'ProductCmsItem',
      SysType: "CmsItem",
      RefCode: refcode,
@@ -91,7 +108,7 @@
        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}&storeInfo=${book.storeInfo}&formPath=${this.data.formPath}`,
        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') {
@@ -112,22 +129,34 @@
          "/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
        wx.downloadFile({
          url: fileLink,
          filePath: wx.env.USER_DATA_PATH + `/${book.name}.${book.selectType}`,
          success: function (res) {
            console.log(res, "wx.downloadFile success res");
            if (res.statusCode != 200) {
              return false;
            }
          }
        });
      }
    })
  },
  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);
      }
    })
  },
  /**
   * 用户点击右上角分享
   */