Explorar o código

feat:更新检查优化

zhanghui %!s(int64=2) %!d(string=hai) anos
pai
achega
17d0303e2d
Modificáronse 1 ficheiros con 27 adicións e 18 borrados
  1. 27 18
      pages/index/index.vue

+ 27 - 18
pages/index/index.vue

@@ -563,24 +563,33 @@ export default {
       updateManager.onCheckForUpdate(function (res) {
         // 请求完新版本信息的回调
         console.log('++++++++++onCheckForUpdate++++++++++',res.hasUpdate);
-      });
-
-      updateManager.onUpdateReady(function (res) {
-        uni.showModal({
-          title: '更新提示',
-          content: '新版本已经准备好,是否重启应用?',
-          success(res) {
-            if (res.confirm) {
-              // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
-              updateManager.applyUpdate();
-            }
-          }
-        });
-
-      });
-
-      updateManager.onUpdateFailed(function (res) {
-        // 新的版本下载失败
+        if (res.hasUpdate){
+
+          updateManager.onUpdateReady(function (res) {
+            console.log('+++++++++onUpdateReady+++++++++++++',res)
+            uni.showModal({
+              title: '更新提示',
+              content: '新版本已经准备好,是否重启应用?',
+              showCancel:false,
+              success(res) {
+                if (res.confirm) {
+                  // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
+                  updateManager.applyUpdate();
+                }
+              }
+            });
+          });
+
+          updateManager.onUpdateFailed(function (res) {
+            // 新的版本下载失败
+            console.log('+++++++++onUpdateFailed+++++++++++++',res)
+            uni.showModal({
+              title: '更新提示',
+              content: '检测到小程序更新,但是下载失败,请检查网络',
+              showCancel:false
+            });
+          });
+        }
       });
     },