Browse Source

bug 修改获取台架详情-全部请求完成判断方法

Jay 9 months ago
parent
commit
8a1e4a240a
1 changed files with 35 additions and 11 deletions
  1. 35 11
      src/views/ordinaryPage/index.vue

+ 35 - 11
src/views/ordinaryPage/index.vue

@@ -1015,24 +1015,48 @@ export default {
 
         // 加载右侧台架照片
         this.getImageName();
+
+        // // 获取奥迪-各台架详情
+        // console.log("循环获取bench_detail")
+        // this.benchList.forEach( (item, index) => {
+        //   this.$store.dispatch("benchList/getBenchDetail", item.id).then(() => {
+        //     console.log(this.benchList.length, index)
+        //     // 获取全部台架信息后
+        //     if (this.benchList.length - 1 == index) { // 此方法判断最后一次请求完成,经常出现元素位乱序问题,导致判断失误
+        //       console.log("台架详情已全部获取完成")
+        //       // 更新台架各状态总台数
+        //       this.refreshBenchStatus();
+        //       // 更新水滴、台架模型
+        //       window.getsqlDataRealTime();
+        //     }
+        //   })
+        // })
+
         // 获取奥迪-各台架详情
-        this.benchList.forEach( (item, index) => {
-          this.$store.dispatch("benchList/getBenchDetail", item.id).then(() => {
-            // 获取全部台架信息后
-            if (this.benchList.length - 1 == index) {
-              // 更新台架各状态总台数
-              this.refreshBenchStatus();
-              // 更新水滴、台架模型
-              window.getsqlDataRealTime();
-            }
+        let pArr = [];
+        this.benchList.forEach((item, index) => {
+          let p = new Promise((resolve, reject) => {
+            this.$store.dispatch("benchList/getBenchDetail", item.id).then(() => {
+              // console.log(index)
+              resolve()
+            });
           })
-        })
+          pArr.push(p)
+        });
+        // 获取全部台架信息后
+        Promise.all(pArr).then(()=>{
+          // console.log("台架详情已全部获取完成")
+          // 更新台架各状态总台数
+          this.refreshBenchStatus();
+          // 更新水滴、台架模型
+          window.getsqlDataRealTime();
+        });
 
         if (count > 30000) {
           that.clearMyInterval(that.timerId);
         }
       });
-    }, 10000);
+    }, 30000);
 
     bus.on("newLog", (param) => {
       if (param.action) {