kukuasir@vip.qq.com 1 year ago
parent
commit
7ce4cff1b6
1 changed files with 18 additions and 8 deletions
  1. 18 8
      src/permission.js

+ 18 - 8
src/permission.js

@@ -13,13 +13,16 @@ NProgress.configure({
 
 const whiteList = ["/login"]; // no redirect whitelist
 
+var analytics = false;
+var interval = {};
+
 router.beforeEach(async (to, from, next) => {
   // start progress bar
   NProgress.start();
-  console.log(to);
-  if (to.path) {
-    window._hmt.push(['_trackPageview', '/#' + to.fullPath]);
-  }
+  // console.log(to);
+  // if (to.path) {
+  //   window._hmt.push(['_trackPageview', '/#' + to.fullPath]);
+  // }
   // set page title
   document.title = getPageTitle(to.meta.title);
 
@@ -76,10 +79,17 @@ router.beforeEach(async (to, from, next) => {
       }
     } else {
       // get analytics
-      await store.dispatch("user/setNums");
-      setInterval(() => {
-        store.dispatch("user/setNums");
-      }, 30000)
+      if (!analytics) {
+        await store.dispatch("user/setNums");
+        if (interval) {
+          clearInterval(interval);
+        }
+        interval = setInterval(() => {
+          console.log(">>> analytics ...");
+          store.dispatch("user/setNums");
+        }, 30000);
+        analytics = true;
+      }
 
       const hasGetUserInfo = store.getters.name;
       if (hasGetUserInfo) {