quality.js 2.04 KB
// packageEquity/pages/newReceptionRecords/components/quality/quality.js
let thisPage = null
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    qualityData: Array
  },
  lifetimes: {
    ready() {
      this.getAudioObject()
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    activeIndex: 0,
    activeId: '',
    classifyId: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    reset() {
      this.setData({
        activeIndex: 0,
        activeId: '',
        classifyId: ''
      })
      this.getAudioObject()
    },
    getAudioObject() {
      thisPage = wx.p.router.getPageInstance()
      if (thisPage.qualityAudio) this.innerAudioContext = thisPage.qualityAudio
      else setTimeout(() => {
        this.getAudioObject()
      }, 100)
    },
    changeClassifyType(e) {
      let {
        index
      } = e.currentTarget.dataset, {
        activeIndex
      } = this.data
      if (activeIndex == index) return
      this.setData({
        activeIndex: index,
        classifyId: `classify-${index}`
      })
    },
    onTimeUpdate() {
      const {
        mergedOffset
      } = this.setProgress()
      this.setData({
        activeId: `text_${mergedOffset}`
      })
    },
    setProgress() {
      const {
        currentTime
      } = this.innerAudioContext,
        mergedOffset = Math.ceil(currentTime)
      return {
        currentTime,
        mergedOffset
      }
    },
    seekPlay(e) {
      let {
        activeId
      } = this.data, {
        item,
      } = e.currentTarget.dataset
      if (!item) return
      thisPage.seek(item.mergedOffset)
      if (item.text_id == activeId) {
        const {
          paused
        } = this.innerAudioContext
        if (paused) thisPage.play()
        else thisPage.onPause()
        thisPage.setData({
          isOperate: !paused
        })
      } else {
        thisPage.play()
        thisPage.setData({
          isOperate: false
        })
      }
    }
  }
})