Commit 07466c8f by 胡悦

修复系统消息埋点,定时器未清除问题

1 parent 4b8de0db
let timer = null
import dayjs from 'dayjs'
export default {
data () {
return {
systemInfo: {}
systemInfo: {},
timer: null,
id: null
}
},
onLoad (options) {
if (this.timer) {
clearInterval(this.timer);
this.timer = null;
}
const { row } = options
const _row = JSON.parse(row)
this.systemInfo = _row
this.systemInfo.time = dayjs(new Date(_row.actualSendTime)).format("YYYY-MM-DD HH:mm:ss")
this.addTrack(_row)
this.timer = setInterval(() => {
this.leaveTrack(this.id)
}, 3000)
},
methods: {
// 进入埋点事件
......@@ -25,9 +33,7 @@ export default {
uni.$api.commonApi.addSystemInfo(entryData).then(res => {
if (res) {
this.leaveTrack(res)
timer = setInterval(() => {
this.leaveTrack(res)
}, 3000)
this.id = res
}
})
} catch (error) {
......@@ -36,12 +42,14 @@ export default {
},
// 离开埋点事件
async leaveTrack(id) {
if (!id) return
await uni.$api.commonApi.leaveSystemInfo({id})
}
},
onUnload () {
if (timer) {
clearInterval(timer);
if (this.timer) {
clearInterval(this.timer);
this.timer = null;
}
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!