Commit c77b6ed2 by 张立顺

app.js 版本更新逻辑修复

1 parent 19b2f366
...@@ -13,7 +13,7 @@ import util from './utils/util.js' ...@@ -13,7 +13,7 @@ import util from './utils/util.js'
import './utils/Track' import './utils/Track'
import { ssoApi, wechatApi } from './api/api' import { ssoApi, wechatApi } from './api/api'
import { trackData } from './utils/data' import { trackData } from './utils/data'
import getUpdateManager from './utils/lib/wxUpdateManager'
import eventbus from './utils/evenbus' import eventbus from './utils/evenbus'
// 实例化对象存储 // 实例化对象存储
import { Storage } from './utils/cache/storage' import { Storage } from './utils/cache/storage'
...@@ -23,7 +23,7 @@ App({ ...@@ -23,7 +23,7 @@ App({
onLaunch: function (options) { onLaunch: function (options) {
console.log(options) console.log(options)
/**挂载到wx对象 */ /**挂载到wx对象 */
this.autoUpdate() // this.autoUpdate()
wx.$storage = $Storage /** 挂载全局缓存方法 */ wx.$storage = $Storage /** 挂载全局缓存方法 */
wx.$eventbus = eventbus wx.$eventbus = eventbus
wx.$util = util wx.$util = util
...@@ -43,6 +43,9 @@ App({ ...@@ -43,6 +43,9 @@ App({
// wx.showMeasure = false // wx.showMeasure = false
wx.showMeasure = !!options.query.scene wx.showMeasure = !!options.query.scene
}, },
onShow(options) {
getUpdateManager()
},
login(returnResponse) { login(returnResponse) {
let _this = this let _this = this
let openId = null let openId = null
...@@ -142,64 +145,64 @@ App({ ...@@ -142,64 +145,64 @@ App({
/** /**
* 下载小程序新版本并重启应用 * 下载小程序新版本并重启应用
*/ */
autoUpdate: function () { // autoUpdate: function () {
// // console.log(new Date())
// const self = this
// // 获取小程序更新机制兼容
// if (wx.canIUse('getUpdateManager')) {
// const updateManager = wx.getUpdateManager()
// //1. 检查小程序是否有新版本发布
// updateManager.onCheckForUpdate(function (res) {
// // 请求完新版本信息的回调
// if (res.hasUpdate) {
// //2. 小程序有新版本,则静默下载新版本,做好更新准备
// updateManager.onUpdateReady(function () {
// console.log(new Date()) // console.log(new Date())
const self = this
// 获取小程序更新机制兼容
if (wx.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager()
//1. 检查小程序是否有新版本发布
updateManager.onCheckForUpdate(function (res) {
// 请求完新版本信息的回调
if (res.hasUpdate) {
//2. 小程序有新版本,则静默下载新版本,做好更新准备
updateManager.onUpdateReady(function () {
console.log(new Date())
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function (res) {
if (res.confirm) {
//3. 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
} else if (res.cancel) {
//如果需要强制更新,则给出二次弹窗,如果不需要,则这里的代码都可以删掉了
// wx.showModal({ // wx.showModal({
// title: '温馨提示~', // title: '更新提示',
// content: '本次版本更新涉及到新的功能添加,旧版本无法正常访问的哦~', // content: '新版本已经准备好,是否重启应用?',
// success: function (res) { // success: function (res) {
// self.autoUpdate()
// return;
// //第二次提示后,强制更新
// if (res.confirm) { // if (res.confirm) {
// // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 // //3. 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
// updateManager.applyUpdate() // updateManager.applyUpdate()
// } else if (res.cancel) { // } else if (res.cancel) {
// //重新回到版本更新提示 // //如果需要强制更新,则给出二次弹窗,如果不需要,则这里的代码都可以删掉了
// self.autoUpdate() // // wx.showModal({
// // title: '温馨提示~',
// // content: '本次版本更新涉及到新的功能添加,旧版本无法正常访问的哦~',
// // success: function (res) {
// // self.autoUpdate()
// // return;
// // //第二次提示后,强制更新
// // if (res.confirm) {
// // // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
// // updateManager.applyUpdate()
// // } else if (res.cancel) {
// // //重新回到版本更新提示
// // self.autoUpdate()
// // }
// // }
// // })
// } // }
// } // }
// }) // })
} // })
} // updateManager.onUpdateFailed(function () {
}) // // 新的版本下载失败
}) // wx.showModal({
updateManager.onUpdateFailed(function () { // title: '已经有新版本了哟~',
// 新的版本下载失败 // content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
wx.showModal({ // })
title: '已经有新版本了哟~', // })
content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~' // }
}) // })
}) // } else {
} // // 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
}) // wx.showModal({
} else { // title: '提示',
// 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示 // content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
wx.showModal({ // })
title: '提示', // }
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。' // },
})
}
},
globalData: {} globalData: {}
}) })
{ {
"description": "项目配置文件,详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", "description": "项目配置文件,详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"packOptions": {
"ignore": [],
"include": []
},
"setting": { "setting": {
"urlCheck": false, "urlCheck": false,
"es6": true, "es6": false,
"enhance": true, "enhance": true,
"postcss": true, "postcss": true,
"preloadBackgroundData": false, "preloadBackgroundData": false,
...@@ -24,14 +20,12 @@ ...@@ -24,14 +20,12 @@
"compileHotReLoad": false, "compileHotReLoad": false,
"lazyloadPlaceholderEnable": false, "lazyloadPlaceholderEnable": false,
"useMultiFrameRuntime": true, "useMultiFrameRuntime": true,
"useApiHook": true,
"useApiHostProcess": true,
"babelSetting": { "babelSetting": {
"ignore": [], "ignore": [],
"disablePlugins": [], "disablePlugins": [],
"outputPath": "" "outputPath": ""
}, },
"useIsolateContext": false, "useIsolateContext": true,
"userConfirmedBundleSwitch": false, "userConfirmedBundleSwitch": false,
"packNpmManually": false, "packNpmManually": false,
"packNpmRelationList": [], "packNpmRelationList": [],
...@@ -39,15 +33,12 @@ ...@@ -39,15 +33,12 @@
"disableUseStrict": false, "disableUseStrict": false,
"minifyWXML": true, "minifyWXML": true,
"showES6CompileOption": false, "showES6CompileOption": false,
"ignoreUploadUnusedFiles": false, "ignoreUploadUnusedFiles": true,
"useCompilerPlugins": [ "useCompilerPlugins": [
"sass" "sass"
] ]
}, },
"compileType": "miniprogram", "compileType": "miniprogram",
"libVersion": "2.25.4",
"appid": "wx1bd947039419e6ce",
"projectname": "%E5%B9%BF%E8%81%94%E5%B0%8F%E7%A8%8B%E5%BA%8F%E6%A8%A1%E7%89%88",
"simulatorType": "wechat", "simulatorType": "wechat",
"simulatorPluginLibVersion": {}, "simulatorPluginLibVersion": {},
"editorSetting": { "editorSetting": {
...@@ -89,5 +80,9 @@ ...@@ -89,5 +80,9 @@
} }
] ]
} }
},
"packOptions": {
"ignore": [],
"include": []
} }
} }
\ No newline at end of file \ No newline at end of file
{ {
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"condition": { "condition": {},
"miniprogram": {
"list": [
{
"name": "分享组件",
"pathName": "tabComponents/pages/share/share",
"query": "",
"scene": null
},
{
"name": "授权组件",
"pathName": "tabComponents/pages/authorize/authorize",
"query": "",
"scene": null
},
{
"name": "时间范围选择器",
"pathName": "tabComponents/pages/time-horizon/time-horizon",
"query": "",
"scene": null
},
{
"name": "cell",
"pathName": "tabComponents/pages/gl-cell/gl-cell",
"query": "",
"scene": null
},
{
"name": "日历",
"pathName": "tabComponents/pages/calendar/calendar",
"query": "",
"scene": null
},
{
"name": "",
"pathName": "pages/addTransform/addTransform/addTransform",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "",
"pathName": "pages/tab/index/index",
"query": "scene=sceneId%3D3275",
"launchMode": "default",
"scene": null
},
{
"name": "",
"pathName": "pages/addValue/addValue/addValue",
"query": "scene=sceneId%3D3102",
"launchMode": "default",
"scene": null
},
{
"name": "数字无忧权益卡",
"pathName": "pages/productDetail/equity/equity",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "氛围灯",
"pathName": "pages/productDetail/ambientLighting/ambientLighting",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "AR导航",
"pathName": "pages/productDetail/arNavigation/arNavigation",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "数字化美容",
"pathName": "pages/productDetail/carBeauty/carBeauty",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "改色膜",
"pathName": "pages/productDetail/changingFilm/changingFilm",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "流失期",
"pathName": "pages/productDetail/lossPhase/lossPhase",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "360导航",
"pathName": "pages/productDetail/navigationArround/navigationArround",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "漆面保护",
"pathName": "pages/productDetail/paintProtect/paintProtect",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "座椅通风",
"pathName": "pages/productDetail/seatVentilate/seatVentilate",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "太阳膜",
"pathName": "pages/productDetail/solarFilm/solarFilm",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "",
"pathName": "pages/tab/index/index",
"query": "scene=sceneId%3D3275",
"launchMode": "default",
"scene": null
},
{
"name": "",
"pathName": "pages/newEnergy/newEnergy",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "",
"pathName": "pages/applySuccess/applySuccess",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "活动申请",
"pathName": "pages/activityApplication/activityApplication",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "展业测算",
"pathName": "pages/measure/measure/measure",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "测算结果",
"pathName": "pages/measure/measureResult/measureResult",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "",
"pathName": "pages/scene/scene",
"query": "",
"launchMode": "default",
"scene": null
}
]
}
},
"setting": { "setting": {
"urlCheck": false, "urlCheck": true,
"compileHotReLoad": false "compileHotReLoad": false
}, },
"libVersion": "2.26.1", "libVersion": "2.26.1",
......
const getUpdateManager = () => {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
// 请求完新版本信息的回调
})
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function (res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function () {
// 新版本下载失败
})
}
export default getUpdateManager
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!