From 6958d50ab485cb42a99c0a410b40d45ee9ee9856 Mon Sep 17 00:00:00 2001 From: guonan <guonan201020@163.com> Date: 星期二, 15 七月 2025 17:08:28 +0800 Subject: [PATCH] 避险场所 --- src/views/Home.vue | 49 +++++++++++++++++++++++++++++++++---------------- 1 files changed, 33 insertions(+), 16 deletions(-) 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鍚庣 -- Gitblit v1.9.3