App.vue
6.1 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<template>
<div class="app" id="app" :style="{ paddingTop: systemInfo.statusHeight + 'px' }">
<MyNavBar
:offset-top="systemInfo.statusHeight"
:title="$route.meta.title"
:show="getIsApp && $route.meta.isTabBarMenu && $route.meta.showNavBar"
:right-text="rightBtnText"
@right-callback="othersBtnFun"
/>
<MyNavBar
:offset-top="systemInfo.statusHeight"
:title="$route.meta.title"
:show="getIsApp && !$route.meta.isTabBarMenu && $route.meta.showNavBar"
:left-arrow="true"
:left-arrow-style="{ color: '#f00' }"
:right-text="rightBtnText"
left-text="返回"
@left-callback="backPrePage"
@right-callback="othersBtnFun"
/>
<div class="router-page-view" :style="{ marginTop: getAppNavBarShow ? '46px' : '' }" :class="{ 'is-tab-bar-menu-page': $route.meta.isTabBarMenu }">
<!-- <keep-alive :include="keepAlivePageNameList"> -->
<router-view />
<!-- </keep-alive> -->
</div>
<template v-if="$route.meta.isTabBarMenu">
<MyTabBar v-model="currentTabBarName" :tab-bar-list="tabBarList" @change="tabBarChange" />
</template>
<MyDialog
:show-popup="dialogOpen"
:title="myDialogConfig.title"
:description="myDialogConfig.description"
:descriptionType="myDialogConfig.descriptionType"
:show-cancel-btn="true"
:cancel-btn-text="myDialogConfig.cancelBtnText"
:ok-close="true"
@ok="dialogOk"
@cancel="dialogCancel"
/>
<MyToast loading-icon="icon-loading-1" ref="myToast" />
<!-- <MyConsole ref="MyConsole" theme="dark" /> -->
</div>
</template>
<script>
import { versionFormatting } from '@/libs/tools'
import { getVersionApi } from '@/apis/commApis'
import MyNavBar from '@/components/MyNavBar/MyNavBar.vue'
import MyTabBar from '@/components/MyTabBar/MyTabBar.vue'
import MyDialog from '@/components/MyDialog/MyDialog.vue'
import MyToast from '@/components/MyToast/MyToast.vue'
import MyConsole from '@/components/MyConsole/MyConsole.vue'
const myDialogConfig = {
title: '提示',
description: '',
descriptionType: 'html',
cancelBtnText: '取消'
}
export default {
name: 'myApp',
components: {
MyNavBar,
MyTabBar,
MyDialog,
MyToast,
MyConsole
},
data() {
return {
currentTabBarName: '',
dialogOpen: false,
isOpenToast: false,
systemInfo: {
version: '0.0.0',
statusHeight: 0
},
newVersion: '',
myDialogConfig: myDialogConfig,
rightBtnText: '',
loadingToast: null
}
},
computed: {
keepAlivePageNameList() {
return this.$router.options.routes
.filter(item => {
return item.meta.keepAlive
})
.map(item => {
return item.name
})
},
tabBarList() {
return this.$router.options.routes
.filter(item => {
return item.meta.isTabBarMenu
})
.map(item => {
return {
name: item.name,
icon: item.meta.icon,
label: item.meta.title
}
})
}
},
watch: {
$route(newVal) {
if (this.getIsApp) {
this.$store.commit('setAppNavBarShow', newVal.meta.showNavBar)
}
}
},
created() {
if (this.getIsApp) {
this.$store.commit('setAppNavBarShow', this.$route.meta.showNavBar)
// 监听App端传过来的系统信息
webf.methodChannel.addMethodCallHandler('postSystemInfo', event => {
console.log('event:', event)
this.systemInfo = event
this.$store.commit('setSystemInfo', event)
})
// 监听下载进度
webf.methodChannel.addMethodCallHandler('updateVersionProgress', event => {
this.loadingToast.ylTotasHintText = `下载中 ${event.toFixed(2)}%`
if (event === 100) {
this.loadingToast.ylTotasOpen = false
this.dialogOk = this.updateVerOkRestart
this.myDialogConfig.title = '下载完成'
this.myDialogConfig.description = '重启App即可更新'
this.myDialogConfig.cancelBtnText = '稍后重启'
this.dialogOpen = true
}
})
}
},
async mounted() {
setTimeout(() => {
this.currentTabBarName = this.$route.name
}, 60)
if (this.getIsApp) {
// 如果是APP,需要检查版本号判断有没有更新
try {
let res = await getVersionApi()
let oldVersion = versionFormatting(this.systemInfo.version)
let newVersion = versionFormatting(res.currentVersion)
this.newVersion = res.currentVersion
if (newVersion - oldVersion > 0) {
this.myDialogConfig.title = '更新提示'
this.myDialogConfig.description = res.description
this.dialogOpen = true
}
} catch (error) {
console.log('error:', error)
}
}
},
methods: {
// tabBar切换
tabBarChange(event) {
this.$router.replace({
name: event.name
})
},
backPrePage() {
console.log('返回:')
this.$router.go(-1)
},
othersBtnFun() {
console.log('this.getAppNavBarShow:', this.getAppNavBarShow)
},
dialogCancel() {
this.rightBtnText = '立即更新'
},
dialogOk() {
webf.methodChannel.invokeMethod('updateVersionDownloadConfirm', {
msg: '确定更新',
newVersion: this.newVersion
})
this.dialogOpen = false
this.loadingToast = this.$refs.myToast.loading({
hintText: '下载中',
duration: 0,
isOpen: true
})
},
// 确定重启更新-触发flutter中webf监听的事件
updateVerOkRestart() {
webf.methodChannel.invokeMethod('updateVersionRestart', {
msg: '确定更新重启'
})
}
}
}
</script>
<style lang="scss">
@import '@/assets/style/iconfont/iconfont.css';
@import '@/assets/style/vant-icon/vant-icon.css';
// @import '@/assets/style/common.scss';
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.router-page-view {
overflow-x: hidden;
&.is-tab-bar-menu-page {
padding-bottom: 54px;
}
}
#app {
overflow-x: hidden;
.my-tabbar-view {
position: fixed;
left: 0;
bottom: 0;
z-index: 999;
width: 100%;
}
}
</style>