Эх сурвалжийг харах

检测新sw,登录按钮提示

Michael Wang 6 жил өмнө
parent
commit
7fce52d0d1

+ 9 - 1
src/features/Login/Login.vue

@@ -86,7 +86,7 @@
                 :loading="loginBtnLoading"
                 @click="login"
               >
-                登录
+                {{ newVersionAvailable ? "点击更新版本" : "登录" }}
               </i-button>
             </i-form-item>
           </i-form>
@@ -144,6 +144,7 @@ export default {
       },
       disableLoginBtn: true,
       loginBtnLoading: false,
+      newVersionAvailable: false,
       VUE_APP_GIT_REPO_VERSION: process.env.VUE_APP_GIT_REPO_VERSION,
     };
   },
@@ -169,6 +170,12 @@ export default {
     // alread precached
     // fetch("/models/tiny_face_detector_model-shard1");
     // fetch("/models/face_landmark_68_model-shard1");
+
+    this.checkNewVersionInterval = setInterval(() => {
+      if (window.__newSWAvailable) {
+        this.newVersionAvailable = true;
+      }
+    }, 1000);
   },
   async created() {
     if (
@@ -293,6 +300,7 @@ export default {
   },
   beforeDestroy() {
     clearTimeout(this.loginTimeout);
+    clearInterval(this.checkNewVersionInterval);
   },
   methods: {
     ...mapMutations(["updateUser", "updateTimeDifference"]),

+ 1 - 0
src/registerServiceWorker.js

@@ -15,6 +15,7 @@ if (process.env.NODE_ENV === "production") {
     },
     updated() {
       console.log("New content is available; please refresh.");
+      window.__newSWAvailable = true;
     },
     offline() {
       console.log(