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/tools/LayerTree.vue | 2 +- src/utils/map.js | 17 ++++++++++++----- src/components/menu/Device.vue | 33 ++++++++++++++++++++++++++------- 3 files changed, 39 insertions(+), 13 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] = []; } diff --git a/src/components/tools/LayerTree.vue b/src/components/tools/LayerTree.vue index 1b44d8f..c534081 100644 --- a/src/components/tools/LayerTree.vue +++ b/src/components/tools/LayerTree.vue @@ -231,7 +231,7 @@ } else if (entityList && typeof entityList.show !== "undefined") { entityList.show = checked; } else { - // console.error(`鏃犳硶璁剧疆鍥惧眰 ${name} 鐨勫彲瑙佹�); + console.error(`鏃犳硶璁剧疆鍥惧眰 ${name} 鐨勫彲瑙佹�); } } diff --git a/src/utils/map.js b/src/utils/map.js index 1aadced..06ec13e 100644 --- a/src/utils/map.js +++ b/src/utils/map.js @@ -156,12 +156,19 @@ return entity; } -export function removeEntities() { - entities.forEach(entity => { - viewer.entities.remove(entity) - entity.show = false; +// export function removeEntities() { +// entities.forEach(entity => { +// viewer.entities.remove(entity) +// entity.show = false; +// }); +// // entities = [] +// } +export function removeEntities(id) { + entities.forEach((entity, index) => { + if (entity.id === id) { + viewer.entities.remove(entity); + } }); - // entities = [] } function removeHandler() { if (interativeHandler != null && Cesium.defined(interativeHandler)) { -- Gitblit v1.9.3