Przeglądaj źródła

先提交一下

wukai 3 tygodni temu
rodzic
commit
b9508104fd
1 zmienionych plików z 42 dodań i 22 usunięć
  1. 42 22
      src/views/dye/hour/calc.vue

+ 42 - 22
src/views/dye/hour/calc.vue

@@ -405,6 +405,7 @@ function getDeviceList() {
     if (selectedMetrics.value[tmp[0] + '_0']) selectedMetrics.value[tmp[0] + '_0'] = '';
     if (selectedMetrics.value[tmp[0] + '_1']) selectedMetrics.value[tmp[0] + '_1'] = '';
     updateQueryData();
+    return;
   }
 
   // 检查是否选择了设备类型和参数
@@ -417,8 +418,11 @@ function getDeviceList() {
     return;
   }
 
+  // 控制是否需要更新数据
+  let needUpdateData = false;
+
   // 为所有选中的产线获取设备列表
-  selectedLines.value.forEach(line => {
+  selectedLines.value.forEach((line, index) => {
     listDevice({
       pageSize: 10000,
       pageNum: 1,
@@ -435,7 +439,6 @@ function getDeviceList() {
       });
 
       // 默认选中第一台设备
-      let needUpdateData = false;
       if (response.rows.length > 0) {
         // 如果是单条产线情况,设置同产线设备对比的第一台设备
         if (selectedLines.value.length === 1) {
@@ -454,18 +457,19 @@ function getDeviceList() {
         }
       }
 
-      // 如果设置了默认设备,则更新数据
-      if (needUpdateData) {
+      // 只有当所有请求都完成后再更新数据
+      if (index === selectedLines.value.length - 1 && needUpdateData) {
         updateQueryData();
       }
     });
   });
 
   oldSelectLines.value = JSON.parse(JSON.stringify(selectedLines.value));
-  // 如果选择了产线,更新图表
+  
+  // 如果已经选择了产线和设备,检查是否所有产线都已设置设备
   if (selectedLines.value.length >= 1 && Object.keys(selectedMetrics.value).length > 0) {
-    // 检查是否所有产线都已设置设备,如果是则更新数据
     let allLinesHaveDevices = true;
+    
     if (selectedLines.value.length === 1) {
       const lineKey = selectedLines.value[0];
       if (!selectedMetrics.value[lineKey + '_0']) {
@@ -480,7 +484,8 @@ function getDeviceList() {
       }
     }
 
-    if (allLinesHaveDevices) {
+    // 如果所有产线都已设置设备,但上面的异步请求还没有触发更新,则在这里更新
+    if (allLinesHaveDevices && !needUpdateData) {
       updateQueryData();
     }
   }
@@ -508,7 +513,6 @@ function updateQueryData() {
       queryPara['line'] = line;
       queryPara['deviceId'] = selectedMetrics.value[line + '_0'];
       listHour(queryPara).then(res => {
-        console.log('listHour response 0:', res); // 调试信息
         rzLineList.value = res.rows;
         nextTick(() => {
           updateChart();
@@ -518,7 +522,6 @@ function updateQueryData() {
       // 查询第二个设备的数据
       queryPara['deviceId'] = selectedMetrics.value[line + '_1'];
       listHour(queryPara).then(res => {
-        console.log('listHour response 1:', res); // 调试信息
         rzLineList1.value = res.rows;
         nextTick(() => {
           updateChart1();
@@ -528,29 +531,48 @@ function updateQueryData() {
   }
   // 情况2:选择了两条产线,每条产线选择一个设备进行对比
   else if (selectedLines.value.length == 2) {
+    // 添加标志防止重复调用
+    let callCount = 0;
+    const maxCalls = 2;
+    
     // 查询第一条产线设备的数据
     if (selectedMetrics.value[selectedLines.value[0]]) {
       queryPara['line'] = selectedLines.value[0];
       queryPara['deviceId'] = selectedMetrics.value[selectedLines.value[0]];
       listHour(queryPara).then(res => {
-        console.log('listHour response 0 (2 lines):', res); // 调试信息
         rzLineList.value = res.rows;
-        nextTick(() => {
-          updateChart();
-        });
+        callCount++;
+        if (callCount === maxCalls) {
+          nextTick(() => {
+            updateChart();
+            updateChart1();
+          });
+        } else {
+          nextTick(() => {
+            updateChart();
+          });
+        }
       });
     }
 
     // 查询第二条产线设备的数据
     if (selectedMetrics.value[selectedLines.value[1]]) {
-      queryPara['line'] = selectedLines.value[1];
-      queryPara['deviceId'] = selectedMetrics.value[selectedLines.value[1]];
-      listHour(queryPara).then(res => {
-        console.log('listHour response 1 (2 lines):', res); // 调试信息
+      const queryPara1 = {...queryPara}; // 创建独立的查询参数对象
+      queryPara1['line'] = selectedLines.value[1];
+      queryPara1['deviceId'] = selectedMetrics.value[selectedLines.value[1]];
+      listHour(queryPara1).then(res => {
         rzLineList1.value = res.rows;
-        nextTick(() => {
-          updateChart1();
-        });
+        callCount++;
+        if (callCount === maxCalls) {
+          nextTick(() => {
+            updateChart();
+            updateChart1();
+          });
+        } else {
+          nextTick(() => {
+            updateChart1();
+          });
+        }
       });
     }
   }
@@ -1428,8 +1450,6 @@ function handleExport() {
   }, `rzLine_${new Date().getTime()}.xlsx`)
 }
 
-getList();
-
 const getTableColumnLabel = (list) => {
   if (list && list.length > 0 && list[0]) {
     const item = list[0];