From e98dee8d702092a88610c3e3ae08bbf4a9c4d494 Mon Sep 17 00:00:00 2001
From: wangjuncheng <1>
Date: 星期一, 19 五月 2025 13:57:34 +0800
Subject: [PATCH] fix change

---
 src/components/menu/Device.vue |   33 ++++++++++++++++++++++++++-------
 1 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/src/components/menu/Device.vue b/src/components/menu/Device.vue
index e3d7932..0f7ceb0 100644
--- a/src/components/menu/Device.vue
+++ b/src/components/menu/Device.vue
@@ -27,26 +27,46 @@
 </template>
 
 <script setup>
+import { ref, computed, onMounted, watch, onBeforeUnmount, } from "vue";
+import { useRoute, onBeforeRouteUpdate } from 'vue-router';
 import { createPoint, removeEntities } from "@/utils/map";
-import { ref, computed, onMounted, watch } from "vue";
 import { deviceDictList, getDictName } from "@/constant/dict.js";
 import { getDeviceInfo } from "@/api/hpApi";
 import { initeWaterPrimitiveView } from "@/utils/water"; //鐩告満flyTo鍑芥暟锛屽悗缁璷ptions鍒楄〃涓湁瀵瑰簲缁忕含搴﹀悗寮冪敤
 import { useSimStore } from "@/store/simulation";
 const simStore = useSimStore();
-const deviceListAll = ref([]);
 onMounted(() => {
   loadDeviceList("瀛欒儭娌�");
   initeWaterPrimitiveView()
+});
+
+onBeforeRouteUpdate((to, from, next) => {
+  if (to.path !== '/zhjc') {
+    handleCleanup();
+  }
+  next();
+});
+const route = useRoute();
+
+onBeforeUnmount(() => {
+  if (route.path !== '/zhjc') {
+    handleCleanup();
+  }
 });
 watch(() => simStore.DeviceShowSwitch, (newValue, oldValue) => {
   if (newValue) {
     initializeDevicePoints();
   } else {
-    removeEntities();
+    handleCleanup()
   }
 });
+const deviceListAll = ref([]);
 const deviceEntities = ref([]);
+const handleCleanup = () => {
+  deviceListAll.value.forEach(item => {
+    removeEntities(item.deviceId);
+  });
+}
 const initializeDevicePoints = () => {
   const list = [];
   deviceListAll.value.forEach((item, index) => {
@@ -57,7 +77,7 @@
     item.className = "device";
     item.showLabel = true;
     // 鎵撳嵃姣忎釜璁惧鐨勫悕绉板拰璁惧绫诲瀷
-    // console.log(`璁惧鍚嶇О: ${item.deviceName}, 璁惧绫诲瀷: ${item.dictDeviceType}`);
+    console.log(`璁惧鍚嶇О: ${item.id}, 璁惧绫诲瀷: ${item.name}`);
     createPoint(item);
   });
   deviceEntities.value = list;
@@ -65,13 +85,14 @@
 // 鏍规嵁鍖哄煙鍚嶇О鍔犺浇璁惧鍒楄〃
 const loadDeviceList = async (areaName) => {
   try {
+    handleCleanup()
     const res = await getDeviceInfo();
     const allDevices = res.data.pageData;
     const devicesInArea = allDevices.filter((item) =>
       item.deviceName?.includes(areaName)
     );
     deviceListAll.value = devicesInArea;
-    removeEntities();
+    deviceListAll.length = 0;
     initializeDevicePoints();
   } catch (error) {
     console.error("鍔犺浇璁惧淇℃伅澶辫触", error);
@@ -125,12 +146,10 @@
   // 鍏堟寜璁惧绫诲瀷鍒嗙粍
   deviceListAll.value.forEach((device) => {
     const typeName = getDictName(deviceDictList, device.dictDeviceType);
-
     if (!typeName) {
       console.warn("鏈壘鍒拌澶囩被鍨�:", device);
       return;
     }
-
     if (!typeMap[typeName]) {
       typeMap[typeName] = [];
     }

--
Gitblit v1.9.3