mo 1 rok temu
rodzic
commit
c01ee61789
4 zmienionych plików z 94 dodań i 61 usunięć
  1. 43 34
      dev-dist/sw.js
  2. 26 26
      index.html
  3. 24 0
      src/router/router-guards.ts
  4. 1 1
      src/views/login/index.tsx

+ 43 - 34
dev-dist/sw.js

@@ -20,23 +20,21 @@ if (!self.define) {
   let nextDefineUri;
 
   const singleRequire = (uri, parentUri) => {
-    uri = new URL(uri + ".js", parentUri).href;
-    return registry[uri] || (
-      
-        new Promise(resolve => {
-          if ("document" in self) {
-            const script = document.createElement("script");
-            script.src = uri;
-            script.onload = resolve;
-            document.head.appendChild(script);
-          } else {
-            nextDefineUri = uri;
-            importScripts(uri);
-            resolve();
-          }
-        })
-      
-      .then(() => {
+    uri = new URL(uri + '.js', parentUri).href;
+    return (
+      registry[uri] ||
+      new Promise(resolve => {
+        if ('document' in self) {
+          const script = document.createElement('script');
+          script.src = uri;
+          script.onload = resolve;
+          document.head.appendChild(script);
+        } else {
+          nextDefineUri = uri;
+          importScripts(uri);
+          resolve();
+        }
+      }).then(() => {
         let promise = registry[uri];
         if (!promise) {
           throw new Error(`Module ${uri} didn’t register its module`);
@@ -47,7 +45,10 @@ if (!self.define) {
   };
 
   self.define = (depsNames, factory) => {
-    const uri = nextDefineUri || ("document" in self ? document.currentScript.src : "") || location.href;
+    const uri =
+      nextDefineUri ||
+      ('document' in self ? document.currentScript.src : '') ||
+      location.href;
     if (registry[uri]) {
       // Module is already loading or loaded.
       return;
@@ -59,15 +60,16 @@ if (!self.define) {
       exports,
       require
     };
-    registry[uri] = Promise.all(depsNames.map(
-      depName => specialDeps[depName] || require(depName)
-    )).then(deps => {
+    registry[uri] = Promise.all(
+      depsNames.map(depName => specialDeps[depName] || require(depName))
+    ).then(deps => {
       factory(...deps);
       return exports;
     });
   };
 }
-define(['./workbox-5357ef54'], (function (workbox) { 'use strict';
+define(['./workbox-5357ef54'], function (workbox) {
+  'use strict';
 
   self.skipWaiting();
   workbox.clientsClaim();
@@ -77,16 +79,23 @@ define(['./workbox-5357ef54'], (function (workbox) { 'use strict';
    * requests for URLs in the manifest.
    * See https://goo.gl/S9QRab
    */
-  workbox.precacheAndRoute([{
-    "url": "registerSW.js",
-    "revision": "3ca0b8505b4bec776b69afdba2768812"
-  }, {
-    "url": "index.html",
-    "revision": "0.75vo45gt8f8"
-  }], {});
+  workbox.precacheAndRoute(
+    [
+      {
+        url: 'registerSW.js',
+        revision: '3ca0b8505b4bec776b69afdba2768812'
+      },
+      {
+        url: 'index.html',
+        revision: '0.75vo45gt8f8'
+      }
+    ],
+    {}
+  );
   workbox.cleanupOutdatedCaches();
-  workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
-    allowlist: [/^\/$/]
-  }));
-
-}));
+  workbox.registerRoute(
+    new workbox.NavigationRoute(workbox.createHandlerBoundToURL('index.html'), {
+      allowlist: [/^\/$/]
+    })
+  );
+});

+ 26 - 26
index.html

@@ -176,32 +176,32 @@
         console.log(e, '这是js的报错 希望可以从错误类型判断')
       }, true)
 
-      if ('serviceWorker' in navigator) {
-        let refreshing = false
-        let flag = caches.keys().length > 0
-        console.log(caches.keys(), 'caches.keys()', `是否有缓存${flag}`);
-        caches.keys().then(function (cacheNames) {
-          cacheNames.forEach(function (cacheName) {
-            caches.delete(cacheName);
-          });
-          if (flag) {
-            window.location.reload()
-          }
-        });
-
-        // 尝试监听install
-
-
-      }
-      let refreshing = false
-      navigator.serviceWorker.addEventListener('controllerchange', () => {
-        console.log('controllerchange')
-        if (refreshing) {
-          return
-        }
-        refreshing = true;
-        window.location.reload();
-      })
+      // if ('serviceWorker' in navigator) {
+      //   // let refreshing = false
+      //   let flag = caches.keys().length > 0
+      //   console.log(caches.keys(), 'caches.keys()', `是否有缓存${flag}`);
+      //   caches.keys().then(function (cacheNames) {
+      //     cacheNames.forEach(function (cacheName) {
+      //       caches.delete(cacheName);
+      //     });
+      //     if (flag) {
+      //       window.location.reload()
+      //     }
+      //   });
+
+      //   // 尝试监听install
+
+
+      // }
+      // let refreshing = false
+      // navigator.serviceWorker.addEventListener('controllerchange', () => {
+      //   console.log('controllerchange')
+      //   if (refreshing) {
+      //     return
+      //   }
+      //   refreshing = true;
+      //   window.location.reload();
+      // })
 
 
       if (!isChrome()) {

+ 24 - 0
src/router/router-guards.ts

@@ -29,6 +29,30 @@ export function createRouterGuards(router: Router) {
     // console.log(to, '修改标题');
     // console.log('access token');
     document.title = to.meta.title ? to.meta.title : ('音乐数字课堂' as string);
+    if ('serviceWorker' in navigator) {
+      // let refreshing = false
+      const flag = (await caches.keys()).length > 0;
+      console.log(caches.keys(), `0904路由更新有缓存${flag}`);
+      caches.keys().then(function (cacheNames) {
+        cacheNames.forEach(function (cacheName) {
+          caches.delete(cacheName);
+        });
+        if (flag) {
+          window.location.reload();
+        }
+      });
+
+      // 尝试监听install
+    }
+    let refreshing = false;
+    navigator.serviceWorker.addEventListener('controllerchange', () => {
+      console.log('controllerchange');
+      if (refreshing) {
+        return;
+      }
+      refreshing = true;
+      window.location.reload();
+    });
 
     if (!isChrome()) {
       return;

+ 1 - 1
src/views/login/index.tsx

@@ -137,7 +137,7 @@ export default defineComponent({
         </div>
         <div class={styles['view-account-form']}>
           <img class={styles.colLogo} src={colLogo}></img>
-          111111111111
+          111111111
           {isForgot.value ? (
             <NTabs
               key="forgotPassword"