click.js 2.52 KB
/*
 * @Author: 前端 qianduan01@didihu.com.cn
 * @Date: 2024-04-08 11:28:48
 * @LastEditors: limin
 * @LastEditTime: 2024-12-06 14:46:47
 * @FilePath: \gl_tape\utils\recordManager\click.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import utils from '@/utils/utils.js'
import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update-nvue.js'
const timer = Object.freeze({
  duration: 40 * 60 * 1000,
  interval: 30 * 1000,
  timeout: duration / interval
})
let counter = 0
let timer_interval = null
export default {
  data() {
    return {
      reaction: 1
    }
  },
  async mounted() {
    this.versionCheck() // 检查更新
  },
  methods: {
    versionCheck() {
      const { textList, tempFileURL, version } = uni.$storage.get('mock_data')
      const res = utils.compareVersions(plus?.runtime?.version, version)
      if (res > -1) {
        return
      }
      const e = {
        result: {
          is_silently: false,
          is_mandatory: true,
          name: '',
          title: '',
          contents: textList.join('\n'),
          version: version,
          url: tempFileURL,
          stable_publish: true
        }
      }
      checkUpdate(e)
    },
    // //关闭提示
    tipCancel() {
      this.audioManager.stop()
      this.saveRecord()
      this.setReceptionStatus(0)
      this.setAudioInfo({ endReasonType: 1 })
      if (this.$refs.tipBox) {
        this.$refs.tipBox.close()
        let { sceneType } = uni.$storage.get('userInfo')
        uni.reLaunch({
          url: sceneType == 0 ? '/pages/equity/index' : '/pages/boutique/index'
        })
      }
    },

    async saveRecord() {
      const preRecord = this.record.preRecord
      return this.record.save(preRecord)
    },
    //结束提示
    tipConfirm() {
      counter = 0
      this.$refs.tipBox?.close()
    },
    closeAudio() {
      this.endWatchClick()
      this.audioManager.stop()
      this.setReceptionStatus(0)
      this.setAudioInfo({ endReasonType: 1 })
    },
    //监听点击事件
    initTime() {
      this.endWatchClick()
      timer_interval = setInterval(() => {
        if (counter >= timer.timeout) {
          //关闭录音
          this.closeAudio()
        }
        counter++
      }, timer.interval)
    },
    endWatchClick() {
      if (timer_interval) clearInterval(timer_interval)
      timer_interval = null
      counter = 0
    },
    handleTouchStart() {
      counter = 0
    }
  }
}