App.vue
1.9 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
<script setup>
import { onLaunch } from '@dcloudio/uni-app'
import useUserStore from '@/store/modules/user.js'
const userStore = useUserStore()
const autoUpdate = () => {
// 判断当前版本是否兼容api更新
if(uni.canIUse('getUpdateManager')) {
const updateManager = uni.getUpdateManager() //1. 检查小程序是否有新版本发布
updateManager.onCheckForUpdate(function (res) { // 请求完新版本信息的回调
if(res.hasUpdate) { //2. 小程序有新版本,则静默下载新版本,做好更新准备
updateManager.onUpdateReady(function () {
uni.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function (successInfo) {
if (successInfo.confirm) {
//3. 新的版本已经下载好,调用applyUpdate应用新版本并重启
updateManager.applyUpdate()
} else if (successInfo.cancel) {
console.log('用户点击取消')
}
}
})
})
// 新的版本下载失败
updateManager.onUpdateFailed(function () {
wx.showModal({
title: '已经有新版本了哟~',
content: '新版本已经上线啦,请您删除当前小程序,在保险服务号入口重新进入',
})
})
}
})
} else {
// 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
uni.showModal({
title: '提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
})
}
}
onLaunch(() => {
autoUpdate()
})
</script>
<style lang="scss">
/*每个页面公共css */
/* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
@import "@/uni_modules/uview-plus/index.scss";
view {
box-sizing: border-box;
}
image{
max-width: 100% !important;
}
</style>