闫增涛
2025-03-31 04c7b0163caeae4ab1c5da62e301fa993101cfad
packageDomain/pages/resourceDetails/document/index.js
@@ -4,6 +4,7 @@
import {
  loginInfo
} from '../../../../assets/js/login';
import XLSX from '../../../../utils/xlsx.mini.min';
Page({
  /**
@@ -53,7 +54,8 @@
    learnStartTime: 0,
    learnTimeList: [],
    learnTimeData: 0,
    threeLeveData: []
    threeLeveData: [],
    selectTypeData: ''
  },
  /**
   * 生命周期函数--监听页面加载
@@ -80,32 +82,13 @@
      deadline: options.deadline,
      formPath: options.formPath,
    })
    const token = wx.getStorageSync(app.config.tokenKey)
    if (!token) {
      loginInfo(app, (data) => {
        if (options.formPath == 'jsek_cloudLearning') {
          this.setData({
            learnStartTime: Date.now(),
          })
          this.getLearnTime()
        }
        this.getBookInfo(this.data.bookId)
        // if (data) {
        //   this.resourceDetailsData()
        // } else {
        //   this.resourceDetailsData()
        // }
    if (options.formPath == 'jsek_cloudLearning') {
      this.setData({
        learnStartTime: Date.now(),
      })
    } else {
      if (options.formPath == 'jsek_cloudLearning') {
        this.setData({
          learnStartTime: Date.now(),
        })
        this.getLearnTime()
      }
      this.getBookInfo(this.data.bookId)
      // this.resourceDetailsData()
      this.getLearnTime()
    }
    this.getBookInfo(this.data.bookId)
  },
  /**
@@ -350,19 +333,14 @@
        isBuy: res.datas.purchasedSaleMethodIdList.includes(res.datas.defaultSaleMethodId)
      })
      res.datas.cmsDatas[0].datas.forEach((item) => {
        // if (this.data.productLinkPath == item.productLinkPath) {
        //   this.handleTeachData(item)
        //   this.setData({
        //     titleName: item.name,
        //     selectType: item.selectType,
        //     learnSelectType: item.learnSelectType
        //   })
        // } else {
        //   return wx.showToast({
        //     icon: 'none',
        //     title: '暂无资源',
        //   })
        // }
        if (this.data.productLinkPath == item.productLinkPath) {
          this.handleTeachData(item)
          this.setData({
            titleName: item.name,
            selectType: item.selectType,
            learnSelectType: item.learnSelectType
          })
        }
        if (this.data.storeInfo == 'jsek_digitalCourses') {
          if (this.data.isBuy) {
            if (this.data.productLinkPath == item.productLinkPath) {
@@ -432,13 +410,13 @@
          learnSelectType: item.learnSelectType,
        })
      } else {
        wx.showToast({
          icon: 'none',
          title: '请先返回资源所在图书详情购买视频资源',
        })
        wx.navigateTo({
          url: `/packageBookService/pages/bookServices/detail/index?id=${this.data.bookDetail.id}&name=${this.data.bookDetail.name}&tabValue=jsek_cloudLearning`,
        });
        // wx.showToast({
        //   icon: 'none',
        //   title: '请先返回资源所在图书详情购买视频资源',
        // })
        // wx.navigateTo({
        //   url: `/packageBookService/pages/bookServices/detail/index?id=${this.data.bookDetail.id}&name=${this.data.bookDetail.name}&tabValue=jsek_cloudLearning`,
        // });
      }
    })
  },
@@ -519,7 +497,7 @@
  },
  //刚进来的时候调用
  handleTeachData(item) {
    let that = this
    //图片
    if (item.selectType == 'picture' || item.learnSelectType == 'picture') {
      let file = item.file ? item.file : item.protectedFile ? item.protectedFile : item.freeFile
@@ -554,28 +532,53 @@
    //文档等
    if (item.selectType == 'document' || item.selectType == 'pdf' || item.learnSelectType == 'document' || item.learnSelectType == 'pdf') {
      let md5 = item.file ? item.file : item.protectedFile ? item.protectedFile : item.freeFile
      app.MG.file.getPdfInfo({
        md5: md5
      }).then((res) => {
        let naturalResources = []
        if (res && res.totalPages) {
          for (let i = 0; i < res.totalPages; i++) {
            const src = app.config.requestCtx + '/file/GetPdfPageImage?md5=' + md5 + '&index=' + (i + 1) + '&dpi=300'
            naturalResources.push(src)
          }
        }
      if (item.fileMap[md5]?.extension == 'xlsx' || item.fileMap[md5]?.extension == 'xls') {
        this.setData({
          naturalResources
          selectTypeData: 'excel'
        })
        wx.hideLoading();
      })
        wx.request({
          url: app.config.requestCtx + '/file/api/ApiDownload?md5=' + md5,
          method: 'GET', // 请求方式
          responseType: 'arraybuffer', // 指定返回类型为 arraybuffer
          success: (res) => {
            if (res.statusCode === 200) {
              let data = new Uint8Array(res.data)
              let workbook = XLSX.read(data, {
                type: 'array'
              })
              let worksheet = workbook.Sheets[workbook.SheetNames[0]]
              let innerHTML = XLSX.utils.sheet_to_json(worksheet)
              console.log(innerHTML)
              that.setData({
                naturalResources: innerHTML
              })
              wx.hideLoading();
            } else {
              console.error('请求失败', res.statusCode);
            }
          },
          fail: function (err) {
            console.error('请求失败', err);
          }
        });
      } else {
        app.MG.file.getPdfInfo({
          md5: md5
        }).then((res) => {
          let naturalResources = []
          if (res && res.totalPages) {
            for (let i = 0; i < res.totalPages; i++) {
              const src = app.config.requestCtx + '/file/GetPdfPageImage?md5=' + md5 + '&index=' + (i + 1) + '&dpi=300'
              naturalResources.push(src)
            }
          }
          this.setData({
            naturalResources
          })
          wx.hideLoading();
        })
      }
    }
  },
  handleTap: function () {
    const naturalResources = this.data.naturalResources;
    naturalResources.forEach(function (item) {});
  },
  onClick() {