Feat(页面):监听页面打开次数和页面停留时长接口对接
This commit is contained in:
+15
-12
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user