App.vue
3.88 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<template>
<div id="app">
<template v-if="$route.meta.showNavBar && !isMiniprogram && showNavBar">
<div class="nav-bar">
<van-nav-bar
safe-area-inset-top
:title="$route.meta.title"
left-arrow
:fixed='true'
@click-left="onClickLeft"
/>
</div>
</template>
<div>
<transition name="fade">
<keep-alive>
<router-view
v-if="$route.meta.keepAlive"
class="main-box"
:class="{'app-box': showNavBar && $route.meta.showNavBar}"
v-wechat-title="$route.meta.title"
/>
</keep-alive>
</transition>
<transition name="fade">
<router-view
class="main-box"
:class="{'app-box': showNavBar && $route.meta.showNavBar}"
v-wechat-title="$route.meta.title"
v-if="!$route.meta.keepAlive"
/>
</transition>
</div>
</div>
</template>
<script>
// import VConsole from 'vconsole'
export default {
data() {
return {
isScroll: false,
pagename: "",
showNavBar: false
};
},
watch: {
// 如果路由有变化
$route(to) {
this.isScroll = false;
let name = to.name;
switch (name) {
case "common.marketing":
this.pagename = "营销页";
break;
case "equity.index":
this.pagename = "权益首页";
break;
case "commodity.recharge":
case "commodity.business":
this.pagename = "商品详情";
break;
case "oilStation.index":
this.pagename = "加油列表";
break;
case "cardRoll.customer":
this.pagename = "客服";
break;
default:
this.pagename = to.meta.title;
}
},
},
components: {},
created() {
const ua = navigator.userAgent.toLowerCase()
if (ua.match(/MicroMessenger/i) != 'micromessenger') {
this.showNavBar = true;
}
window.onload = function () {
let navigationStart = window.performance.timing.navigationStart.toString();
navigationStart = parseInt(navigationStart.substr(0, 10));
let domContentLoadedEventEnd =
window.performance.timing.domContentLoadedEventEnd.toString();
domContentLoadedEventEnd = parseInt(domContentLoadedEventEnd.substr(0, 10));
let logs = window.vm.trackConfig({
event: "loading_event",
properties: {
pagename: localStorage['pagename'],
enter_time: navigationStart,
leave_time: domContentLoadedEventEnd,
},
});
window.vm.track.collect(logs);
};
},
mounted() {
// window.vConsole = new VConsole()
//解决ios下history.back后不刷新
this.handleScroll();
var isPageHide = false;
window.addEventListener("pageshow", function () {
if (isPageHide) {
window.location.reload();
}
});
window.addEventListener("pagehide", function () {
isPageHide = true;
});
},
methods: {
onClickLeft() {
this.$router.go(-1)
},
handleScroll() {
window.addEventListener("scroll", () => {
if (!this.isScroll) {
let logs = window.vm.trackConfig({
event: "scroll_event",
properties: {
pagename: this.pagename,
isScroll: true,
},
});
window.vm.track.collect(logs);
this.isScroll = true;
}
});
},
},
};
</script>
<style scoped>
#app {
font-size: 14px;
}
.main-box {
width: 100%;
position: absolute;
left: 0px;
height: 100%;
overflow: scroll;
padding-bottom: 0px;
box-sizing: border-box!important;
}
.app-box {
box-sizing: border-box!important;
width: 100%;
position: absolute;
left: 0px;
overflow: scroll;
padding-bottom: 0px;
}
.app-box.main-box {
height: calc(100% - 46px);
}
.van-nav-bar {
z-index: 100;
}
.nav-bar {
height: 46px;
width: 100%;
}
</style>