闫增涛
2024-04-10 8cbdee91e04162812b29134397a0c311759d0b77
packageDomain/pages/resourceDetails/myAudio/index.js
@@ -83,13 +83,9 @@
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const systInfo = wx.getSystemInfoSync();
    const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息
    const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度
    this.setData({
      navBarHeight: navBarHeight,
      barHeight: systInfo.statusBarHeight,
@@ -101,26 +97,10 @@
      parentProductLinkPath: options.parentProductLinkPath,
      productLinkPath: options.productLinkPath
    })
    this.resourceDetailsData()
    this.getNoteList()
  },
  onUnload() {
    myAudio.src = ''
    myAudio.destroy()
    this.setData({
      myAudioPos: '',
      isplay: false, //是否默认播放,
      myAudioCurrent: '00:00', // 当前播放进度
      showData: '',
    });
    // console.log(myAudio.src);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   * 
@@ -137,7 +117,6 @@
    this.setData({
      startTime: Date.now()
    })
  },
  /**
@@ -157,13 +136,27 @@
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    this.setData({
      pauseTime: Date.now()
    })
    if (wx.getStorageSync(app.config.tokenKey)) {
      let duration = this.data.pauseTime - this.data.startTime
      this.count(duration)
    }
    // this.setData({
    //   pauseTime: Date.now()
    // })
    // if (wx.getStorageSync(app.config.tokenKey)) {
    //   let duration = this.data.pauseTime - this.data.startTime
    //   this.count(duration)
    // }
    // myAudio.src = ''
    // myAudio.destroy()
    // this.setData({
    //   myAudioPos: '',
    //   isplay: false, //是否默认播放,
    //   myAudioCurrent: '00:00', // 当前播放进度
    //   showData: '',
    // });
    // 停止音频播放
    myAudio.stop();
    // 销毁 InnerAudioContext 实例
    myAudio.destroy();
  },
  count(timeStr) {
    const data = {
@@ -219,7 +212,6 @@
  },
  showDialog(e) {
    this.setData({
      submitTitle: this.data.bookName,
      dialogKey: true,
@@ -260,16 +252,13 @@
        size: 999
      }
    }
    app.MG.store.getProductDetail(query).then(res => {
      res.datas.cmsDatas[0].datas.forEach((item, index) => {
        if (item.selectType === "audio") {
          this.data.threeLeveData.push(item)
          this.setData({
            threeLeveData: this.data.threeLeveData
          })
          this.data.threeLeveData.forEach((items, index) => { // 修改此处添加index参数
            if (this.data.productLinkPath == items.productLinkPath) {
              this.setData({
@@ -277,38 +266,25 @@
                titleName: items.name
              })
              this.pubulicPlayFun()
              let selectedIndex = index; // 存储选中项的索引
              this.setData({
                selectedId: selectedIndex // 设置选中项的索引
              });
            }
          });
        }
      })
      this.data.threeLeveData.forEach((item) => {
        // console.log(item.name);
      })
      this.data.threeLeveData.forEach((item) => {})
    })
  },
  onVideo(e) {
    // console.log(e, 'e');
    this.setData({
      myAudioCurrent: '00:00',
      myAudioPos: '',
      isplay: false
    })
    const item = e.currentTarget.dataset.item
    if (this.data.showData != '') {
      this.setData({
        titleName: item.name,
        selectId: item.id,
@@ -436,11 +412,8 @@
      topicIdOrRefCode: topicId + ''
    }
    await app.MG.ugc.getTopicMessageList(query).then((res) => {
      // notePage.value.total = res.totalSize
      res.datas.forEach((item) => {
        item.createDate = this.convertTimestamp(item.createDate)
      })
      this.setData({
        "pageCount.total": res.totalSize,
@@ -652,14 +625,11 @@
      this.changeItem(this.data.threeLeveData[index - 1])
      this.setData({
        selectedId: index - 1,
      })
    } else {
      console.log('已经是第一首了');
    }
  },
  //右切换
  onRightSwitch() {
    this.setData({