Browse Source

联调有功功率数据,进行前端展示查询风机数据更新

liujiejie 10 months ago
parent
commit
53957e6a15

+ 2 - 2
src/components/map/index.vue

@@ -196,8 +196,8 @@ export default {
         new TileLayer({
           source: new XYZ({
             // url: "http://127.0.0.1:8010/tiles/{z}/{x}/{y}.png", //本地
-            url: "http://192.168.50.235/tiles/{z}/{x}/{y}.png", //内网
-            // url: "http://106.120.102.238:18000/tiles/{z}/{x}/{y}.png", //外网
+            // url: "http://192.168.50.235/tiles/{z}/{x}/{y}.png", //内网
+            url: "http://106.120.102.238:18000/tiles/{z}/{x}/{y}.png", //外网
             //  url: "http://10.96.137.5:9080/tiles/{z}/{x}/{y}.png",
           }),
         }),

+ 49 - 23
src/views/performance/assetssDetail.vue

@@ -1,8 +1,8 @@
 <!--
  * @Author: your name
  * @Date: 2024-05-27 09:25:45
- * @LastEditTime: 2024-09-14 16:05:45
- * @LastEditors: bogon
+ * @LastEditTime: 2024-09-14 17:20:08
+ * @LastEditors: milo-MacBook-Pro.local
  * @Description: In User Settings Edit
  * @FilePath: /performance-test/src/views/performance/assetssDetail.vue
 -->
@@ -445,37 +445,63 @@ export default {
         }
         this.initializeLoading();
         //有功功率的数据处理
+        // 有功功率的数据处理
         if (this.formInfo.analysisTypeCode === "power_curve") {
           const generalFiles = response.data[0].generalFiles || [];
           this.generalFilesData = await Promise.all(
             generalFiles.map(async (item, ind) => {
               const types = this.getFileType(item.fileAddr);
               if (types !== "html" && types !== "image") {
-                const resultChartsData = await axios.get(item.fileAddr);
-                // 更新表格数据
-                return {
-                  chartsData: {
-                    ...resultChartsData.data,
-                  },
-                  powerCurveTableData: this.creatPowerCurveTableData(
-                    resultChartsData.data
-                  ).filter((val) => val !== undefined),
-                };
+                try {
+                  const resultChartsData = await axios.get(item.fileAddr);
+                  // 更新表格数据
+
+                  return {
+                    chartsData: {
+                      ...resultChartsData.data,
+                    },
+                    powerCurveTableData: this.creatPowerCurveTableData(
+                      resultChartsData.data
+                    )
+                      .filter((val) => val !== undefined)
+                      .filter(
+                        (item) =>
+                          item[0].enginName === this.formInfo.fieldEngineCode
+                      ),
+                  };
+                } catch (error) {
+                  console.error("Error fetching chart data:", error);
+                  return null; // 如果有错误,返回 null
+                }
               }
+              // 确保返回一个空对象来替代 undefined
+              return null;
             })
           );
+          console.log(this.generalFilesData, "this.generalFilesData");
+          // 过滤掉 null 或者没有 chartsData 的项
+          this.generalFilesData = this.generalFilesData.filter(
+            (item) => item && item.chartsData
+          );
 
-          const grapgFilterData =
-            this.generalFilesData &&
-            this.generalFilesData[0].chartsData.data.filter(
-              (item) =>
-                item.enginName === "合同功率曲线" ||
-                item.enginName === this.formInfo.fieldEngineCode
-            );
-          this.graphChartData = {
-            ...this.generalFilesData[0].chartsData,
-            data: grapgFilterData,
-          };
+          if (
+            this.generalFilesData.length > 0 &&
+            this.generalFilesData[0].chartsData
+          ) {
+            const grapgFilterData =
+              this.generalFilesData[0].chartsData.data.filter(
+                (item) =>
+                  item.enginName === "合同功率曲线" ||
+                  item.enginName === this.formInfo.fieldEngineCode
+              );
+            this.graphChartData = {
+              ...this.generalFilesData[0].chartsData,
+              data: grapgFilterData,
+            };
+          } else {
+            // 如果没有数据,设置为 null 或其他默认值
+            this.graphChartData = null;
+          }
         }
         this.loading = false;
       } catch (error) {

+ 14 - 4
src/views/performance/components/EditAnalysis.vue

@@ -1,7 +1,7 @@
 <!--
  * @Author: your name
  * @Date: 2024-05-29 09:14:23
- * @LastEditTime: 2024-09-14 16:08:24
+ * @LastEditTime: 2024-09-18 09:35:42
  * @LastEditors: bogon
  * @Description: In User Settings Edit
  * @FilePath: /performance-test/src/views/performance/components/EditAnalysis.vue
@@ -518,10 +518,10 @@ export default {
         //有功功率的数据处理
         if (this.form.configAnalysis === "power_curve") {
           const generalFiles = response.data[0].generalFiles || [];
-          this.generalFilesData = await Promise.all(
+          const generalFilesData = await Promise.all(
             generalFiles.map(async (item, ind) => {
               const types = this.getFileType(item.fileAddr);
-              console.log(types,'返回url 类型')
+              console.log(types, "返回url 类型");
               if (types !== "html" && types !== "image") {
                 const resultChartsData = await axios.get(item.fileAddr);
                 // 更新表格数据
@@ -531,12 +531,22 @@ export default {
                   },
                   powerCurveTableData: this.creatPowerCurveTableData(
                     resultChartsData.data
-                  ).filter((val) => val !== undefined),
+                  )
+                    .filter((val) => val !== undefined)
+                    .filter((item) => item[0].enginName === this.form.turbines),
                 };
               }
+              // 确保总是返回一个对象,即使条件不满足
+              return {}; // 或者返回 null
             })
           );
+
+          // 在 await 之后进行过滤,过滤掉没有 chartsData 的项
+          this.generalFilesData = generalFilesData.filter(
+            (item) => item && item.chartsData
+          );
         }
+
         this.loading = false;
       } catch (error) {
         console.error(error);

+ 68 - 27
src/views/performance/components/PlotlyCharts.vue

@@ -117,35 +117,76 @@ export default {
     };
   },
   mounted() {
-    this.powerCurveData.turbines =
-      this.lineMarkerData.data &&
-      this.lineMarkerData.data.length > 0 &&
-      this.lineMarkerData.data.filter(
-        (item) => item.enginName !== "合同功率曲线"
-      );
-    this.powerCurveData.contractPowerCurve =
-      this.lineMarkerData.data &&
-      this.lineMarkerData.data.length > 0 &&
-      this.lineMarkerData.data.filter(
-        (item) => item.enginName === "合同功率曲线"
-      );
-    if (
-      this.comType === "generalDrawing" &&
-      this.lineMarkerData &&
-      this.lineMarkerData.data
-    ) {
-      this.renderPlot();
-    } else if (
-      this.comType === "graph" &&
-      this.lineMarkerData &&
-      this.lineMarkerData.data
-    ) {
-      this.$nextTick(() => {
-        this.initializeEngineCharts();
-      });
-    }
+    this.updateCharts(); // 初次渲染
+  },
+  watch: {
+    lineMarkerData: {
+      deep: true,
+      handler() {
+        console.log("====================================");
+        console.log("变化了");
+        console.log("====================================");
+        this.updateCharts(); // 数据变化时更新
+      },
+    },
+    comType(newType, oldType) {
+      if (newType !== oldType) {
+        this.updateCharts(); // 类型变化时更新
+      }
+    },
   },
+  // mounted() {
+  //   console.log("====================================");
+  //   console.log(this.lineMarkerData, "this.lineMarkerData");
+  //   console.log("====================================");
+  //   this.powerCurveData.turbines =
+  //     this.lineMarkerData.data &&
+  //     this.lineMarkerData.data.length > 0 &&
+  //     this.lineMarkerData.data.filter(
+  //       (item) => item.enginName !== "合同功率曲线"
+  //     );
+  //   this.powerCurveData.contractPowerCurve =
+  //     this.lineMarkerData.data &&
+  //     this.lineMarkerData.data.length > 0 &&
+  //     this.lineMarkerData.data.filter(
+  //       (item) => item.enginName === "合同功率曲线"
+  //     );
+  //   if (
+  //     this.comType === "generalDrawing" &&
+  //     this.lineMarkerData &&
+  //     this.lineMarkerData.data
+  //   ) {
+  //     this.renderPlot();
+  //   } else if (
+  //     this.comType === "graph" &&
+  //     this.lineMarkerData &&
+  //     this.lineMarkerData.data
+  //   ) {
+  //     this.$nextTick(() => {
+  //       this.initializeEngineCharts();
+  //     });
+  //   }
+  // },
   methods: {
+    updateCharts() {
+      this.powerCurveData.turbines =
+        this.lineMarkerData.data?.filter(
+          (item) => item.enginName !== "合同功率曲线"
+        ) || [];
+
+      this.powerCurveData.contractPowerCurve =
+        this.lineMarkerData.data?.filter(
+          (item) => item.enginName === "合同功率曲线"
+        ) || [];
+
+      if (this.comType === "generalDrawing" && this.lineMarkerData?.data) {
+        this.renderPlot();
+      } else if (this.comType === "graph" && this.lineMarkerData?.data) {
+        this.$nextTick(() => {
+          this.initializeEngineCharts();
+        });
+      }
+    },
     renderPlot() {
       const data = [];
       // Add traces for each turbine with colors from config