From 06eeb9b59644971d93e6dd9207ac447864e527b9 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期二, 03 六月 2025 17:38:08 +0800
Subject: [PATCH] 动态溯源(待完成)

---
 src/utils/chart/factor-data-parser.js      |   80 +++++++++++++
 src/views/sourcetrace/SourceTrace.vue      |  116 ++++++++++++++++--
 src/api/index.js                           |    8 
 src/components.d.ts                        |    3 
 src/utils/map/3dLayer.js                   |   34 +++--
 src/views/realtimemode/RealtimeMode.vue    |   16 +-
 src/components/scene/SceneTable.vue        |   42 +++++-
 src/components/chart/RealTimeLineChart.vue |   10 +
 8 files changed, 258 insertions(+), 51 deletions(-)

diff --git a/src/api/index.js b/src/api/index.js
index 6fba3e6..c456a07 100644
--- a/src/api/index.js
+++ b/src/api/index.js
@@ -12,10 +12,10 @@
 }
 
 if (debug) {
-  // ip1 = 'http://192.168.0.110:8084/';
-  ip1 = 'http://localhost:8084/';
-  // ws = `192.168.0.110:9031`;
-  ws = `localhost:9031`;
+  ip1 = 'http://192.168.0.110:8084/';
+  // ip1 = 'http://localhost:8084/';
+  ws = `192.168.0.110:9031`;
+  // ws = `localhost:9031`;
 }
 
 const $http = axios.create({
diff --git a/src/components.d.ts b/src/components.d.ts
index b6b61b4..d85f428 100644
--- a/src/components.d.ts
+++ b/src/components.d.ts
@@ -39,6 +39,7 @@
     ElFormItem: typeof import('element-plus/es')['ElFormItem']
     ElIcon: typeof import('element-plus/es')['ElIcon']
     ElInput: typeof import('element-plus/es')['ElInput']
+    ElInputNumber: typeof import('element-plus/es')['ElInputNumber']
     ElLink: typeof import('element-plus/es')['ElLink']
     ElOption: typeof import('element-plus/es')['ElOption']
     ElPagination: typeof import('element-plus/es')['ElPagination']
@@ -49,12 +50,14 @@
     ElScrollbar: typeof import('element-plus/es')['ElScrollbar']
     ElSelect: typeof import('element-plus/es')['ElSelect']
     ElSlider: typeof import('element-plus/es')['ElSlider']
+    ElSpace: typeof import('element-plus/es')['ElSpace']
     ElStatistic: typeof import('element-plus/es')['ElStatistic']
     ElSwitch: typeof import('element-plus/es')['ElSwitch']
     ElTable: typeof import('element-plus/es')['ElTable']
     ElTableColumn: typeof import('element-plus/es')['ElTableColumn']
     ElTabPane: typeof import('element-plus/es')['ElTabPane']
     ElTabs: typeof import('element-plus/es')['ElTabs']
+    ElTag: typeof import('element-plus/es')['ElTag']
     ElText: typeof import('element-plus/es')['ElText']
     FactorCheckbox: typeof import('./components/monitor/FactorCheckbox.vue')['default']
     FactorLegend: typeof import('./components/monitor/FactorLegend.vue')['default']
diff --git a/src/components/chart/RealTimeLineChart.vue b/src/components/chart/RealTimeLineChart.vue
index 0cd7b58..fa8da32 100644
--- a/src/components/chart/RealTimeLineChart.vue
+++ b/src/components/chart/RealTimeLineChart.vue
@@ -44,6 +44,7 @@
       }
       if (this.lineChart) {
         this.lineChart.setOption(this.option, { notMerge: true });
+        console.log('鎶樼嚎鍥剧敓鎴愶細绔嬪嵆');
       } else {
         this.onChartCreated = () => {
           this.lineChart.setOption(this.option, { notMerge: true });
@@ -53,9 +54,12 @@
   },
   mounted() {
     this.lineChart = echarts.init(this.$refs.lineChart);
-    if (typeof this.onChartCreated === 'function') {
-      this.onChartCreated();
-    }
+    setTimeout(() => {
+      if (typeof this.onChartCreated === 'function') {
+        this.onChartCreated();
+        console.log('鎶樼嚎鍥剧敓鎴愶細婊炲悗');
+      }
+    }, 500);
   }
 };
 </script>
diff --git a/src/components/scene/SceneTable.vue b/src/components/scene/SceneTable.vue
index 9aa89ac..a587167 100644
--- a/src/components/scene/SceneTable.vue
+++ b/src/components/scene/SceneTable.vue
@@ -3,7 +3,6 @@
     :data="sceneList"
     table-layout="fixed"
     size="small"
-    height="30vh"
     :show-overflow-tooltip="true"
     border
     row-class-name="t-row"
@@ -13,7 +12,7 @@
     @row-click="handleRowClick"
     @filter-change="handleFilterChange"
   >
-    <el-table-column type="index" label="#" width="25" />
+    <!-- <el-table-column type="index" label="#" width="25" /> -->
     <el-table-column
       prop="type"
       label="绫诲瀷"
@@ -23,13 +22,19 @@
       :filter-method="filterHandler"
     />
     <el-table-column prop="name" label="鍚嶇О" />
-    <!-- <el-table-column prop="location" label="鍦板潃" /> -->
-    <el-table-column
+    <el-table-column prop="location" label="鍦板潃" />
+    <el-table-column label="涓磋繎绔欑偣" width="65">
+      <template #default="{ row }">
+        <div>{{ row.closestStation.name }}</div>
+        <div>{{ parseInt(row.length) + '绫�' }}</div>
+      </template>
+    </el-table-column>
+    <!-- <el-table-column
       prop="districtName"
       label="鍖哄幙"
       align="center"
       width="54"
-    />
+    /> -->
     <!-- <el-table-column label="绠$悊" width="70" align="center">
       <template #default="{ row }">
         <el-button
@@ -50,7 +55,11 @@
 import marks from '@/utils/map/marks';
 
 const props = defineProps({
-  sceneList: Array
+  sceneList: Array,
+  showMarks: {
+    type: Boolean,
+    default: true
+  }
 });
 
 let layer = undefined;
@@ -78,11 +87,30 @@
 });
 
 watch(showSceneList, (nV, oV) => {
-  if (nV != oV) {
+  if (nV && props.showMarks) {
     drawMarks(nV);
+  } else {
+    if (layer != undefined) {
+      MapUtil.removeViews(layer);
+      layer = undefined;
+    }
   }
 });
 
+watch(
+  () => props.showMarks,
+  (nV, oV) => {
+    if (showSceneList.value && nV) {
+      drawMarks(showSceneList.value);
+    } else {
+      if (layer != undefined) {
+        MapUtil.removeViews(layer);
+        layer = undefined;
+      }
+    }
+  }
+);
+
 function drawMarks(sceneList) {
   if (layer != undefined) {
     MapUtil.removeViews(layer);
diff --git a/src/utils/chart/factor-data-parser.js b/src/utils/chart/factor-data-parser.js
new file mode 100644
index 0000000..0eb8dfb
--- /dev/null
+++ b/src/utils/chart/factor-data-parser.js
@@ -0,0 +1,80 @@
+/**
+ * 灏嗙洃娴嬫暟鎹牸寮忓寲涓篹-charts鍥捐〃鏁版嵁
+ */
+import { factorName } from '@/constant/factor-name';
+
+function refreshX(factorDatas) {
+  const newTimes = factorDatas.times.map((v) => {
+    return v.split(' ')[1];
+  });
+  return newTimes;
+}
+function refreshY(factorDatas) {
+  const allSeries = new Map();
+  for (const key in factorDatas.factor) {
+    if (Object.hasOwnProperty.call(factorDatas.factor, key)) {
+      const e = factorDatas.factor[key];
+      if (!allSeries.has(key)) {
+        allSeries.set(key, {
+          key: key,
+          name: factorName[e.factorName],
+          label: e.factorName,
+          type: 'line',
+          data: [],
+          showAllSymbol: true,
+          animationDelay: function (idx) {
+            return idx * 10;
+          }
+        });
+      }
+      if (e.datas.length == 0) {
+        continue;
+      }
+      const series = allSeries.get(key);
+      // 鎻掑叆鏂版暟鎹�
+      const newSeries = e.datas.map((v) => v.factorData);
+      series.data = series.data.concat(newSeries);
+      // 璁$畻鏁版嵁鑼冨洿
+      const { min, max } = dataRange(series.data);
+      series.min = min;
+      series.max = max;
+      // 璁板綍鏈�鏂版暟鎹�
+      series.currentData =
+        Math.round(series.data[series.data.length - 1] * 10) / 10;
+    }
+  }
+  return allSeries;
+}
+
+function dataRange(dataList) {
+  let min, max;
+  dataList.forEach((e) => {
+    if (!min || min > e) {
+      min = e;
+    }
+    if (!max || max < e) {
+      max = e;
+    }
+  });
+  return { min, max };
+}
+function toList(xAxis, allSeries, selectedFactors) {
+  const list = [];
+  selectedFactors.forEach((t) => {
+    if (allSeries.has(t.value)) {
+      list.push({
+        xAxis: xAxis,
+        series: allSeries.get(t.value)
+      });
+    }
+  });
+  return list;
+}
+
+export default {
+  parseData(factorDatas, selectedFactors) {
+    const xAxis = refreshX(factorDatas);
+    const allSeries = refreshY(factorDatas);
+    return toList(xAxis, allSeries, selectedFactors);
+  }
+};
diff --git a/src/utils/map/3dLayer.js b/src/utils/map/3dLayer.js
index 5222ed4..6a7c0c8 100644
--- a/src/utils/map/3dLayer.js
+++ b/src/utils/map/3dLayer.js
@@ -116,12 +116,20 @@
 
   var geometry = cylinder.geometry;
 
-  const scale = _getScale(_minH, _maxH);
+  var minH = heights[0];
+  var maxH = heights[0];
+  for (let i = 0; i < heights.length; i++) {
+    const h = heights[i];
+    minH = Math.min(minH, h);
+    maxH = Math.max(maxH, h);
+  }
+
+  const scale = _getScale(minH, maxH);
   for (let i = 0; i < coors.length; i++) {
     var r = lnglats_GD[i];
     var lastP = lnglats_GD[i - 1];
     var p = coors[i];
-    var h = (heights[i] - _minH) * scale + _minHeight;
+    var h = (heights[i] - minH) * scale + _minHeight;
     if (heights[i] == -1) {
       h = -1;
     }
@@ -277,17 +285,17 @@
     map.off('zoomend', onMapZoom);
 
     // 2.璁$畻缁樺浘楂樺害鐨勮竟鐣屽��
-    if (merge != true) {
-      var minH = _minH < 0 ? heights[0] : _minH;
-      var maxH = _maxH < 0 ? heights[0] : _maxH;
-      for (let i = 0; i < heights.length; i++) {
-        const h = heights[i];
-        minH = Math.min(minH, h);
-        maxH = Math.max(maxH, h);
-      }
-      _minH = minH;
-      _maxH = maxH;
-    }
+    // if (merge != true) {
+    //   var minH = _minH < 0 ? heights[0] : _minH;
+    //   var maxH = _maxH < 0 ? heights[0] : _maxH;
+    //   for (let i = 0; i < heights.length; i++) {
+    //     const h = heights[i];
+    //     minH = Math.min(minH, h);
+    //     maxH = Math.max(maxH, h);
+    //   }
+    //   _minH = minH;
+    //   _maxH = maxH;
+    // }
 
     // 5.缁樺埗3D鍥惧舰
     this.drawMesh(fDatas, factor, merge);
diff --git a/src/views/realtimemode/RealtimeMode.vue b/src/views/realtimemode/RealtimeMode.vue
index 1cdc47b..6d82f64 100644
--- a/src/views/realtimemode/RealtimeMode.vue
+++ b/src/views/realtimemode/RealtimeMode.vue
@@ -2,18 +2,20 @@
   <div class="p-events-none m-t-2">
     <el-row justify="center" align="middle" class="top-wrap">
       <DeviceChange @change="onDeviceChange"></DeviceChange>
+      <el-button
+        type="primary"
+        class="p-events-auto el-button-custom"
+        @click="clearFetchingTask"
+      >
+        鍋滄
+      </el-button>
     </el-row>
     <el-row class="m-t-2">
-      <FactorRadio
-        :device-type="deviceType"
-        v-model="factorType"
-      ></FactorRadio>
+      <FactorRadio :device-type="deviceType" v-model="factorType"></FactorRadio>
     </el-row>
     <el-row class="m-t-2">
       <el-col span="1">
-        <FactorLegend
-          :factor="factorDatas.factor[factorType]"
-        ></FactorLegend>
+        <FactorLegend :factor="factorDatas.factor[factorType]"></FactorLegend>
       </el-col>
       <el-col span="1">
         <SourceTrace v-model:factorType="factorType"></SourceTrace>
diff --git a/src/views/sourcetrace/SourceTrace.vue b/src/views/sourcetrace/SourceTrace.vue
index 1b23daa..8afb284 100644
--- a/src/views/sourcetrace/SourceTrace.vue
+++ b/src/views/sourcetrace/SourceTrace.vue
@@ -8,35 +8,64 @@
         <button @click="handleSend">send</button>
         <button @click="handleLink">link</button>
       </div> -->
-          <div>鍔ㄦ�佹函婧�</div>
+          <!-- <div>
+            <el-text type="primary" size="large" tag="b">鍔ㄦ�佹函婧�</el-text>
+          </div> -->
           <el-scrollbar ref="scrollbarRef" :height="height" class="scrollbar">
             <div ref="scrollContentRef">
               <div v-for="(item, index) in streams" :key="index">
                 <el-row gap="4">
-                  <el-text type="primary">鍙戠敓鏃堕棿锛�</el-text>
+                  <!-- <el-tag v-if="index == 0" type="danger">鏈�鏂�</el-tag> -->
                   <el-text type="primary">{{
-                    item.pollutedData.startTime + ' 鑷� '
-                  }}</el-text>
-                  <el-text type="primary">{{
+                    '绾跨储鏃堕棿锛�' +
+                    item.pollutedData.startTime +
+                    ' - ' +
                     item.pollutedData.endTime
                   }}</el-text>
                 </el-row>
-                <div>姹℃煋鍖哄煙锛歿{ item.pollutedArea.address }}</div>
-                <div>姹℃煋璺濈锛歿{ item.pollutedArea.distanceType }}</div>
+                <div>
+                  <el-text type="primary">
+                    姹℃煋鍖哄煙锛歿{ item.pollutedArea.address }}
+                  </el-text>
+                </div>
+                <div>
+                  <el-text type="primary">
+                    婧簮璺濈锛歿{
+                      formatDistanceType(item.pollutedArea.distanceType)
+                    }}
+                  </el-text>
+                </div>
                 <el-row>
                   <el-col :span="6">
-                    <el-statistic title="鍥犲瓙" :value="item.pollutedData.factorName" />
+                    <el-statistic
+                      title="绐佸彉鍥犲瓙"
+                      :value="item.pollutedData.factorName"
+                    />
                   </el-col>
                   <el-col :span="6">
-                    <el-statistic title="鍙樺寲骞呭害" :value="formatPercentage(item.pollutedData.avgPer)" />
+                    <el-statistic
+                      title="鍙樺寲骞呭害"
+                      :value="formatPercentage(item.pollutedData.avgPer)"
+                    />
                   </el-col>
                   <el-col :span="6">
-                    <el-statistic title="鍙戠敓娆℃暟" :value="item.pollutedData.times" />
+                    <el-statistic
+                      title="鍙戠敓娆℃暟"
+                      :value="item.pollutedData.times"
+                    />
+                  </el-col>
+                  <el-col :span="6">
+                    <el-statistic
+                      title="骞冲潎椋庨��"
+                      :value="item.pollutedData.windSpeed"
+                      suffix="m/s"
+                    />
                   </el-col>
                 </el-row>
                 <el-row justify="space-between">
                   <el-link
                     type="primary"
+                    underline
                     @click="item.showMore = !item.showMore"
                   >
                     {{
@@ -46,12 +75,24 @@
                       '锛�'
                     }}
                   </el-link>
-                  <el-link type="primary" @click="drawPolygon(item.pollutedArea)">
-                    鏌ョ湅寮傚父
+                  <el-link
+                    type="primary"
+                    underline
+                    @click="drawPolygon(item.pollutedArea)"
+                  >
+                    瀹氫綅寮傚父
                   </el-link>
                 </el-row>
+                <div v-show="item.showMore" style="width: 320px; height: 140px">
+                  <RealTimeLineChart
+                    v-for="(item1, index1) in item._chartOptions"
+                    :key="index1"
+                    :model-value="item1"
+                  ></RealTimeLineChart>
+                </div>
                 <SceneTable
                   v-show="item.showMore"
+                  :show-marks="item.showMore"
                   :scene-list="item.pollutedSource.sceneList"
                 ></SceneTable>
                 <el-divider />
@@ -130,6 +171,7 @@
 import marks from '@/utils/map/marks';
 import { map, onMapMounted } from '@/utils/map/index_old';
 import { FactorDatas } from '@/model/FactorDatas';
+import factorDataParser from '@/utils/chart/factor-data-parser';
 
 const START_STR = '##';
 const SPLIT_STR = '&&';
@@ -175,18 +217,22 @@
   // 姹℃煋绾跨储 PollutedClue
   if (type == '1') {
     const obj = JSON.parse(content);
+    obj.showMore = true;
     console.log('姹℃煋绾跨储: ', obj);
+    drawPolygon(obj.pollutedArea);
+    parseChartData(obj);
     if (streams.length == 0) {
       streams.push(obj);
     } else {
+      streams.forEach((s) => {
+        s.showMore = false;
+      });
       streams.unshift(obj);
       show.value = true;
     }
 
     // scrollToBottom();
     scrollToTop();
-
-    drawPolygon(obj.pollutedArea);
   }
   // 姹℃煋鍒嗘瀽缁撴灉 AnalysisResult
   else if (type == '2') {
@@ -222,15 +268,46 @@
     path: bounds, //澶氳竟褰㈣疆寤撶嚎鐨勮妭鐐瑰潗鏍囨暟缁�
     fillOpacity: 0, //澶氳竟褰㈠~鍏呴�忔槑搴�
     fillColor: '#CCF3FF', //澶氳竟褰㈠~鍏呴鑹�
-    // strokeColor: '#ffffff' //绾挎潯棰滆壊
-    strokeColor: '#0552f7', //绾挎潯棰滆壊
+    strokeColor: '#02ffea', //绾挎潯棰滆壊
+    // strokeColor: '#0552f7', //绾挎潯棰滆壊
+    strokeStyle: 'dashed',
     zIndex: 9
   });
   map.setFitView();
 }
 
+function parseChartData(obj) {
+  const factorDatas = new FactorDatas();
+  factorDatas.setData(obj.pollutedData.dataVoList, 0, () => {
+    obj._chartOptions = factorDataParser.parseData(factorDatas, [
+      {
+        label: obj.pollutedData.factorName,
+        name: obj.pollutedData.factorName,
+        value: obj.pollutedData.factorId + ''
+      }
+    ]);
+    console.log('鎶樼嚎鍥撅細', obj._chartOptions);
+  });
+}
+
 function formatPercentage(value) {
-  return Math.round(value * 100) + '%'
+  return Math.round(value * 100) + '%';
+}
+
+function formatDistanceType(value) {
+  switch (value) {
+    case 'TYPE1':
+      return '50绫�';
+    case 'TYPE2':
+      return '50绫� - 500绫�';
+    case 'TYPE3':
+      return '50绫� - 1鍏噷';
+    case 'TYPE4':
+      return '50绫� - 2鍏噷';
+
+    default:
+      break;
+  }
 }
 
 /******************************************************************************************************************** */
@@ -338,7 +415,12 @@
   --el-text-color: white;
 }
 
+:deep(.el-link) {
+  --el-link-text-color: #23dad1;
+}
+
 .scrollbar {
   min-width: 300px;
+  /* color: #02ffea; */
 }
 </style>

--
Gitblit v1.9.3