优化小程序版本更新检测逻辑,增强用户体验。新增扫码功能,支持用户通过扫一扫获取信息并展示解析结果,提升交互性。更新样式以适应新功能,确保界面友好。

This commit is contained in:
乘风
2026-02-13 09:59:08 +08:00
parent 808c959a20
commit 0f9633b8f0
5 changed files with 121 additions and 74 deletions

View File

@@ -240,36 +240,40 @@ App({
}
},
// 检查更新
// 版本更新检测:发现新版本时提示用户立即更新
checkUpdate() {
if (wx.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate((res) => {
if (res.hasUpdate) {
console.log('发现新版本')
if (!wx.canIUse('getUpdateManager')) return
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate((res) => {
if (res.hasUpdate) {
console.log('[App] 发现新版本,正在后台下载')
wx.showToast({ title: '发现新版本,正在准备…', icon: 'none', duration: 2000 })
}
})
updateManager.onUpdateReady(() => {
wx.showModal({
title: '发现新版本',
content: '小程序已更新,请立即重启以使用最新版本。',
confirmText: '立即更新',
cancelText: '稍后',
showCancel: true,
success: (res) => {
if (res.confirm) {
updateManager.applyUpdate()
}
}
})
updateManager.onUpdateReady(() => {
wx.showModal({
title: '更新提示',
content: '新版本已准备好,是否重启应用?',
success: (res) => {
if (res.confirm) {
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(() => {
wx.showModal({
title: '更新失败',
content: '新版本下载失败,请稍后重新打开小程序或删除后重新搜索打开。',
showCancel: false
})
updateManager.onUpdateFailed(() => {
wx.showToast({
title: '更新失败,请稍后重试',
icon: 'none'
})
})
}
})
},
/**