Browse Source

在线心跳调整

zhangjie 3 years ago
parent
commit
2cd21568fd
3 changed files with 53 additions and 18 deletions
  1. 52 0
      src/App.vue
  2. 1 0
      src/modules/portal/routes/routes.js
  3. 0 18
      src/modules/portal/views/home/Home.vue

+ 52 - 0
src/App.vue

@@ -3,7 +3,59 @@
 </template>
 </template>
 
 
 <script>
 <script>
+import timeMixin from "./mixins/timeMixin";
+import { QUESTION_API } from "@/constants/constants";
+
 export default {
 export default {
   name: "App",
   name: "App",
+  mixins: [timeMixin],
+  data() {
+    return {
+      signalWaiting: false,
+    };
+  },
+  watch: {
+    $route: {
+      immediate: true,
+      handler(val) {
+        // console.log(val);
+        const unSignalRoutes = ["Root", "Login", "NotFound"];
+        if (unSignalRoutes.includes(val.name)) {
+          this.signalWaiting = false;
+          this.clearSetTs();
+          return;
+        }
+        this.onlineSignal();
+      },
+    },
+  },
+
+  beforeDestroy() {
+    this.clearSetTs();
+  },
+  methods: {
+    async onlineSignal() {
+      if (this.signalWaiting) return;
+      this.clearSetTs();
+      this.signalWaiting = true;
+
+      let result = true;
+      await this.$httpWithoutBar
+        .post(QUESTION_API + "/user/online/signal")
+        .catch((error) => {
+          result = false;
+          console.log("signal error", error);
+        });
+      if (!result) {
+        this.signalWaiting = false;
+        return;
+      }
+
+      this.addSetTime(() => {
+        this.signalWaiting = false;
+        this.onlineSignal();
+      }, 60 * 1000);
+    },
+  },
 };
 };
 </script>
 </script>

+ 1 - 0
src/modules/portal/routes/routes.js

@@ -15,6 +15,7 @@ export default [
   {
   {
     // will match everything
     // will match everything
     path: "*",
     path: "*",
+    name: "NotFound",
     component: Component404,
     component: Component404,
   },
   },
   // {
   // {

+ 0 - 18
src/modules/portal/views/home/Home.vue

@@ -166,12 +166,10 @@ import { USER_SIGNOUT, USER_SIGNIN } from "../../store/user";
 import { QUESTION_API } from "@/constants/constants";
 import { QUESTION_API } from "@/constants/constants";
 import HomeSide from "./HomeSide.vue";
 import HomeSide from "./HomeSide.vue";
 import LinkTitles from "./LinkTitles.vue";
 import LinkTitles from "./LinkTitles.vue";
-import timeMixin from "../../../../mixins/timeMixin";
 
 
 export default {
 export default {
   name: "Home",
   name: "Home",
   components: { HomeSide, LinkTitles },
   components: { HomeSide, LinkTitles },
-  mixins: [timeMixin],
   data() {
   data() {
     var validatePass = (rule, value, callback) => {
     var validatePass = (rule, value, callback) => {
       if (value === "") {
       if (value === "") {
@@ -247,29 +245,13 @@ export default {
     if (this.user.passwordWeak) {
     if (this.user.passwordWeak) {
       this.passWeakDialog = true;
       this.passWeakDialog = true;
     }
     }
-    this.onlineSignal();
   },
   },
   beforeDestroy() {
   beforeDestroy() {
     this.clearSetTs();
     this.clearSetTs();
   },
   },
   methods: {
   methods: {
     ...mapActions([USER_SIGNOUT, USER_SIGNIN]),
     ...mapActions([USER_SIGNOUT, USER_SIGNIN]),
-    async onlineSignal() {
-      this.clearSetTs();
 
 
-      let result = true;
-      await this.$httpWithoutBar
-        .post(QUESTION_API + "/user/online/signal")
-        .catch((error) => {
-          result = false;
-          console.log("tag", error);
-        });
-      if (!result) return;
-
-      this.addSetTime(() => {
-        this.onlineSignal();
-      }, 5000);
-    },
     openMessageHome() {
     openMessageHome() {
       this.$router.push({ path: "/home/site-message" });
       this.$router.push({ path: "/home/site-message" });
     },
     },