litian
2024-07-10 81c23f9c2f5bdfbe962d0b19a5a80ea7c12f043d
packageDomain/pages/resourceDetails/myVideo/index.js
@@ -16,6 +16,7 @@
    dialogKey: false,
    style: 'border: 2rpx solid rgba(220,220,220,1);border-radius: 12rpx;',
    activeId: '',
    storeInfo: '',
    bookId: '',
    bookName: '',
    cmsId: '',
@@ -38,9 +39,12 @@
    startTime: "", //进入页面当前时间
    pauseTime: 0, //暂停时间
    formPath: '',
    loading: true,
    loading: false,
    hidden: true,
    videoError: false
    videoError: false,
    videoLoading: false,
    progress: 0,
    playerList: []
  },
  // 格式化笔记时间
  convertTimestamp(timestamp) {
@@ -64,11 +68,11 @@
    const systInfo = wx.getSystemInfoSync();
    const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息
    const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度
    console.log(options, 'options');
    this.setData({
      navBarHeight: navBarHeight,
      barHeight: systInfo.statusBarHeight,
      activeId: options.activeId,
      storeInfo: options.storeInfo,
      bookId: options.bookId,
      bookName: options.bookName,
      cmsId: options.cmsId,
@@ -82,7 +86,6 @@
        parentName: options.parentName,
      })
    }
    console.log(options, 'options');
    this.resourceDetailsData()
    this.getNoteList()
  },
@@ -115,6 +118,7 @@
      let duration = this.data.pauseTime - this.data.startTime
      this.count(duration)
    }
    this.setPlayerList()
  },
  /**
@@ -128,6 +132,7 @@
      let duration = this.data.pauseTime - this.data.startTime
      this.count(duration)
    }
    this.setPlayerList()
  },
  count(timeStr) {
    const data = {
@@ -183,7 +188,6 @@
  },
  showDialog(e) {
    this.setData({
      dialogKey: true,
      textvalue: '',
@@ -202,7 +206,12 @@
    wx.navigateBack();
  },
  resourceDetailsData() {
    this.setData({
      videoLoaidng: true,
      loading: true
    })
    let query = {
      storeInfo: this.data.storeInfo,
      path: '*',
      queryType: '*',
      productId: this.data.bookId,
@@ -228,57 +237,57 @@
    }
    app.MG.store.getProductDetail(query).then(res => {
      res.datas.cmsDatas[0].datas.forEach((item) => {
        console.log(item);
        if (item.selectType === "video" || item.learnSelectType === "video") {
          this.data.threeLeveData.push(item)
          this.setData({
            threeLeveData: this.data.threeLeveData
          })
          this.data.threeLeveData.forEach((items, index) => { // 修改此处添加index参数
            if (this.data.productLinkPath == items.productLinkPath) {
              if (this.data.formPath === "jsek_cloudLearning") {
                let file
                items.protectedFile ? file = items.protectedFile : file = items.freeFile
                this.setData({
                  showData: app.config.requestCtx + '/file/api/ApiDownloadForAuthorize?md5=' + file + '&token=' + wx.getStorageSync(app.config.tokenKey),
                  titleName: items.name
                })
              } else {
                this.setData({
                  showData: item.file ? app.config.requestCtx + '/file/api/ApiDownload?md5=' + item.file : app.config.requestCtx + '/file/api/ApiDownload?md5=' + item.freeFile,
                  titleName: items.name
                })
              }
              let selectedIndex = index; // 存储选中项的索引
              this.setData({
                selectedId: selectedIndex // 设置选中项的索引
              });
            }
          });
        }
      })
      this.data.threeLeveData.forEach((items, index) => { // 修改此处添加index参数
        if (this.data.productLinkPath == items.productLinkPath) {
          if (this.data.formPath === "jsek_cloudLearning") {
            let file
            items.protectedFile || item.file ? file = items.protectedFile || item.file : file = items.freeFile
            this.setData({
              showData: app.config.requestCtx + '/file/api/ApiDownloadForAuthorize?md5=' + file + '&token=' + wx.getStorageSync(app.config.tokenKey),
              titleName: items.name
            })
          } else {
            this.setData({
              showData: items.file ? app.config.requestCtx + '/file/api/ApiDownload?md5=' + items.file : app.config.requestCtx + '/file/api/ApiDownload?md5=' + items.freeFile,
              titleName: items.name
            })
          }
          let selectedIndex = index; // 存储选中项的索引
          this.setData({
            selectedId: selectedIndex // 设置选中项的索引
          });
        }
      });
      this.setData({
        loading: false,
        hidden: false
      })
      console.log('地址', this.data.showData);
    })
  },
  onVideo(e) {
    this.setPlayerList()
    const item = e.currentTarget.dataset.item
    this.setData({
      videoLoaidng: true,
      selectedId: e.currentTarget.dataset.index,
      showData: '',
      activeId: item.id,
      // showData: '',
      titleName: item.name
    })
    if (item.selectType == "video" || item.learnSelectType === "video") {
      if (this.data.formPath === "jsek_cloudLearning") {
        let file
        item.protectedFile ? file = item.protectedFile : file = item.freeFile
        item.protectedFile || item.file ? file = item.protectedFile || item.file : file = item.freeFile
        this.setData({
          showData: app.config.requestCtx + '/file/api/ApiDownloadForAuthorize?md5=' + file + '&token=' + wx.getStorageSync(app.config.tokenKey)
        })
        console.log(this.data.showData);
      } else {
        this.setData({
          showData: item.file ? app.config.requestCtx + '/file/api/ApiDownload?md5=' + item.file : app.config.requestCtx + '/file/api/ApiDownload?md5=' + item.freeFile,
@@ -286,6 +295,54 @@
      }
    }
  },
  timeUpdate(e) {
    let {
      currentTime,
      duration
    } = e.detail
    this.setData({
      progress: ((currentTime / duration) * 100).toFixed(2)
    })
  },
  //获取视频学习
  getPlayerList() {
    app.MG.identity
      .getUserKey({
        domain: 'videoPlayer',
        keys: [this.data.bookId]
      })
      .then((res) => {
        if (res.length > 0) {
          this.setData({
            playerList: JSON.parse(res[0].value)
          })
        }
      })
  },
  setPlayerList() {
    let that = this
    if (that.data.progress > 0) {
      let index = that.data.playerList.findIndex((itemData) => itemData.cmsItemId == that.data.activeId)
      if (index > -1) {
        that.data.playerList.splice(index, 1)
      }
      that.data.playerList.push({
        cmsItemId: that.data.activeId,
        progress: that.data.progress
      })
      app.MG.identity
        .setUserKey({
          setKeyRequests: [{
            domain: 'videoPlayer',
            key: that.data.bookId,
            value: JSON.stringify(that.data.playerList)
          }]
        })
        .then((res) => {})
    }
  },
  getProductUserSubmitTopicGet() {
    app.MG.ugc.getProductUserSubmitTopic({
@@ -342,8 +399,6 @@
    } else if (this.data.submitType == 'edit') {
      this.updateNote()
    }
    console.log(this.data.textvalue);
    console.log(this.data.titleName);
    this.setData({
      dialogKey: false
    });
@@ -356,13 +411,11 @@
      textvalue: e.detail.value
    })
  },
  // 获取笔记列表
  async getNoteList() {
    // this.setData({
    //   loading: true
    // })
    this.setData({
      loading: true
    })
    let topicId
    await app.MG.ugc
      .getProductUserSubmitTopic({
@@ -398,7 +451,6 @@
        // item.deleteHover = false
        item.createDate = this.convertTimestamp(item.createDate)
      })
      console.log(res, 'res');
      this.setData({
        "pageCount.total": res.totalSize,
        noteList: res.datas,
@@ -539,9 +591,13 @@
    console.log(e);
  },
  videoError: function (e) {
    console.log('视频加载失败', e);
    this.setData({
      videoError: true
    });
  },
  loadedmetadata(e) {
    this.setData({
      videoLoaidng: false
    })
  }
})