From f57633ef165ae24ae858894e3b9583a00d3ef7f6 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期三, 03 七月 2024 17:49:21 +0800
Subject: [PATCH] 分段轨迹

---
 src/views/realtimemode/RealtimeMode.vue |  175 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 173 insertions(+), 2 deletions(-)

diff --git a/src/views/realtimemode/RealtimeMode.vue b/src/views/realtimemode/RealtimeMode.vue
index b991977..c4de517 100644
--- a/src/views/realtimemode/RealtimeMode.vue
+++ b/src/views/realtimemode/RealtimeMode.vue
@@ -1,9 +1,180 @@
 <template>
-  <div>RealtimeMode</div>
+  <div class="p-events-none m-t-2">
+    <el-row justify="center" align="middle" class="top-wrap">
+      <DeviceChange @change="onDeviceChange"></DeviceChange>
+    </el-row>
+    <el-row class="m-t-2">
+      <FactorRadio
+        :device-type="deviceType"
+        @change="(e) => (factorType = e)"
+      ></FactorRadio>
+    </el-row>
+    <el-row class="m-t-2">
+      <FactorLegend
+        class="m-t-2"
+        :factor="factorDatas.factor[factorType]"
+      ></FactorLegend>
+    </el-row>
+    <DashBoard class="dash-board" :factor-datas="factorDatas"></DashBoard>
+    <RealTimeTrend
+      class="real-time-trend"
+      :factor-datas="factorDatas"
+      :device-type="deviceType"
+    ></RealTimeTrend>
+  </div>
 </template>
 
 <script>
+import { useFetchData } from '@/composables/fetchData';
+import { TYPE0 } from '@/constant/device-type';
+import { FactorDatas } from '@/model/FactorDatas';
+import monitorDataApi from '@/api/monitorDataApi';
+import DashBoard from './component/DashBoard.vue';
+import RealTimeTrend from './component/RealTimeTrend.vue';
+import DeviceChange from './component/DeviceChange.vue';
+import { realTimeMapAnimation } from '@/utils/map/animation';
+
+// const mapAnimation = new MapAnimation();
+
 export default {
-  name: 'HistoryPage'
+  components: { DashBoard, RealTimeTrend, DeviceChange },
+  setup() {
+    const { loading, fetchData } = useFetchData(10000);
+    return { loading, fetchData };
+  },
+  data() {
+    return {
+      // 鐩戞祴璁惧绫诲瀷
+      deviceType: TYPE0,
+      deviceCode: '0a0000000001',
+      // 鐩戞祴鍥犲瓙鐨勭被鍨嬬紪鍙�
+      factorType: '1',
+      // 鏂拌幏鍙栫殑鐩戞祴鏁版嵁
+      factorDatas: new FactorDatas(),
+      // 鍏ㄩ儴鐩戞祴鏁版嵁
+      allFactorDatas: new FactorDatas()
+    };
+  },
+  watch: {
+    factorType(nV, oV) {
+      if (nV != oV) {
+        realTimeMapAnimation.setFactorType(nV);
+      }
+    }
+  },
+  computed: {
+    latestTime() {
+      if (this.factorDatas.times.length == 0) {
+        return '';
+      } else {
+        return this.factorDatas.times[this.factorDatas.times.length - 1];
+      }
+    }
+  },
+  methods: {
+    onDeviceChange({ type, deviceCode }) {
+      this.deviceType = type;
+      this.deviceCode = deviceCode;
+      this.clearFetchingTask();
+      realTimeMapAnimation.stop();
+      this.allFactorDatas.clearData();
+      this.factorDatas.clearData();
+      this.notFirstFetch = false;
+      this.fetchRealTimeData();
+    },
+    onFetchData(data) {
+      // todo 鏍规嵁璁惧绫诲瀷鍒囨崲鍦板浘鐩戞祴鍥犲瓙灞曠ず鍗曢�夋銆佹姌绾垮浘澶嶉�夋銆佹暟鎹〃鏍煎閫夋鐨勫洜瀛愮被鍨�
+      // this.deviceType = type;
+      const fDatas = new FactorDatas();
+      fDatas.setData(data, this.drawMode, () => {
+        fDatas.refreshHeight(this.factorType);
+        // this.draw();
+        this.factorDatas = fDatas;
+      });
+    },
+    fetchRealTimeData() {
+      // fixme 2024.5.3 姝ゅ鍒濆鑾峰彇鐨勬暟鎹紝鍙傛暟搴旇鐢眘earchbar鍐冲畾锛屽悗缁慨鏀�
+      this.fetchData((page) => {
+        return monitorDataApi
+          .fetchHistroyData({
+            deviceCode: this.deviceCode,
+            // startTime: '2021-11-04 09:53:35',
+            page,
+            perPage: 100
+          })
+          .then((res) => {
+            this.onFetchData(res.data);
+            this.onMapData(res.data);
+            this.fetchNextData();
+          });
+      });
+    },
+    clearFetchingTask() {
+      if (this.fetchingTask) {
+        clearInterval(this.fetchingTask);
+        this.fetchingTask = undefined;
+      }
+    },
+    fetchNextData() {
+      this.clearFetchingTask();
+      this.fetchingTask = setInterval(() => {
+        if (this.isFetching) {
+          return;
+        }
+
+        this.isFetching = true;
+        this.fetchData(() => {
+          return monitorDataApi
+            .fetchNextData({
+              deviceCode: this.deviceCode,
+              updateTime: this.latestTime,
+              perPage: 10
+            })
+            .then((res) => {
+              this.onFetchData(res.data);
+              this.onMapData(res.data);
+            })
+            .finally(() => (this.isFetching = false));
+        });
+      }, 10000);
+    },
+    onMapData(dataList) {
+      let startIndex = this.allFactorDatas.length() - 1;
+      if (!this.notFirstFetch) {
+        startIndex = dataList.length - 2;
+        this.notFirstFetch = true;
+      }
+      startIndex = startIndex < 0 ? 0 : startIndex;
+      return new Promise((resolve, reject) => {
+        this.allFactorDatas.addData(dataList, this.drawMode, () => {
+          realTimeMapAnimation.moveAnimation(
+            this.allFactorDatas,
+            this.factorType,
+            startIndex
+          );
+        });
+      });
+    }
+  },
+  mounted() {
+    this.fetchRealTimeData();
+  },
+  unmounted() {
+    this.clearFetchingTask();
+    realTimeMapAnimation.stop();
+    console.log('clear');
+  }
 };
 </script>
+<style scoped>
+.dash-board {
+  position: absolute;
+  left: 0;
+  bottom: 2px;
+}
+.real-time-trend {
+  position: absolute;
+  right: 0;
+  top: 0;
+}
+</style>

--
Gitblit v1.9.3