From 2280e8be717608bb36c3cf921f129db24349396d Mon Sep 17 00:00:00 2001
From: guonan <guonan201020@163.com>
Date: 星期二, 10 六月 2025 17:55:29 +0800
Subject: [PATCH] 大改图层树

---
 src/components/menu/Device.vue |   84 +++++++++++++++++-------------------------
 1 files changed, 34 insertions(+), 50 deletions(-)

diff --git a/src/components/menu/Device.vue b/src/components/menu/Device.vue
index 99d409b..e587b5e 100644
--- a/src/components/menu/Device.vue
+++ b/src/components/menu/Device.vue
@@ -85,8 +85,9 @@
 
 onMounted(async () => {
   try {
-    await getData();
-    await loadDeviceList(selectValue.value);
+    if (simStore.devices && simStore.devices.length > 0) {
+      await loadDeviceList(selectValue.value);
+    }
     // initeWaterPrimitiveView();
   } finally {
     isLoading.value = false;
@@ -106,21 +107,20 @@
     clearAllPoints();
   }
 });
-watch(
-  () => simStore.DeviceShowSwitch,
-  (newValue, oldValue) => {
-    if (newValue) {
-      initializeDevicePoints();
-    } else {
-      clearAllPoints();
-    }
-  }
-);
+
+// watch(
+//   () => simStore.DeviceShowSwitch,
+//   (newValue, oldValue) => {
+//     if (newValue) {
+//       initializeDevicePoints();
+//     } else {
+//       clearAllPoints();
+//     }
+//   }
+// );
 
 const deviceListAll = ref([]);
-const deviceEntities = ref([]);
 
-// const initializeDevicePoints = (val) => {
 const initializeDevicePoints = () => {
   const list = [];
   // val.forEach((item, index) => {
@@ -135,57 +135,38 @@
     // console.log(`璁惧鍚嶇О: ${item.id}, 璁惧绫诲瀷: ${item.name}`);
     createPoint(item);
   });
-  deviceEntities.value = list;
 };
-const allDevices = ref([]);
-const getData = async () => {
-  const res = await getDeviceInfoShg();
-  allDevices.value = res.data.pageData;
-};
+
 // 鏍规嵁鍖哄煙鍚嶇О鍔犺浇璁惧鍒楄〃
 const loadDeviceList = async (areaName) => {
   try {
     clearAllPoints();
     isLoading.value = true;
-    // const res = await getDeviceInfoShg();
-    // const allDevices = res.data.pageData;
-    deviceListAll.value = allDevices.value.filter((item) =>
+
+    deviceListAll.value = simStore.devices.filter((item) =>
       item.deviceName?.includes(areaName)
     );
 
-    initializeDevicePoints();
-    // getDeviceInfo().then((res) => {
-    //   const list = res.data.pageData;
-    //   deviceListAll.value = [];
-
-    //   let index = 0;
-    //   const batchSize = 50; // 姣忔澶勭悊鐨勬暟閲�
-    //   const delay = 100; // 姣忛殧澶氬皯姣澶勭悊涓�娆�
-
-    //   const intervalId = setInterval(() => {
-    //     // 鍙栧嚭褰撳墠鎵规鐨勬暟鎹�
-    //     const batch = list.slice(index, index + batchSize);
-
-    //     if (batch.length === 0) {
-    //       clearInterval(intervalId); // 鏁版嵁澶勭悊瀹屼簡锛屽仠姝㈠畾鏃跺櫒
-    //       return;
-    //     }
-
-    //     // 鎶婂綋鍓嶆壒娆$殑鏁版嵁 push 鍒� deviceListAll
-    //     deviceListAll.value = [...deviceListAll.value, ...batch];
-
-    //     // 瀵瑰綋鍓嶆壒娆℃墽琛屽垵濮嬪寲鏂规硶
-    //     initializeDevicePoints(batch);
-
-    //     index += batchSize;
-    //   }, delay);
-    // });
+    await initializeDevicePoints();
   } catch (error) {
     console.error("鍔犺浇璁惧淇℃伅澶辫触", error);
   } finally {
     isLoading.value = false;
   }
 };
+
+// 鐩戝惉 simStore.devices 鍙樺寲
+watch(
+  () => simStore.devices,
+  (newVal) => {
+    if (newVal && newVal.length > 0) {
+      loadDeviceList(selectValue.value);
+    } else {
+      clearAllPoints();
+      deviceListAll.value = [];
+    }
+  }
+);
 
 // 澶勭悊鍖哄煙鍙樺寲浜嬩欢
 const handleChange = (item) => {
@@ -195,6 +176,8 @@
   }
   // 鏍规嵁鏂板尯鍩熷悕閲嶆柊鍔犺浇璁惧鍒楄〃
   loadDeviceList(item);
+  initializeDevicePoints();
+
   // console.log(deviceListAll.value);
 };
 
@@ -246,6 +229,7 @@
 });
 
 function handleTreeNodeClick(data) {
+  initializeDevicePoints();
   // 鍙湁璁惧鑺傜偣鎵嶅鐞嗙偣鍑讳簨浠�
   if (!data.children) {
     const entity = viewer.entities.getById(data.deviceId);

--
Gitblit v1.9.3