msgwebview.vue 1.71 KB
<!--
 * @Author: 前端 qianduan01@didihu.com.cn
 * @Date: 2024-04-28 18:19:19
 * @LastEditors: 前端 qianduan01@didihu.com.cn
 * @LastEditTime: 2024-09-06 14:42:32
 * @FilePath: \gl-tape\pages\common\webview.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <web-view :src="url"></web-view>
</template>

<script type="text/ecmascript-6">
let timer = null
export default {
  name: '',
  data () {
    return {
      url: '',
      viewerUrl: '/hybrid/html/web/viewer.html',
    }
  },
  onLoad (options) {
    console.log(options,'options')
    if(options.fileUrl) this.url = `${this.viewerUrl}?file=${options.fileUrl}`
    else this.url = options.url
    if (options.title) uni.setNavigationBarTitle({
      title: options.title
    })
    this.addTrack(options)
  },
  mounted () {
  },
  beforeDestroy() {
    if (timer) {
      clearInterval(timer);
    }
  },
  methods: {
    // 进入埋点事件
    addTrack(row) {
      console.log(row)
      try {
        const {phone} = uni.$storage.get("userInfo")
        const entryData = {
          taskId: row.id,
          phoneNumber: phone
        }
        uni.$api.commonApi.addSystemInfo(entryData).then(res => {
          if (res) {
            this.leaveTrack(res)
            timer = setInterval(() => {
              this.leaveTrack(res)
            }, 3000)
          }
        })
      } catch (error) {
        console.error('进入埋点发生错误', error);
      }
    },
    // 离开埋点事件
    async leaveTrack(id) {
      await uni.$api.commonApi.leaveSystemInfo({id})
    }
  }
}
</script>

<style scoped lang="scss"></style>