Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jz_Travel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhengke
jz_Travel
Commits
c21900ae
Commit
c21900ae
authored
Jan 20, 2025
by
youjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
检测新版本并 更新版本
parent
05e25781
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
1 deletion
+58
-1
App.vue
App.vue
+1
-0
utils.js
plugin/utils.js
+57
-1
No files found.
App.vue
View file @
c21900ae
...
...
@@ -13,6 +13,7 @@ export default {
},
onShow
:
function
()
{
//console.log('App Show')
this
.
$utils
.
VersionUpdate
()
},
onHide
:
function
()
{
//console.log('App Hide')
...
...
plugin/utils.js
View file @
c21900ae
...
...
@@ -91,6 +91,61 @@ function SubscribeMsgAli(cb) {
})
}
// #endif
//定义更新方法
function
VersionUpdate
()
{
// 判断应用的 getUpdateManager 是否在当前版本可用
if
(
uni
.
canIUse
(
'getUpdateManager'
))
{
const
updateManager
=
uni
.
getUpdateManager
()
// 向小程序后台请求完新版本信息
updateManager
.
onCheckForUpdate
(
function
(
res
)
{
if
(
res
.
hasUpdate
)
{
//小程序有新版本,静默下载新版本,新版本下载完成
updateManager
.
onUpdateReady
(
function
()
{
//模态弹窗(确认、取消)
uni
.
showModal
({
title
:
'更新提示'
,
content
:
'小程序已发布新版本,是否重启?'
,
success
:
function
(
res
)
{
//用户点击确定
if
(
res
.
confirm
)
{
//当新版本下载完成,调用该方法会强制当前小程序应用上新版本并重启
updateManager
.
applyUpdate
()
}
//用户点击取消
else
if
(
res
.
cancel
)
{
//强制用户更新,弹出第二次弹窗
uni
.
showModal
({
title
:
'提示'
,
content
:
'小程序已发布新版本,是否重启'
,
showCancel
:
false
,
//隐藏取消按钮
success
:
function
(
res
)
{
//第二次提示后,强制更新
if
(
res
.
confirm
)
{
// 当新版本下载完成,调用该方法会强制当前小程序应用上新版本并重启
updateManager
.
applyUpdate
()
}
}
})
}
}
})
})
// 当新版本下载失败
updateManager
.
onUpdateFailed
(
function
()
{
uni
.
showModal
({
title
:
'提示'
,
content
:
'请您删除当前小程序,重新打开小程序'
,
})
})
}
})
}
else
{
// 提示用户在最新版本的客户端上体验
uni
.
showModal
({
title
:
'温馨提示'
,
content
:
'当前微信版本过低,可能无法使用该功能,请升级到最新版本后重试。'
})
}
}
export
default
{
calcContentHeight
,
...
...
@@ -98,6 +153,7 @@ export default {
getRect
,
getretailer
,
// #ifdef MP-ALIPAY
SubscribeMsgAli
SubscribeMsgAli
,
// #endif
VersionUpdate
,
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment