Browse Source

[Mod 0000] 修改塔山火灾数据数据处理

wangkeyi 1 ngày trước cách đây
mục cha
commit
613520218a

+ 11 - 11
src/views/vent/home/configurable/components/preset/selectorDualChart.vue

@@ -70,6 +70,7 @@
   const selectedValue2 = ref('');
   const selectedLabel1 = ref('');
   const selectedLabel2 = ref('');
+  const isUpdate = ref(false);
 
   // 从配置中获取选择器配置
   const { chartConfig, selectorConfig1, selectorConfig2 } = props.config.config;
@@ -111,19 +112,18 @@
   // 组件挂载时初始化一次
   onMounted(() => {
     initData();
-    // 设置默认选中项
-    setDefaultSelections();
   });
-
   // 初始化数据
   const initData = () => {
-    // 从数据中获取第一个选择器的选项
-    options1.value = selectorConfig1.options || [];
-    // 从数据中获取第二个选择器的选项
-    options2.value = selectorConfig2.options || [];
-
     if (props.data) {
       rawChartData.value = getData(props.data, chartConfig.readFrom, chartConfig.parser);
+      options1.value = selectorConfig1.options = getData(props.data, selectorConfig1.readFrom, chartConfig.parser).options;
+      options2.value = selectorConfig2.options = getData(props.data, selectorConfig2.readFrom, chartConfig.parser).options;
+      if (!isUpdate.value) {
+        // 设置默认选中项
+        setDefaultSelections();
+        isUpdate.value = true;
+      }
     }
   };
 
@@ -150,12 +150,12 @@
   // 根据两个选择器的值过滤图表数据
   const chartData = computed(() => {
     // 如果没有原始数据,直接返回空
-    if (!rawChartData.value.length) return [];
+    if (!rawChartData?.value?.length) return [];
 
     // 过滤逻辑:使用选中的值过滤
     return rawChartData.value.filter((item: any) => {
-      const matchFirst = item.deviceType === selectedValue1.value;
-      const matchSecond = item.deviceId === selectedValue2.value;
+      const matchFirst = item.deviceID === selectedValue1.value;
+      const matchSecond = item.sensorId === selectedValue2.value;
       return matchFirst && matchSecond;
     });
   });

+ 11 - 99
src/views/vent/home/configurable/configurable.data.tashan.ts

@@ -187,15 +187,15 @@ export const testConfigTSFire: Config[] = [
       chart: [
         {
           type: 'line_smooth',
-          readFrom: 'readData.fibreTemperature',
-          parser: 'json',
+          readFrom: '',
+          // parser: 'json',
           legend: { show: true },
           xAxis: [{ show: true }],
           yAxis: [{ show: true, name: '温度(℃)', position: 'left' }],
           series: [
             {
               label: '${strinstallpos}',
-              readFrom: '',
+              readFrom: 'readData.fibreTemperature',
               xprop: 'pos',
               yprop: 'value',
             },
@@ -507,121 +507,33 @@ export const testConfigTSFire: Config[] = [
       complex_list: [],
       preset: [
         {
-          readFrom: '',
+          readFrom: 'deviceInfo.bundletube.chartConfig',
           selectorConfig2: {
-            options: [
-              {
-                value: 'o2',
-                label: '氧气',
-              },
-              {
-                value: 'co',
-                label: '一氧化碳',
-              },
-            ],
+            readFrom: 'selectorConfig2',
+            options: [{}],
           },
           selectorConfig1: {
-            options: [
-              {
-                value: '1',
-                label: '工作面1',
-              },
-              {
-                value: '2',
-                label: '工作面2',
-              },
-            ],
+            readFrom: 'selectorConfig1',
+            options: [{}],
           },
           chartConfig: {
             clear: true,
             type: 'line_smooth',
-            readFrom: 'mockChart',
-            legend: { show: true },
+            readFrom: 'chartData',
+            legend: { show: false },
             xAxis: [{ show: true }],
             yAxis: [{ show: true, name: '', position: 'left' }],
             series: [
               {
                 label: '${label}',
                 readFrom: 'seriesData',
-                xprop: 'pos',
+                xprop: 'time',
                 yprop: 'value',
               },
             ],
           },
         },
       ],
-      mock: {
-        mockChart: [
-          {
-            label: '工作面1氧气',
-            deviceId: 'o2',
-            deviceType: '1',
-            seriesData: [
-              { pos: '0', value: 21 },
-              { pos: '10', value: 21 },
-              { pos: '20', value: 21 },
-              { pos: '30', value: 21 },
-              { pos: '40', value: 21 },
-              { pos: '50', value: 21 },
-              { pos: '60', value: 21 },
-              { pos: '70', value: 21 },
-              { pos: '80', value: 21 },
-              { pos: '90', value: 21 },
-            ],
-          },
-          {
-            label: '工作面1一氧化碳',
-            deviceId: 'co',
-            deviceType: '1',
-            seriesData: [
-              { pos: '0', value: 11 },
-              { pos: '10', value: 11 },
-              { pos: '20', value: 11 },
-              { pos: '30', value: 11 },
-              { pos: '40', value: 11 },
-              { pos: '50', value: 11 },
-              { pos: '60', value: 11 },
-              { pos: '70', value: 11 },
-              { pos: '80', value: 11 },
-              { pos: '90', value: 11 },
-            ],
-          },
-          {
-            label: '工作面2氧气',
-            deviceId: 'o2',
-            deviceType: '2',
-            seriesData: [
-              { pos: '0', value: 25 },
-              { pos: '10', value: 25 },
-              { pos: '20', value: 25 },
-              { pos: '30', value: 25 },
-              { pos: '40', value: 25 },
-              { pos: '50', value: 25 },
-              { pos: '60', value: 25 },
-              { pos: '70', value: 25 },
-              { pos: '80', value: 25 },
-              { pos: '90', value: 25 },
-            ],
-          },
-          {
-            label: '工作面2一氧化碳',
-            deviceId: 'co',
-            deviceType: '2',
-            seriesData: [
-              { pos: '0', value: 15 },
-              { pos: '10', value: 15 },
-              { pos: '20', value: 15 },
-              { pos: '30', value: 15 },
-              { pos: '40', value: 15 },
-              { pos: '50', value: 15 },
-              { pos: '60', value: 15 },
-              { pos: '70', value: 15 },
-              { pos: '80', value: 15 },
-              { pos: '90', value: 15 },
-            ],
-          },
-        ],
-      },
     },
     showStyle: {
       size: 'width:440px;height:270px;',

+ 110 - 11
src/views/vent/home/configurable/fireTS.vue

@@ -140,19 +140,118 @@
         returnWind: datalist.filter((item) => item.strRemark === 'returnWind'),
       };
     }
-    // 处理开采煤层自燃发火特性
-    // if (processedData.sysInfo.coalSpoCha && typeof processedData.sysInfo.coalSpoCha === 'string') {
-    //   processedData.sysInfo.coalSpoCha = JSON.parse(res.sysInfo.coalSpoCha || '[]');
-    // }
     // 处理光纤测温数据
-    // if (processedData.deviceInfo?.fiber?.datalist) {
-    //   processedData.deviceInfo.fiber.datalist.forEach((item) => {
-    //     item.readData.fibreTemperature = JSON.parse(item.readData.fibreTemperature || '[]');
-    //   });
-    // }
+    if (processedData.deviceInfo?.fiber?.datalist) {
+      processedData.deviceInfo.fiber.datalist.forEach((item) => {
+        const tempData = item.readData.fibreTemperature;
+        if (typeof tempData === 'string') {
+          try {
+            item.readData.fibreTemperature = JSON.parse(tempData || '[]');
+          } catch (e) {
+            // 解析失败时的容错处理
+            console.error('解析JSON失败:', e);
+            item.readData.fibreTemperature = []; // 给个默认值
+          }
+        }
+      });
+    }
+    // 处理束管数据
+    if (processedData.deviceInfo?.bundletube?.datalist) {
+      // 每次处理前先清空chartData,避免数据累积
+      chartData.value = [];
+      const bundletubeDataList = processedData.deviceInfo.bundletube.datalist;
+      // 处理selectorConfig1:遍历datalist,提取deviceID和strinstallpos
+      selectorConfig1 = {
+        options: bundletubeDataList.map((device) => ({
+          value: device.deviceID, // 选项值:设备唯一ID
+          label: device.strinstallpos, // 选项标签:设备
+        })),
+      };
+      const targetIndicators: Array<keyof Pick<BundletubeHistoryItem, 'ch2val' | 'chval' | 'co2val' | 'coval' | 'gasval' | 'o2val'>> = [
+        'ch2val',
+        'chval',
+        'co2val',
+        'coval',
+        'gasval',
+        'o2val',
+      ];
+
+      // 遍历datalist(每个item对应一个设备安装位置)
+      bundletubeDataList.forEach((deviceItem) => {
+        const deviceID = deviceItem.deviceID; // 设备ID
+        const deviceHistory = deviceItem.history; // 当前设备的history数组
+
+        // 跳过history为空的情况
+        if (!deviceHistory || !Array.isArray(deviceHistory)) return;
+
+        //  遍历每个指标,生成对应的chartData项
+        targetIndicators.forEach((indicator) => {
+          // 收集当前指标的seriesData(时间+数值)
+          const seriesData: SeriesDataItem[] = deviceHistory
+            .map((historyItem: BundletubeHistoryItem) => ({
+              time: historyItem.time,
+              value: historyItem[indicator], // 匹配当前指标的数值
+            }))
+            .filter((item) => item.time); // 过滤掉无时间的无效数据
+
+          // 推送到最终chartData
+          chartData.value.push({
+            deviceID,
+            sensorId: indicator,
+            seriesData,
+          });
+        });
+      });
+      processedData.deviceInfo.bundletube.chartConfig = {
+        selectorConfig1: selectorConfig1,
+        selectorConfig2: selectorConfig2,
+        chartData: chartData,
+      };
+    }
     return processedData;
   };
-
+  interface BundletubeHistoryItem {
+    time: string; // 时间戳(如"2025-08-23 07:56:35")
+    ch2val: string | number; // 甲烷2值
+    chval: string | number; // 甲烷值
+    co2val: string | number; // 二氧化碳值
+    coval: string | number; // 一氧化碳值
+    gasval: string | number; // 瓦斯值
+    o2val: string | number; // 氧气值
+  }
+  // 定义chartData中seriesData的单个元素类型
+  interface SeriesDataItem {
+    time: string;
+    value: string | number; // 对应指标的数值
+  }
+  interface ChartDataItem {
+    deviceID: string; // 设备id
+    sensorId: 'ch2val' | 'chval' | 'co2val' | 'coval' | 'gasval' | 'o2val'; // 指标ID(固定6个)
+    seriesData: SeriesDataItem[]; // 时间+数值数组
+  }
+  // 处理selectorConfig1:遍历datalist,提取deviceID和strinstallpos
+  let selectorConfig1 = {
+    options: [
+      {
+        value: '', // 选项值:设备唯一Id
+        label: '', // 设备名
+      },
+    ],
+  };
+  // 处理selectorConfig2:固定6个指标ID及对应中文标签
+  const selectorConfig2 = {
+    options: [
+      { value: 'o2val', label: '氧气' },
+      { value: 'coval', label: '一氧化碳' },
+      { value: 'co2val', label: '二氧化碳' },
+      { value: 'chval', label: '甲烷' },
+      { value: 'ch2val', label: '乙烷' },
+      { value: 'gasval', label: '瓦斯' },
+    ],
+  };
+  // 最终生成的图表数据
+  const chartData = ref<ChartDataItem[]>([]);
+  // 数据处理函数
   onUnmounted(() => {
     clearInterval(interval);
   });
@@ -204,7 +303,7 @@
       align-items: center;
       justify-content: center;
       background: url('@/assets/images/home-container/configurable/tashanhome/center-bar-bg.png') no-repeat center;
-
+      z-index: 1;
       .center-info-content {
         position: relative;
         top: 15px;