| <script> | |
| 	 | |
| 	export default { | |
| 		onLaunch: function() { | |
| 			this.checkUpdate(); | |
| 		}, | |
| 		onShow: function() { | |
| 			this.$store.commit('initConfig') | |
| 		}, | |
| 		onHide: function() { | |
| 			 | |
| 		}, | |
| 		methods: { | |
| 		  checkUpdate() { | |
| 		    if (wx.getUpdateManager) { | |
| 		      const updateManager = wx.getUpdateManager(); | |
| 		 | |
| 		      // 监听是否有新版本 | |
| 		      updateManager.onCheckForUpdate((res) => { | |
| 		        console.log("是否有新版本:", res.hasUpdate); | |
| 		      }); | |
| 		 | |
| 		      // 监听新版本下载完成 | |
| 		      updateManager.onUpdateReady(() => { | |
| 		        wx.showModal({ | |
| 		          title: "更新提示", | |
| 		          content: "新版本已经准备好,是否重启应用?", | |
| 		          success: (res) => { | |
| 		            if (res.confirm) { | |
| 		              updateManager.applyUpdate(); // 强制应用新版本 | |
| 		            } | |
| 		          }, | |
| 		        }); | |
| 		      }); | |
| 		 | |
| 		      // 监听更新失败 | |
| 		      updateManager.onUpdateFailed(() => { | |
| 		        wx.showModal({ | |
| 		          title: "更新失败", | |
| 		          content: "请删除小程序后重新打开。", | |
| 		        }); | |
| 		      }); | |
| 		    } else { | |
| 		      console.log("当前基础库版本不支持更新管理"); | |
| 		    } | |
| 		  }, | |
| 		} | |
| 	} | |
| </script> | |
| 
 | |
| <style lang="scss"> | |
| 	@import "@/uni_modules/uview-ui/index.scss"; | |
| 	@import './styles/index.scss'; | |
| </style>
 |