Commit 07466c8f by 胡悦

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

1 parent 4b8de0db
let timer = null
import dayjs from 'dayjs' import dayjs from 'dayjs'
export default { export default {
data () { data () {
return { return {
systemInfo: {} systemInfo: {},
timer: null,
id: null
} }
}, },
onLoad (options) { onLoad (options) {
if (this.timer) {
clearInterval(this.timer);
this.timer = null;
}
const { row } = options const { row } = options
const _row = JSON.parse(row) const _row = JSON.parse(row)
this.systemInfo = _row this.systemInfo = _row
this.systemInfo.time = dayjs(new Date(_row.actualSendTime)).format("YYYY-MM-DD HH:mm:ss") this.systemInfo.time = dayjs(new Date(_row.actualSendTime)).format("YYYY-MM-DD HH:mm:ss")
this.addTrack(_row) this.addTrack(_row)
this.timer = setInterval(() => {
this.leaveTrack(this.id)
}, 3000)
}, },
methods: { methods: {
// 进入埋点事件 // 进入埋点事件
...@@ -25,9 +33,7 @@ export default { ...@@ -25,9 +33,7 @@ export default {
uni.$api.commonApi.addSystemInfo(entryData).then(res => { uni.$api.commonApi.addSystemInfo(entryData).then(res => {
if (res) { if (res) {
this.leaveTrack(res) this.leaveTrack(res)
timer = setInterval(() => { this.id = res
this.leaveTrack(res)
}, 3000)
} }
}) })
} catch (error) { } catch (error) {
...@@ -36,12 +42,14 @@ export default { ...@@ -36,12 +42,14 @@ export default {
}, },
// 离开埋点事件 // 离开埋点事件
async leaveTrack(id) { async leaveTrack(id) {
if (!id) return
await uni.$api.commonApi.leaveSystemInfo({id}) await uni.$api.commonApi.leaveSystemInfo({id})
} }
}, },
onUnload () { onUnload () {
if (timer) { if (this.timer) {
clearInterval(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!