xiaoxin 1 gadu atpakaļ
vecāks
revīzija
075e1be858

+ 38 - 3
App.vue

@@ -1,9 +1,44 @@
 <script>
 export default {
-	onLaunch: function () {
-		// console.warn('当前组件仅支持 uni_modules 目录结构 ,请升级 HBuilderX 到 3.1.0 版本以上!')
-		// console.log('App Launch')
+	onLaunch() {
+		// 获取小程序更新机制兼容
+		if (uni.canIUse('getUpdateManager')) {
+			const updateManager = uni.getUpdateManager()
+			// 检查是否有新版本发布
+			updateManager.onCheckForUpdate((res) => {
+				if (res.hasUpdate) {
+					//小程序有新版本,则静默下载新版本,做好更新准备
+					updateManager.onUpdateReady(() => {
+						uni.showModal({
+							title: '更新提示',
+							content: '新版本已经准备好,请重启应用',
+							showCancel: false,
+							success: (res) => {
+								if (res.confirm) {
+									//新的版本已经下载好,调用 applyUpdate 应用新版本并重启
+									updateManager.applyUpdate()
+								}
+							}
+						})
+					})
+					// 新的版本下载失败
+					updateManager.onUpdateFailed(() => {
+						uni.showModal({
+							title: '温馨提示',
+							content: '新版本已经上线,请您删除当前小程序,重新搜索打开'
+						})
+					})
+				}
+			})
+		} else {
+			// 提示用户在最新版本的客户端上体验
+			uni.showModal({
+				title: '温馨提示',
+				content: '当前微信版本过低,可能无法使用该功能,请升级到最新版本后重试。'
+			})
+		}
 	},
+
 	onShow: function () {
 		// console.log('App Show')
 	},

+ 31 - 1
unpackage/dist/dev/mp-weixin/app.js

@@ -33,7 +33,37 @@ if (!Math) {
   "./pagesWarning/home/home.js";
 }
 const _sfc_main = {
-  onLaunch: function() {
+  onLaunch() {
+    if (common_vendor.index.canIUse("getUpdateManager")) {
+      const updateManager = common_vendor.index.getUpdateManager();
+      updateManager.onCheckForUpdate((res) => {
+        if (res.hasUpdate) {
+          updateManager.onUpdateReady(() => {
+            common_vendor.index.showModal({
+              title: "更新提示",
+              content: "新版本已经准备好,请重启应用",
+              showCancel: false,
+              success: (res2) => {
+                if (res2.confirm) {
+                  updateManager.applyUpdate();
+                }
+              }
+            });
+          });
+          updateManager.onUpdateFailed(() => {
+            common_vendor.index.showModal({
+              title: "温馨提示",
+              content: "新版本已经上线,请您删除当前小程序,重新搜索打开"
+            });
+          });
+        }
+      });
+    } else {
+      common_vendor.index.showModal({
+        title: "温馨提示",
+        content: "当前微信版本过低,可能无法使用该功能,请升级到最新版本后重试。"
+      });
+    }
   },
   onShow: function() {
   },

+ 1 - 27
unpackage/dist/dev/mp-weixin/project.private.config.json

@@ -4,32 +4,6 @@
   "setting": {
     "compileHotReLoad": true
   },
-  "condition": {
-    "miniprogram": {
-      "list": [
-        {
-          "name": "pages/track/track",
-          "pathName": "pages/track/track",
-          "query": "id=1049",
-          "launchMode": "default",
-          "scene": null
-        },
-        {
-          "name": "pages/statistics/statistics",
-          "pathName": "pages/statistics/statistics",
-          "query": "",
-          "launchMode": "default",
-          "scene": null
-        },
-        {
-          "name": "pages/login2/login2",
-          "pathName": "pages/login2/login2",
-          "query": "",
-          "launchMode": "default",
-          "scene": null
-        }
-      ]
-    }
-  },
+  "condition": {},
   "libVersion": "3.4.5"
 }