From d8134b8a3c3e0b481bf447e5e8b0c022a3996d8f Mon Sep 17 00:00:00 2001
From: guonan <guonan201020@163.com>
Date: 星期三, 09 七月 2025 14:52:22 +0800
Subject: [PATCH] 优化目录树以及实时模拟最后弹窗的问题

---
 src/components/tools/LayerTree.vue |   80 +++++++++++++++++++++++++++++++++-------
 src/components/menu/TimeLine.vue   |   11 ++++-
 2 files changed, 74 insertions(+), 17 deletions(-)

diff --git a/src/components/menu/TimeLine.vue b/src/components/menu/TimeLine.vue
index 649f970..2be26e1 100644
--- a/src/components/menu/TimeLine.vue
+++ b/src/components/menu/TimeLine.vue
@@ -340,8 +340,9 @@
       }
 
       // 瑙﹀彂杩涘害鏇存柊
-      const progress = currentTime.value / totalDuration;
-      emit("timeUpdate", progress * 100);
+      // const progress = currentTime.value / totalDuration;
+      // 瀹炴椂妯℃嫙搴旇涓嶇敤鏄剧ず寮圭獥鍚�
+      // emit("timeUpdate", progress * 100);
 
       // 濡傛灉闇�瑕佽Е鍙戞煇浜涙洿鏂板嚱鏁帮紝涔熷彲浠ヤ繚鐣�
       updateWaterColorByTime();
@@ -1076,7 +1077,11 @@
 watch(
   () => finishPlay.value,
   (newVal) => {
-    if (newVal && selectedScheme.value.type === 2) {
+    if (
+      newVal &&
+      selectedScheme.value.type === 2 &&
+      simStore.rePlayList.length > 0
+    ) {
       handlePlayFinished();
     }
   }
diff --git a/src/components/tools/LayerTree.vue b/src/components/tools/LayerTree.vue
index cbe28aa..f265158 100644
--- a/src/components/tools/LayerTree.vue
+++ b/src/components/tools/LayerTree.vue
@@ -239,22 +239,61 @@
  * 娓呴櫎鍥惧眰瀹炰綋
  * @param {String} layerName - 鍥惧眰鍚嶇О
  */
-function clearLayerEntities(layerName) {
+// 鏆備笖淇濈暀
+// async function clearLayerEntities(layerName) {
+//   const list = treeMap.get(layerName);
+//   if (list && Array.isArray(list)) {
+//     for (const item of list) {
+//       const entity = await item;
+//       if (layerName == "缁煎悎鐩戞祴璁惧淇℃伅") {
+//         removeEntities(entity.deviceId);
+//       } else if (layerName == "瀛欒儭娌熼殣鎮g偣") {
+//         removeEntities(entity.hdId);
+//       }
+//     }
+//   }
+//   treeMap.delete(layerName);
+// }
+
+/**
+ * 娓呴櫎鍥惧眰瀹炰綋
+ * @param {String} layerName - 鍥惧眰鍚嶇О
+ */
+// 姝ゅ嚱鏁颁紭鍖栦簡鍦ㄦā鎷熶豢鐪熼〉闈紝濡傛灉鐐瑰嚮鐩綍鏍戦�変腑鍙栨秷锛屾偿浣嶈浠嶆樉绀�
+async function clearLayerEntities(layerName) {
+  const isMnfzPage = route.path === "/mnfz"; // 鍒ゆ柇鏄惁涓� /mnfz 椤甸潰
+
   const list = treeMap.get(layerName);
   if (list && Array.isArray(list)) {
-    list.forEach((entity) => {
-      clearAllPoints();
-    });
+    for (const item of list) {
+      const entity = await item;
+
+      let shouldRemove = true; // 榛樿瑕佸垹闄�
+
+      // 濡傛灉鏄� /mnfz 椤甸潰锛屽苟涓旀槸鈥滄偿浣嶈鈥濓紝鍒欎笉鍒犻櫎
+      if (isMnfzPage && entity.type === "娉ヤ綅璁�") {
+        shouldRemove = false;
+      }
+
+      if (shouldRemove) {
+        if (layerName === "缁煎悎鐩戞祴璁惧淇℃伅") {
+          removeEntities(entity.deviceId);
+        } else if (layerName === "瀛欒儭娌熼殣鎮g偣") {
+          removeEntities(entity.hdId);
+        }
+      }
+    }
   }
+
   treeMap.delete(layerName);
 }
 
-// 鐩戞帶璁惧寮�鍏冲彉鍖�
-watchEffect(() => {
+watchEffect(async () => {
   clearLayerEntities("缁煎悎鐩戞祴璁惧淇℃伅");
 
   if (simStore.DeviceShowSwitch) {
-    const deviceList = simStore.devices
+    // 浣跨敤 Promise.all 绛夊緟鎵�鏈夊紓姝ユ搷浣滃畬鎴�
+    const deviceListPromises = simStore.devices
       .filter((item) => item.deviceName?.includes("瀛欒儭娌�"))
       .map(async (item) => {
         const entity = viewer.entities.getById(item.deviceId);
@@ -263,8 +302,12 @@
         item.id = item.deviceId;
         item.className = "device";
         item.showLabel = true;
-        await createPoint(item);
+        await createPoint(item); // 纭繚 createPoint 杩斿洖涓�涓� Promise 鎴栬�呮湰韬氨鏄紓姝ュ嚱鏁�
+        return item; // 杩斿洖澶勭悊鍚庣殑 item
       });
+
+    // 绛夊緟鎵�鏈夊紓姝ユ搷浣滃畬鎴�
+    const deviceList = await Promise.all(deviceListPromises);
 
     if (deviceList.length) {
       treeMap.set("缁煎悎鐩戞祴璁惧淇℃伅", deviceList);
@@ -273,13 +316,15 @@
 });
 
 // 鐩戞帶闅愭偅鐐瑰紑鍏冲彉鍖�
-watchEffect(() => {
+watchEffect(async () => {
   clearLayerEntities("瀛欒儭娌熼殣鎮g偣");
 
   if (simStore.DangerShowSwitch) {
-    const dangerPoints = simStore.DangerPoint.filter((item) =>
+    const filteredPoints = simStore.DangerPoint.filter((item) =>
       item.position?.includes("瀛欒儭娌�")
-    ).map(async (item) => {
+    );
+
+    const dangerPointPromises = filteredPoints.map(async (item) => {
       const entity = viewer.entities.getById(item.hdId);
       item.id = item.hdId;
       item.name = item.hdName;
@@ -288,11 +333,18 @@
       item.showBillboard = true;
       item.type = item.disasterType;
       item.className = "district";
-      await createPoint(item);
+      await createPoint(item); // 纭繚 createPoint 鏄紓姝ュ嚱鏁�
+      return item; // 杩斿洖澶勭悊濂界殑 item
     });
 
-    if (dangerPoints.length) {
-      treeMap.set("瀛欒儭娌熼殣鎮g偣", dangerPoints);
+    try {
+      const resolvedPoints = await Promise.all(dangerPointPromises);
+
+      if (resolvedPoints.length) {
+        treeMap.set("瀛欒儭娌熼殣鎮g偣", resolvedPoints);
+      }
+    } catch (error) {
+      console.error("鍒涘缓闅愭偅鐐规椂鍙戠敓閿欒:", error);
     }
   }
 });

--
Gitblit v1.9.3