From 6958d50ab485cb42a99c0a410b40d45ee9ee9856 Mon Sep 17 00:00:00 2001
From: guonan <guonan201020@163.com>
Date: 星期二, 15 七月 2025 17:08:28 +0800
Subject: [PATCH] 避险场所

---
 src/api/hpApi.js   |    7 ++-
 src/views/Home.vue |   49 ++++++++++++++++--------
 src/views/mnfz.vue |   38 ++++++++++++++++--
 3 files changed, 71 insertions(+), 23 deletions(-)

diff --git a/src/api/hpApi.js b/src/api/hpApi.js
index b18a094..c085429 100644
--- a/src/api/hpApi.js
+++ b/src/api/hpApi.js
@@ -248,14 +248,17 @@
 }
 
 // 鏌ヨ瀛欒儭娌熼伩闄╁満鎵�
-export async function getSafePoint() {
+export async function getSafePoint(data) {
   const response = await axios.get("/hp/safeHavenLocation/getDataSelect", {
     params: {
-      divisionId: 110116110218
+      divisionId: data
     }
   });
   return response.data;
 }
+// 110116110218
+
+
 
 // 鏌ヨ鍖椾含甯�
 export async function getAllCode() {
diff --git a/src/views/Home.vue b/src/views/Home.vue
index 243e35a..ceb55ae 100644
--- a/src/views/Home.vue
+++ b/src/views/Home.vue
@@ -60,7 +60,7 @@
 import { showDeviceDetail } from "@/store";
 import { setupTokenRefresh, getDangerPoint, getAllCode } from "@/api/hpApi.js";
 import { convertToWKT } from "@/utils/wktUtils";
-import { getDeviceInfoSHG, getSafePoint } from "@/api/hpApi";
+import { getDeviceInfoSHG, getWeather } from "@/api/hpApi";
 
 const route = useRoute();
 const simStore = useSimStore();
@@ -100,35 +100,52 @@
 // 璁$畻灞炴��
 const showDetail = computed(() => showDeviceDetail.value);
 
-function extractAllChildrenInfoUnique(dataArray) {
-  const map = new Map();
+function groupTopWithLeafNodes(dataArray) {
+  const result = {};
 
-  function traverse(nodes) {
+  function traverse(nodes, topLevelName = null) {
     if (!Array.isArray(nodes)) return;
 
     for (const node of nodes) {
-      const key = node.code;
+      const isLeaf = !node.children || node.children.length === 0;
 
-      // 妫�鏌ユ槸鍚︽槸鏈�鍚庝竴灞傦紙娌℃湁瀛愯妭鐐规垨瀛愯妭鐐逛负绌烘暟缁勶級
-      if (!node.children || node.children.length === 0) {
-        if (key && !map.has(key)) {
-          map.set(key, { name: node.nameChn, code: key });
+      // 濡傛灉鏄《灞傝妭鐐癸紝璁板綍瀹冪殑鍚嶅瓧浣滀负 key
+      if (!topLevelName && !isLeaf) {
+        topLevelName = node.nameChn;
+        if (!result[topLevelName]) {
+          result[topLevelName] = [];
         }
-      } else {
-        // 濡傛灉鏈夊瓙鑺傜偣锛岀户缁�掑綊閬嶅巻
-        traverse(node.children);
+      }
+
+      // 濡傛灉鏄彾瀛愯妭鐐癸紝鍔犲叆瀵瑰簲鏁扮粍
+      if (isLeaf && topLevelName) {
+        result[topLevelName].push({
+          name: node.nameChn,
+          code: node.code,
+        });
+      }
+
+      // 缁х画閫掑綊瀛愯妭鐐癸紙淇濇寔褰撳墠椤跺眰鍚嶇О锛�
+      if (node.children && node.children.length > 0) {
+        traverse(node.children, topLevelName);
       }
     }
   }
 
-  traverse(dataArray);
-  return Array.from(map.values());
-}
+  // 閬嶅巻鏁翠釜澶ф暟缁勪腑鐨勬瘡涓�椤癸紙鍗虫瘡涓�涓尯鍩燂級
+  for (const item of dataArray) {
+    if (item && item.children && Array.isArray(item.children)) {
+      traverse([item]); // 鎶婂綋鍓嶉」鍖呰鎴愭暟缁勶紝鏂逛究缁熶竴澶勭悊
+    }
+  }
 
+  return result;
+}
 onMounted(async () => {
   getAllCode().then((res) => {
     // 鍖椾含甯傛墍鏈夋潙浠ュ強琛楅亾code
-    simStore.townCodeAll = extractAllChildrenInfoUnique(res.data[0].children);
+    simStore.townCodeAll = groupTopWithLeafNodes(res.data[0].children);
+    console.log(simStore.townCodeAll, "aaaaaaaaaaaaaaaaaaa");
   });
   setupTokenRefresh(); // 鑾峰彇瀹忓浘token
   // getSimData(); //娴嬭瘯tr鍚庣
diff --git a/src/views/mnfz.vue b/src/views/mnfz.vue
index b015a4a..6a243ed 100644
--- a/src/views/mnfz.vue
+++ b/src/views/mnfz.vue
@@ -142,28 +142,55 @@
   });
   dataSources.length = 0;
 }
+
 // 閬块櫓鍦烘墍锛岀豢鑹插瘜鏂囨湰
 async function addTetrahedron(visible) {
   const emergencyAreaList = [];
 
   try {
-    const res = await getSafePoint();
+    let codesToFetch = [];
 
-    const geoJsonData = convertToGeoJson(res.data);
+    // 鍒ゆ柇褰撳墠閫夋嫨鍖哄煙鏄惁涓衡�滃尯鈥�
+    if (simStore.selectedScheme.areaName.includes("鍖�")) {
+      // 浠� simStore.townCodeAll 涓嬁鍒拌鍖轰笅鐨勬墍鏈変埂闀� code
+      const townList = simStore.townCodeAll[simStore.selectedScheme.areaName];
+
+      // 鍋囪 townList 鏄竴涓暟缁勶紝閲岄潰姣忎釜鍏冪礌鏈� .code 瀛楁
+      if (Array.isArray(townList)) {
+        codesToFetch = townList.map((item) => item.code);
+      } else {
+        console.warn("鏈壘鍒板搴旂殑涔¢晣鍒楄〃");
+        return;
+      }
+    } else {
+      // 涓嶆槸鈥滃尯鈥濓紝灏变娇鐢ㄩ粯璁� code
+      codesToFetch = ["110116110218"];
+    }
+
+    // 骞跺彂璇锋眰鎵�鏈� code 鐨勯伩闄╃偣鏁版嵁
+    const allRes = await Promise.all(
+      codesToFetch.map((code) => getSafePoint(code))
+    );
+
+    // 鍚堝苟缁撴灉锛堝亣璁炬瘡涓� res.data 鏄竴涓暟缁勶級
+    const allSafePoints = allRes.flatMap((res) => res.data);
+
+    // 杞崲涓� GeoJSON锛堝鏋滄瘡涓� data 閮介渶瑕佸崟鐙鐞嗭級
+    const geoJsonData = convertToGeoJson(allSafePoints);
 
     // 鍔犺浇搴曞眰闈㈢墖锛堝杈瑰舰锛�
     const polygonEntities = await loadAreaPolygon(geoJsonData, true);
     emergencyAreaList.push(...polygonEntities);
 
     // 娣诲姞缁胯壊瀵屾枃鏈爣娉�
-    const textPromises = res.data.map(async (item) => {
+    const textPromises = allSafePoints.map(async (item) => {
       const point = earthCtrl.factory.createRichTextPoint(
         "閬块櫓鍦烘墍",
-        [item.lon , item.lat , 540],
+        [item.lon, item.lat, 540],
         {
           distanceDisplayCondition:
             new SmartEarth.Cesium.DistanceDisplayCondition(0, 2000),
-          fontColor: "#fff", 
+          fontColor: "#fff",
           fontSize: 20,
         },
         "0"
@@ -179,6 +206,7 @@
     console.error("鍔犺浇閬块櫓鍦烘墍澶辫触锛�", error);
   }
 }
+
 // 鍒犻櫎閬块櫓鍦烘墍鐨勫瘜鏂囨湰瀹炰綋
 function removeEmergencyPoints() {
   const emergencyAreaList = treeMap.get("閬块櫓鍦烘墍"); // 鑾峰彇瀛樺偍鐨勯伩闄╁満鎵�瀹炰綋鍒楄〃

--
Gitblit v1.9.3