Przeglądaj źródła

发送在线心跳消息

Michael Wang 4 lat temu
rodzic
commit
bb41e69d78
1 zmienionych plików z 27 dodań i 1 usunięć
  1. 27 1
      src/App.vue

+ 27 - 1
src/App.vue

@@ -15,7 +15,7 @@ import { mapState } from "vuex";
 export default {
   name: "APP",
   computed: {
-    ...mapState(["QECSConfig"]),
+    ...mapState(["user", "QECSConfig"]),
   },
   watch: {
     QECSConfig() {
@@ -87,6 +87,32 @@ export default {
       }
     },
   },
+  async created() {
+    this.interval = setInterval(() => {
+      this.sendOnlineSignal();
+    }, 3 * 60 * 1000);
+  },
+  beforeDestroy() {
+    clearInterval(this.interval);
+  },
+  methods: {
+    async sendOnlineSignal() {
+      if (!window.sessionStorage.getItem("token")) {
+        return;
+      }
+      try {
+        await this.$http.get(
+          "/api/ecs_core/student/online_signal/" + this.user.id
+        );
+      } catch (error) {
+        this.logger({
+          page: window.location.pathname,
+          action: "发送在线信号",
+          userId: this.user.id,
+        });
+      }
+    },
+  },
 };
 </script>