deepsea 1 年間 前
コミット
cdb32f7ad8
2 ファイル変更47 行追加2 行削除
  1. 42 2
      src/views/ordinaryPage/index.vue
  2. 5 0
      vue.config.js

+ 42 - 2
src/views/ordinaryPage/index.vue

@@ -777,6 +777,8 @@ export default {
       isConnected: false,
       currentBenchId: 0,
       gridItems: [1, 2, 3, 4, 5, 6, 7, 8, 9],
+      timerIdMap: { num: 0 },
+      timerId: 0
     };
   },
   computed: {
@@ -861,8 +863,18 @@ export default {
 
     window.bmMapItemActivate = this.bmMapItemActivate;
     setInterval(() => {
-      that.$store.dispatch("benchList/fetchBenchList");
+      
     }, 1500);
+    
+    // 调用定时器方法,返回定时器id,用于按条件清空
+    that.timerId = that.myInterval((count) => {
+        console.log(count)
+        this.$store.dispatch("benchList/fetchBenchList");
+        if (count > 3) {
+            console.log('end')
+            that.clearMyInterval(that.timerId)
+        }
+    }, 1000)
 
     this.$store.dispatch("issueList/fetchIssueList", {
       bench_id: null,
@@ -997,7 +1009,7 @@ export default {
       this.$store.dispatch("common/setSquareStatus", false);
     })
 
-    let autoCurrentTaskData = localStorage.get("autoCurrentTaskData");
+    let autoCurrentTaskData = window.localStorage.getItem("autoCurrentTaskData");
     autoCurrentTaskData = JSON.parse(autoCurrentTaskData)
     if (autoCurrentTaskData) {
       this.$store.dispatch("planList/setPlanExecId", autoCurrentTaskData.id)
@@ -1011,6 +1023,34 @@ export default {
     }
   },
   methods: {
+    myInterval(callback, interval) {
+        // 每设置一次定时器,num++ 代表系统中有num个自定义的定时器
+        this.timerIdMap.num ++
+        // 第 num 个定时器的id
+        let intervalId = 'id' + this.timerIdMap.num
+        this.timerIdMap[intervalId] = true
+        // 循环次数
+        let count = 0
+        
+        let startTime = Date.now()
+        let loop = () => {
+            // 系统map中不存在这个id,就停止循环
+            if (!this.timerIdMap[intervalId]) {
+                return
+            }
+            if (Date.now() > startTime + interval * (count + 1)) {
+                count ++
+                callback(count)
+            }
+            window.requestAnimationFrame(loop)
+        }
+        loop()
+        return intervalId
+    },
+    // 清空定时器,删除全局的定时器id map
+    clearMyInterval(intervalId) {
+        delete this.timerIdMap[intervalId]
+    },
     loadBench() {
       const bench = new FBXLoader();
       bench.load("../models/flower.gltf", function (fbx) {

+ 5 - 0
vue.config.js

@@ -39,6 +39,11 @@ module.exports = defineConfig({
         changeOrigin: true, //需要代理跨域
         rewrite: (path) => path.replace(/^\/arbitrator/, ''), //路径重写,把'/api'替换为''
       },
+      '/8b934420_ZJUb_b6f9': {
+        target: 'http://172.16.50.4:18080',
+        changeOrigin: true, //需要代理跨域
+        rewrite: (path) => path.replace(/^\/8b934420_ZJUb_b6f9/, ''), //路径重写,把'/api'替换为''
+      }
     },
   },
 });