App.vue
1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<template>
<div id="app">
<template v-if="showWindow">
<transition name="fade">
<keep-alive v-if="$route.meta.keepAlive">
<router-view></router-view>
</keep-alive>
</transition>
<transition name="fade">
<router-view v-if="!$route.meta.keepAlive"></router-view>
</transition>
</template>
<action v-show="$route.meta.showAction && !$store.state.app.isLiveFull"></action>
</div>
</template>
<script>
import { bigdatautilApi } from '@/api'
export default {
name: 'App',
data() {
return {
timer: null
}
},
watch: {
watchFlag: {
immediate: true,
handler(newval) {
this.showWindow = newval
this.hideLoading()
}
},
wacthLoginStatus: {
immediate: true,
handler(newval) {
if (newval) {
console.log('触发埋点')
this.init()
}
}
}
},
computed: {
watchFlag() {
return this.$store.state.app.showWindow
},
wacthLoginStatus() {
return this.$store.state.app.loginStatus
}
},
mounted() {},
methods: {
init() {
this.openListener()
window.addEventListener('pagehide', () => {
this.leave()
this.closeListener()
// console.log('页面要关闭了')
})
},
// 心跳检测
openListener() {
this.timer = setInterval(() => {
this.heartbeat()
}, 60 * 1000)
},
closeListener() {
clearInterval(this.timer)
},
// 心跳检测
heartbeat() {
this.trackFn('heartbeat', 5)
},
//离开事件
leave() {
// console.log('离开时间')
this.trackFn('leaveReportTrack', 5)
},
trackFn(name, actionType) {
const { id } = this.getQuery()
bigdatautilApi[name](id, actionType)
}
}
}
</script>