Sfoglia il codice sorgente

修复设备检查界面上定时功能失效bug

liling 1 anno fa
parent
commit
e23778ffc2

+ 31 - 33
src/views/device/check.vue

@@ -218,20 +218,20 @@ export default {
             value: 0
           },
           {
-            label: 3,
+            label: '每3秒',
             value: 3
           },
           {
-            label: 5,
-            value: 5
+            label: '每10秒',
+            value: 10
           },
           {
-            label: 10,
-            value: 10
+            label: '每1分钟',
+            value: 60
           },
           {
-            label: '自动刷新',
-            value: 1
+            label: '每5分钟',
+            value: 300
           }
         ],
         deviceCheckPlans: [],
@@ -293,7 +293,7 @@ export default {
       handler() {
         if (this.deviceDetail.deviceRefreshValue > 0) {
           // 死循环一直更新状态数据
-          this.getStatusLoop()
+          // this.getStatusLoop()
         }
       },
       deep: true
@@ -305,6 +305,11 @@ export default {
     this.deviceDetail.deviceId = this.$route.query.deviceId
   },
   mounted() {
+    const tmpdeviceRefreshValue = window.localStorage.getItem('deviceRefreshValue')
+    if (tmpdeviceRefreshValue !== null && !isNaN(tmpdeviceRefreshValue)) {
+      this.deviceDetail.deviceRefreshValue = tmpdeviceRefreshValue * 1
+      this.getStatusLoop()
+    }
     this.$nextTick(() => {
       // 网页加载完成后执行
       this.initFunctions()
@@ -372,27 +377,27 @@ export default {
       this.getSteps()
     },
     // 更改定时器时 清除之前的定时器
-    changeTime() {
-      // console.log('timer', this.timer)
-      for (let i = 1; i <= this.timer; i++) {
-        clearInterval(i)
+    changeTime(val) {
+      this.clearTimer()
+      this.deviceDetail.deviceRefreshValue = val
+      if (this.deviceDetail.deviceRefreshValue === 0) {
+        window.localStorage.removeItem('deviceRefreshValue')
+      } else {
+        window.localStorage.setItem('deviceRefreshValue', this.deviceDetail.deviceRefreshValue)
+        this.getStatusLoop()
       }
     },
     // 自动循环刷新
     async getStatusLoop() {
+      if (this.deviceDetail.deviceRefreshValue === 0 || this.deviceDetail.deviceRefreshValue === null) {
+        this.clearTimer()
+        return
+      }
       // 每隔x秒运行一次
-      this.timer = setInterval(() => {
-        // #TODO: 是否需要上一次请求获取成功了再执行下一次,还是不管成功与否时间到了就执行
-        // const unixtime = new Date().getTime()
-        // console.log('定时器执行了=', unixtime)
-        // console.log('定时器执行了 this.deviceDetail.deviceRefreshValue=', this.deviceDetail.deviceRefreshValue)
-
-        // 判断是否选择了不刷新或自动刷新 ,如果是,清空定时器
-        // 因为自动刷新是连接ws,所以需要停止当前定时器
-        // if (this.deviceDetail.deviceRefreshValue<=0) {
-        // ws协议还没有准备好,自动刷新的判断先不写
+      this.timer = setTimeout(() => {
         if (this.deviceDetail.deviceRefreshValue === 0 || !this.deviceDetail.deviceRefreshValue) {
           this.clearTimer()
+          return
         }
 
         // 刷新测试状态
@@ -414,15 +419,9 @@ export default {
           this.deviceCheckPlanUpdate = 'steps' + new Date().getTime()
           // console.log('getStatusLoop 步骤状态(高频刷新) res=', res)
         })
-        if (this.$refs.stepComp) {
-          this.$refs.stepComp.stepActionClick('refresh')
-        }
-        if (this.$refs.lowPComp) {
-          this.$refs.lowPComp.refreshFn()
-        }
         // 刷新用例、采样表格状态
         EventBus.$emit('refreshManualFn', false)
-        EventBus.$emit('refreshManualSample')
+        EventBus.$emit('refreshManualSample', false)
 
         // 接口 用例状态(高频刷新) /test/execute/:runner/results
         // :runner 例 3200000217
@@ -504,9 +503,8 @@ export default {
             })
           }
         })
-      },
-      // 间隔时间 秒
-      this.deviceDetail.deviceRefreshValue * 1000)
+        this.getStatusLoop()
+      }, this.deviceDetail.deviceRefreshValue * 1000)
     },
 
     // 获取禁用状态
@@ -706,7 +704,7 @@ export default {
     clearTimer() {
       // console.log('clearTimer started')
       this.deviceDetail.deviceRefreshValue = 0
-      clearInterval(this.timer)
+      clearTimeout(this.timer)
       this.timer = null
     }
   }

+ 2 - 1
src/views/device/tables/Example.vue

@@ -241,9 +241,10 @@ export default {
   // },
 
   created() {
-    EventBus.$on('refreshManualFn', this.refreshManual)
   },
   mounted() {
+    EventBus.$off('refreshManualFn')
+    EventBus.$on('refreshManualFn', this.refreshManual)
     this.$nextTick(() => {
       // 网页加载完成后执行
       this.initFunctions()

+ 17 - 9
src/views/device/tables/Sample_master104.vue

@@ -333,10 +333,11 @@ export default {
     // 接口 导入测点 /test/plan/:plan/points.csv
     this.importCsvActionStr = envUrl + `/test/plan/${this.componentParames.curPlanId}/points.csv`
     // console.log('this.importCsvActionStr=', this.importCsvActionStr)
-    // 在bus上挂载刷新事件
-    EventBus.$on('refreshManualSample', this.refreshManual)
   },
   mounted() {
+    EventBus.$off('refreshManualSample')
+    // 在bus上挂载刷新事件
+    EventBus.$on('refreshManualSample', this.refreshManual)
     this.$nextTick(() => {
       // 网页加载完成后执行
       this.initFunctions()
@@ -507,14 +508,21 @@ export default {
                 this.tableIsUpdate = 'sample-' + new Date().getTime()
               }
             })
-            this.carddata.forEach((k, item) => {
-              item.forEach(item2 => {
-                if (item2.id === ritem.id) {
-                  item2.value = ritem.value
-                  item2.occur = ritem.occur
+            for (const item in this.carddata) {
+              let hasitem = false
+              for (let i = 0; i < this.carddata[item].length; i++) {
+                const element = this.carddata[item][i]
+                if (element.id === ritem.id) {
+                  this.carddata[item][i].value = ritem.value
+                  this.carddata[item][i].occur = ritem.occur
+                  hasitem = true
+                  break
                 }
-              })
-            })
+              }
+              if (hasitem) {
+                break
+              }
+            }
           })
           this.$forceUpdate()
         }