yiming
2024-04-03 8c794be279e13aa477af7ebbe4bc97570b7da816
packageDomain/pages/resourceDetails/myAudio/index.js
@@ -37,18 +37,31 @@
    style: 'height: 248rpx',
    submitType: "new", //  新建 or 编辑
    noteId: '',
    myAudioDuration: '00:00',  // 视频时间
    myAudioCurrent: '00:00',   // 当前播放进度
    myAudioDuration: '00:00', // 视频时间
    myAudioCurrent: '00:00', // 当前播放进度
    isplay: false, //是否默认播放,
    selectId: '',
    speed: 1.0,
    myAudioPos: ''
    myAudioPos: '',
    startTime: "", //进入页面当前时间
    pauseTime: 0 //暂停时间
  },
  // 时间格式化
  format(t) {
    let time = Math.floor(t / 60) >= 10 ? Math.floor(t / 60) : '0' + Math.floor(t / 60);
    t = time + ':' + ((t % 60) / 100).toFixed(2).slice(-2);
    return t;
  // // 时间格式化
  // format(t) {
  //   let time = Math.floor(t / 60) >= 10 ? Math.floor(t / 60) : '0' + Math.floor(t / 60);
  //   t = time + ':' + ((t % 60) / 100).toFixed(2).slice(-2);
  //   return t;
  // },
  // 转化时间
  format(time) {
    let minute = Math.floor(time / 60);
    let second = Math.floor(time % 60);
    minute = minute < 10 ? ("0" + minute) : minute;
    second = second < 10 ? ("0" + second) : second;
    let res = minute + ":" + second;
    return res;
  },
  audio: null,
  // 格式化笔记时间
@@ -70,10 +83,13 @@
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    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,
@@ -91,8 +107,20 @@
  },
  },
  onUnload() {
    myAudio.src = ''
    myAudio.destroy()
    this.setData({
      myAudioPos: '',
      isplay: false, //是否默认播放,
      myAudioCurrent: '00:00', // 当前播放进度
      showData: '',
    });
    // console.log(myAudio.src);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   * 
@@ -106,7 +134,9 @@
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      startTime: Date.now()
    })
  },
@@ -114,16 +144,45 @@
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
    this.setData({
      pauseTime: Date.now()
    })
    if (wx.getStorageSync(app.config.tokenKey)) {
      let duration = this.data.pauseTime - this.data.startTime
      this.count(duration)
    }
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    this.setData({
      pauseTime: Date.now()
    })
    if (wx.getStorageSync(app.config.tokenKey)) {
      let duration = this.data.pauseTime - this.data.startTime
      this.count(duration)
    }
  },
  count(timeStr) {
    const data = {
      appRefCode: app.config.appRefCode,
      type: 'LearningTime', //统计类型--阅读时长
      data: timeStr + '', //统计内容--时长毫秒
      event: 'LearningTime',
      sysType: 'App'
    }
    //阅读商品的id
    if (this.data.bookId) {
      data.productId = this.data.bookId
    }
    //阅读资源的id
    if (this.data.cmsId) {
      data.cmsItemId = this.data.cmsId
    }
    app.MG.job.newJobWithApiNewEvent(data).then((res) => {})
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
@@ -150,7 +209,8 @@
  onTabsClick(event) {
  }, handleChange(e) {
  },
  handleChange(e) {
    this.setData({
      activeValues: e.detail.value,
    });
@@ -164,13 +224,10 @@
      submitTitle: this.data.bookName,
      dialogKey: true,
      textvalue: ''
    });
  },
  closeDialog() {
    this.setData({
      dialogKey: false
    });
@@ -220,7 +277,7 @@
                titleName: items.name
              })
              this.pubulicPlayFun()
              console.log(index, 'index');
              let selectedIndex = index; // 存储选中项的索引
              this.setData({
                selectedId: selectedIndex // 设置选中项的索引
@@ -241,11 +298,14 @@
    // console.log(e, 'e');
    this.setData({
      myAudioCurrent: '00:00',
      myAudioPos: ''
      myAudioPos: '',
      isplay: false
    })
    const item = e.currentTarget.dataset.item
    console.log(item, 'item0980');
    if (this.data.showData != '') {
@@ -255,7 +315,7 @@
        selectedId: e.currentTarget.dataset.index,
        showData: ''
      })
      console.log(e.currentTarget.dataset.index, 'e.currentTarget.dataset.index');
      if (item.selectType == "audio") {
        this.setData({
          showData: app.config.requestCtx + '/file/api/ApiDownload?md5=' + item.file
@@ -271,7 +331,6 @@
      appRefCode: app.config.appRefCode
    }).then((res) => {
      // console.log(res);
      this.setData({
        topicId: res.id
      })
@@ -310,7 +369,7 @@
  },
  confirmSuggest() {
    if (!this.data.textvalue) {
    if (!this.data.textvalue.trim()) {
      return wx.showToast({
        icon: 'error',
        title: '请填写笔记内容',
@@ -381,7 +440,7 @@
      res.datas.forEach((item) => {
        item.createDate = this.convertTimestamp(item.createDate)
        console.log(item, 'item789');
      })
      this.setData({
        "pageCount.total": res.totalSize,
@@ -410,13 +469,15 @@
    messageIds.push(id)
    wx.showModal({
      title: '提示',
      content: '确认删除该笔记吗?',//editable如果为true,这就是输入框的内容
      editable: false,//是否显示输入框
      placeholderText: '请输入内容吧',//输入框的默认内容
      content: '确认删除该笔记吗?', //editable如果为true,这就是输入框的内容
      editable: false, //是否显示输入框
      placeholderText: '请输入内容吧', //输入框的默认内容
      success: (res) => {
        if (res.confirm) {
          app.MG.ugc
            .delTopicMessage({ messageIds })
            .delTopicMessage({
              messageIds
            })
            .then((res) => {
              wx.showToast({
                title: '删除成功',
@@ -434,15 +495,15 @@
  },
  // 新建笔记接口
  async makeNote() {
    const token = wx.getStorageSync('jsek-token')
    if (!token) {
      return wx.getUserProfile({
        desc: '用户登录',
        success: (res) => {
          // console.log(res);
        }
      })
    }
    // const token = wx.getStorageSync('jsek-token')
    // if (!token) {
    //   return wx.getUserProfile({
    //     desc: '用户登录',
    //     success: (res) => {
    //       // console.log(res);
    //     }
    //   })
    // }
    let topicId
    await app.MG.ugc
      .getProductUserSubmitTopic({
@@ -520,15 +581,12 @@
  },
  // 播放公共代码
  pubulicPlayFun() {
    myAudio.src = this.data.showData
    console.log(myAudio.src);
    // console.log(myAudio.src);
    // 在onCanplay里获取并设置音频时长和播放进度
    myAudio.onCanplay(() => {
      myAudio.duration; //必须写,不然获取不到。。。
      setTimeout(() => {
        console.log(myAudio.duration, 'myAudio.duration');
        this.setData({
          myAudioDuration: this.format(myAudio.duration),
          myAudioCurrent: this.format(myAudio.currentTime)
@@ -562,19 +620,15 @@
  //播放  
  play() {
    console.log(22222);
    myAudio.startTime = this.data.myAudioCurrent; //考虑到进度条被拖动,不一定从00:00:00开始
    myAudio.play();
    this.setData({
      isplay: true
    });
  },
  // 停止
  stop() {
    myAudio.pause();
    this.setData({
      isplay: false
@@ -663,7 +717,7 @@
    setTimeout(() => {
      console.log(this.data.speed, 'this.data.speed');
      myAudio.startTime = this.data.myAudioDuration  //开始时间
      myAudio.startTime = this.data.myAudioDuration //开始时间
      myAudio.playbackRate = this.data.speed; //  播放速率
    }, 200);
  },