Feat(页面):监听页面打开次数和页面停留时长接口对接

This commit is contained in:
lifizer
2024-06-13 18:09:35 +08:00
parent 51bc828dc9
commit 344e0aa888
8 changed files with 131 additions and 36 deletions
+15 -12
View File
@@ -1,15 +1,18 @@
import {
pageToWatchShowCount,
pageToWatchShowTimer
pageToWatchShowTimer,
getCurrDateTime,
TimeDifference
} from '@/utils/util'
export const pageListenMixins = {
data(){
return {
pageTimer: null
pageViewDateTime: ''
}
},
onShow() {
this.pageToWatchShowCount(this.pageKeyId, this.pageShowTimerFn())
this.pageViewDateTime = getCurrDateTime()
this.pageToWatchShowCount(this.pageKeyId)
},
onHide() {
this.clearPageTimerFn()
@@ -17,17 +20,17 @@ export const pageListenMixins = {
methods: {
pageToWatchShowCount,
pageToWatchShowTimer,
pageShowTimerFn() {
this.pageTimer = setInterval(() => {
console.log('----页面监听----%s', this.pageKeyId)
this.pageToWatchShowTimer(this.pageKeyId)
}, 1000)
},
clearPageTimerFn() {
if (this.pageTimer) {
console.log('清除页面监听-----%s', this.pageKeyId)
clearInterval(this.pageTimer)
const visitTime = TimeDifference(this.pageViewDateTime, getCurrDateTime())
if (visitTime > 0) {
this.pageToWatchShowTimer(this.pageKeyId, {
statsName: this.pageKeyId,
statsTime: this.pageViewDateTime,
visitTime
})
}
this.pageViewDateTime = ''
console.log('清除页面监听-----%s', this.pageKeyId)
}
}
}