From bf0eb543e2deab8a1629dd2a46f8e1cd191531e1 Mon Sep 17 00:00:00 2001
From: wangjuncheng <1>
Date: 星期四, 17 七月 2025 15:22:01 +0800
Subject: [PATCH] Merge branch 'master' of http://103.135.160.14:9034/r/NslWeb

---
 src/views/Home.vue |   93 ++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 89 insertions(+), 4 deletions(-)

diff --git a/src/views/Home.vue b/src/views/Home.vue
index e93eab5..d627921 100644
--- a/src/views/Home.vue
+++ b/src/views/Home.vue
@@ -26,12 +26,11 @@
   <ImagePreview v-if="showPreview" />
   <!-- <Weather v-if="weatherShow" @close="weatherShow = false" /> -->
   <Bar v-if="barShow" @close="barShow = false" />
-
   <Detail v-if="showDetail" />
 </template>
 
 <script setup>
-import { computed } from "vue";
+import { computed, onMounted, ref, getCurrentInstance } from "vue";
 import { useRoute } from "vue-router";
 import { useSimStore } from "@/store/simulation";
 import { storeToRefs } from "pinia";
@@ -56,14 +55,20 @@
 import GisView from "./GisView.vue";
 // import Device from "@/components/menu/Device.vue";
 import Detail from "@/components/tools/Detail.vue";
-// 涓嶅彲浠ュ垹闄わ紝鍚﹀垯鍏ㄥ眬鏍峰紡浼氫涪鎺夛紝涓嶇煡閬撳師鍥�
-import ResultAssess from "@/components/monifangzhen/ResultAssess.vue";
+// import ResultAssess from "@/components/monifangzhen/ResultAssess.vue";
 // import DangerAssess from "@/components/monifangzhen/DangerAssess.vue";
 import { showDeviceDetail } from "@/store";
+import { setupTokenRefresh, getDangerPoint, getAllCode } from "@/api/hpApi.js";
+import { convertToWKT } from "@/utils/wktUtils";
+import { getDeviceInfoSHG, getWeather } from "@/api/hpApi";
 
 const route = useRoute();
 const simStore = useSimStore();
 
+// 鎺ユ敹鏉ヨ嚜 ComponentA 鐨勪簨浠讹紝骞舵洿鏂� isFlying
+function handleBackToHome() {
+  backHome.value = false;
+}
 // 浠� store 涓В鏋勯渶瑕佺殑鐘舵��
 const {
   flowShow,
@@ -76,10 +81,90 @@
   showDangerAssess,
 } = storeToRefs(simStore);
 const { init, startYHGL, startZHJC, startMNFZ, startMNPG } = simStore;
+// 妯℃嫙鐨勭粡绾害鏁扮粍
+const multiPolygonCoordinates = [
+  [
+    [120.123456, 30.654321],
+    [120.234567, 30.765432],
+    [120.345678, 30.876543],
+    [120.123456, 30.654321], // 闂悎鐐�
+  ],
+  [
+    [121.111111, 31.222222],
+    [121.333333, 31.444444],
+    [121.555555, 31.666666],
+    [121.111111, 31.222222], // 闂悎鐐�
+  ],
+];
 
 // 璁$畻灞炴��
 const showDetail = computed(() => showDeviceDetail.value);
 
+function groupTopWithLeafNodes(dataArray) {
+  const result = {};
+
+  function traverse(nodes, topLevelName = null) {
+    if (!Array.isArray(nodes)) return;
+
+    for (const node of nodes) {
+      const isLeaf = !node.children || node.children.length === 0;
+
+      // 濡傛灉鏄《灞傝妭鐐癸紝璁板綍瀹冪殑鍚嶅瓧浣滀负 key
+      if (!topLevelName && !isLeaf) {
+        topLevelName = node.nameChn;
+        if (!result[topLevelName]) {
+          result[topLevelName] = [];
+        }
+      }
+
+      // 濡傛灉鏄彾瀛愯妭鐐癸紝鍔犲叆瀵瑰簲鏁扮粍
+      if (isLeaf && topLevelName) {
+        result[topLevelName].push({
+          name: node.nameChn,
+          code: node.code,
+        });
+      }
+
+      // 缁х画閫掑綊瀛愯妭鐐癸紙淇濇寔褰撳墠椤跺眰鍚嶇О锛�
+      if (node.children && node.children.length > 0) {
+        traverse(node.children, topLevelName);
+      }
+    }
+  }
+
+  // 閬嶅巻鏁翠釜澶ф暟缁勪腑鐨勬瘡涓�椤癸紙鍗虫瘡涓�涓尯鍩燂級
+  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 = groupTopWithLeafNodes(res.data[0].children);
+    console.log(simStore.townCodeAll, "涓杞帴鍙h幏鍙栦埂闀嘽ode");
+  });
+  setupTokenRefresh(); // 鑾峰彇瀹忓浘token
+  // getSimData(); //娴嬭瘯tr鍚庣
+  // 鑾峰彇闅愭偅鐐瑰垪琛紙鍥犱负涓杞悗绔帴鍙h幏鍙栧姞杞芥椂闂磋緝闀匡級
+  getDangerPoint("110116110000").then((res) => {
+    simStore.DangerPoint = res.data.pageData;
+  });
+
+  getDeviceInfoSHG(null).then((res) => {
+    simStore.devices = res.data.pageData;
+  });
+  try {
+    const wktResult = convertToWKT(multiPolygonCoordinates);
+    // console.log(wktResult,'a');
+    // 杈撳嚭: MULTIPOLYGON(((120.123456 30.654321,120.234567 30.765432,120.345678 30.876543,120.123456 30.654321)))
+  } catch (error) {
+    console.error(error.message);
+  }
+});
 // 鍒濆鍖�
 init();
 </script>

--
Gitblit v1.9.3