From 0719dc09c2d9b297f836c4e0832c9db622adfcd0 Mon Sep 17 00:00:00 2001
From: guonan <guonan201020@163.com>
Date: 星期六, 07 六月 2025 18:25:58 +0800
Subject: [PATCH] 增加隐患点及监测设备以及解决ID报错问题

---
 src/views/GisView.vue |   91 +++++++++++++++++++++++----------------------
 1 files changed, 46 insertions(+), 45 deletions(-)

diff --git a/src/views/GisView.vue b/src/views/GisView.vue
index c214560..4d59796 100644
--- a/src/views/GisView.vue
+++ b/src/views/GisView.vue
@@ -36,6 +36,7 @@
   addTileset,
   addTerrain,
   removeEntities,
+  clearAllPoints,
 } from "@/utils/map.js";
 import { loadAreaPolygon } from "@/utils/area.js";
 import { loadAreaPolygonAll } from "@/utils/area_all.js";
@@ -46,7 +47,7 @@
 import { useSimStore } from "@/store/simulation";
 const simStore = useSimStore();
 
-import { getDangerPoint } from "@/api/hpApi";
+import { getDangerPoint, getDeviceInfo } from "@/api/hpApi";
 /////////////////////////鍦板浘褰卞儚閫夋嫨/////////////////////////
 const views = [
   { label: "鍦板浘", value: "map", icon: "鍦板浘.png" },
@@ -450,78 +451,82 @@
 }
 import { ElMessage } from "element-plus";
 
-const districtList = ref([]); // 褰撳墠鍖哄煙鐨勯殣鎮g偣鍒楄〃
-const loadedPointIds = new Set(); // 宸插姞杞界殑闅愭偅鐐笽D闆嗗悎
+const districtList = ref([]);
 
 // 璁剧疆浜岀骇鍖哄煙鐐瑰嚮澶勭悊(璇锋眰闅愭偅鐐癸紝鐩戞祴璁惧绛�)
 function secondaryHandler(html, item, config) {
   html.element.addEventListener("click", async () => {
     try {
-      // handleCleanup();
+      // 娓呯悊宸叉湁鐐�
+      handleCleanup();
 
-      // 鏄剧ず loading 鎻愮ず
+      // 鏄剧ず loading 鎻愮ず锛堟棤閬僵锛屼粎鏂囧瓧+杞湀锛�
       const loadingInstance = ElMessage({
-        type: "success",
-        message: "闅愭偅鐐规鍦ㄥ姞杞戒腑...",
-        duration: 0,
-        icon: "el-icon-loading", // 纭繚浣跨敤鐨勬槸Element Plus鎻愪緵鐨刲oading鍥炬爣绫诲悕
-        grouping: true,
-        customClass: "custom-loading-message", // 娣诲姞鑷畾涔夌被鍚�
+        type: "info",
+        message: "鏁版嵁姝e湪鍔犺浇涓�...",
+        duration: 0, // 鎸佺画鏄剧ず锛岀洿鍒版墜鍔ㄥ叧闂�
+        icon: "loading", // 鏄剧ず涓� loading 鍥炬爣锛圗lement Plus 鏀寔锛�
+        grouping: true, // 鐩稿悓鍐呭鐨勬秷鎭悎骞讹紝閬垮厤閲嶅鎻愮ず
       });
-      // 璇锋眰闅愭偅鐐规暟鎹�
-      const res = await getDangerPoint(item.districtCode);
 
-      const newPoints = res.data.pageData;
+      let res;
+      if (route.path === "/yhgl") {
+        // 璇锋眰闅愭偅鐐规暟鎹�
+        res = await getDangerPoint(item.districtCode);
+      } else if (route.path === "/zhjc") {
+        // 璇锋眰鐩戞祴璁惧鏁版嵁
+        res = await getDeviceInfo(item.districtCode);
+      } else {
+        loadingInstance.close();
+        return;
+      }
+      districtList.value = [];
+      // 鏇存柊鏁版嵁
+      districtList.value = res.data.pageData;
 
-      if (newPoints.length === 0) {
-        ElMessage.warning("璇ュ尯鍩熸殏鏃犻殣鎮g偣");
-        districtList.value = [];
+      if (districtList.value.length === 0) {
+        ElMessage.warning("璇ュ尯鍩熸殏鏃犵浉鍏虫暟鎹�");
         loadingInstance.close();
         return;
       }
 
-      // 娓呯┖褰撳墠鍖哄煙鏄剧ず鐨勯殣鎮g偣鍒楄〃锛堜絾涓嶆竻闄ゅ凡鍔犺浇鐨勬爣璁帮級
-      districtList.value = [];
-
-      // 閬嶅巻鏂版暟鎹紝杩囨护鎺夊凡鍔犺浇杩囩殑鐐�
-      for (const [index, point] of newPoints.entries()) {
-        if (loadedPointIds.has(point.hdId)) {
-          continue; // 濡傛灉宸插姞杞斤紝璺宠繃
-        }
-
-        // 娣诲姞鍒板凡鍔犺浇闆嗗悎
-        loadedPointIds.add(point.hdId);
-
-        // 璁剧疆鐐瑰睘鎬�
-        point.id = point.hdId;
-        point.name = point.hdName;
-        point.latitude = point.lat;
-        point.longitude = point.lon;
+      // 鍒涘缓鍦板浘鐐�
+      for (const [index, point] of districtList.value.entries()) {
+        point.id = point.hdId || point.deviceId; // 鏍规嵁瀹為檯鎯呭喌璋冩暣
+        point.latitude = point.lat || point.latitude; // 鏍规嵁瀹為檯鎯呭喌璋冩暣
+        point.longitude = point.lon || point.longitude; // 鏍规嵁瀹為檯鎯呭喌璋冩暣
         point.showBillboard = true;
-        point.type = point.disasterType;
+        point.type = point.disasterType || point.deviceTypeName; // 鏍规嵁瀹為檯鎯呭喌璋冩暣
         point.className = "district";
 
-        districtList.value.push(point); // 鏇存柊褰撳墠鍖哄煙闅愭偅鐐瑰垪琛�
+        // 鉁� 鏍规嵁璺敱鍐冲畾鍚嶇О瀛楁
+        if (route.path === "/yhgl") {
+          point.name = point.hdName; // 闅愭偅鐐瑰悕绉�
+          point.className = "district";
+        } else if (route.path === "/zhjc") {
+          point.name = point.deviceForShort; // 璁惧绠�绉�
+          point.className = "device";
+        }
 
-        await createPoint(point); // 鍒涘缓鍦板浘鐐�
+        await createPoint(point);
       }
 
       // 椋炲悜鎸囧畾浣嶇疆
       await flyToDistrict(item.longitude, item.latitude, config.flyToHeight);
 
-      // 鍔犺浇瀹屾垚鍚庡叧闂� loading
+      // 鍔犺浇瀹屾垚鍚庡叧闂� loading 鎻愮ず
       loadingInstance.close();
     } catch (error) {
       console.error("鍖哄煙鐐瑰嚮澶勭悊澶辫触:", error);
       ElMessage.error("鏁版嵁鍔犺浇澶辫触锛岃绋嶅悗鍐嶈瘯");
+      loadingInstance.close(); // 纭繚鍦ㄥ彂鐢熼敊璇椂涔熷叧闂� loading 鎻愮ず
     }
   });
 }
 
 const handleCleanup = async () => {
-  await Promise.all(
-    districtList.value.map((item) => removeEntities(item.hdId))
-  );
+  districtList.value = [];
+  clearAllPoints();
 };
 
 // 璁剧疆涓�绾у尯鍩熺偣鍑诲鐞�
@@ -727,9 +732,5 @@
 }
 .earthBox.shift-right {
   right: 13%;
-}
-.custom-loading-message .el-icon-loading {
-  color: #409eff !important; /* 璁剧疆涓轰綘鎯宠鐨勯鑹� */
-  font-size: 18px; /* 鍙�夛細璋冩暣鍥炬爣澶у皬 */
 }
 </style>

--
Gitblit v1.9.3