From 32947c42c53afdd9a6c49637c4ecc8e5fa4be24c Mon Sep 17 00:00:00 2001
From: wangjuncheng <1>
Date: 星期三, 18 六月 2025 16:34:44 +0800
Subject: [PATCH] Merge branch 'master' of http://103.135.160.14:9034/r/NslWeb

---
 src/views/GisView.vue |  103 +++++++++++++++++++++++++++++----------------------
 1 files changed, 59 insertions(+), 44 deletions(-)

diff --git a/src/views/GisView.vue b/src/views/GisView.vue
index f286edd..e1b6921 100644
--- a/src/views/GisView.vue
+++ b/src/views/GisView.vue
@@ -417,40 +417,28 @@
   },
   // 涓�绾у尯鍩�
   primary: {
-    maxVisibleDistance: 50000000,
+    maxVisibleDistance: 60000000,
     minVisibleDistance: 70000,
     flyToHeight: 45000,
   },
 };
 
-const showDeviceCount = ref(false);
-
-// 鐩戝惉璺敱鍙樺寲
-watch(
-  () => route.name,
-  (newName) => {
-    console.log("璺敱鍚嶇О鍙樺寲:", newName);
-    // 浣跨敤涓夊厓杩愮畻绗︽潵鍐冲畾 showDeviceCount 鐨勫��
-    showDeviceCount.value = newName === "zhjc" ? true : false;
-    initDistrictCount("primary");
-  },
-  { immediate: true }
-);
-
 // 鍒濆鍖栧尯鍩熺粺璁�
 async function initDistrictCount(level = "secondary") {
   try {
-    const deviceTotal = ref([]);
+    const deviceAreaTotal = ref([]);
+    const deviceTownTotal = ref([]);
+
     if (level === "primary") {
-      // 涓�绾у尯鍩燂細鐩存帴璋冪敤 getAeraCode()
-      // 濡傛灉鏄� "/zhjc" 璺敱锛屽厛鑾峰彇璁惧缁熻鎺ュ彛鏁版嵁
-      if (showDeviceCount.value) {
-        deviceTotal.value = await getDeviceCount();
+      // 涓�绾у尯鍩熷鐞�
+      if (route.path === "/zhjc") {
+        deviceAreaTotal.value = await getDeviceCount(); // 鑾峰彇鍖虹骇璁惧缁熻
       }
+
       const res = await getAeraCode();
       res.data.forEach((item) => {
-        if (showDeviceCount.value) {
-          const matchedDistrict = deviceTotal.value.data.find(
+        if (route.path === "/zhjc") {
+          const matchedDistrict = deviceAreaTotal.value.data?.find(
             (d) => d.districtName === item.districtName
           );
           if (matchedDistrict) {
@@ -460,23 +448,40 @@
         processDistrictItem(item, LEVEL_CONFIG[level], level);
       });
     } else if (level === "secondary") {
-      // 浜岀骇鍖哄煙锛氬厛鑾峰彇涓�绾у尯鍩燂紝鍐嶉亶鍘嗘瘡涓竴绾у尯鍩熺殑 code 鏌ヨ浜岀骇鍖哄煙
+      // 浜岀骇鍖哄煙澶勭悊
       const primaryRes = await getAeraCode();
 
-      // 閬嶅巻鎵�鏈変竴绾у尯鍩熺殑 districtCode锛屽苟鍙戣姹備簩绾у尯鍩熸暟鎹�
-      const townPromises = primaryRes.data.map((item) =>
-        getAeraTownCode(item.districtCode)
+      if (route.path === "/zhjc") {
+        // 骞跺彂鑾峰彇姣忎釜鍖虹殑璁惧缁熻
+        deviceTownTotal.value = await Promise.all(
+          primaryRes.data.map((item) =>
+            getDeviceCount({ districtCode: Number(item.districtCode) })
+          )
+        );
+      }
+
+      // 骞跺彂鑾峰彇姣忎釜鍖轰笅鐨勯晣鏁版嵁
+      const townResults = await Promise.all(
+        primaryRes.data.map((item) => getAeraTownCode(item.districtCode))
       );
 
-      // 绛夊緟鎵�鏈変簩绾у尯鍩熻姹傚畬鎴�
-      const townResults = await Promise.all(townPromises);
+      // 澶勭悊姣忎釜鍖虹殑闀囨暟鎹�
+      for (let i = 0; i < townResults.length; i++) {
+        const townRes = townResults[i];
+        const deviceCountData = deviceTownTotal.value[i]?.data || []; // 瀵瑰簲鍖虹殑璁惧缁熻鏁版嵁
 
-      // 澶勭悊鎵�鏈変簩绾у尯鍩熸暟鎹�
-      townResults.forEach((townRes) => {
         townRes.data.forEach((townItem) => {
+          if (route.path === "/zhjc") {
+            const matchedTown = deviceCountData.find(
+              (d) => d.districtName === townItem.districtName
+            );
+            if (matchedTown) {
+              townItem.count = matchedTown.count;
+            }
+          }
           processDistrictItem(townItem, LEVEL_CONFIG[level], level);
         });
-      });
+      }
     } else {
       console.error("鏈煡鐨� level 绫诲瀷:", level);
     }
@@ -495,6 +500,12 @@
   } else {
     primaryHandler(html, item, config);
   }
+
+  // 姝ゅ蹇呴』鍔狅紝涓嶇劧浜屾璋冪敤鍒濆鍖栧嚱鏁扮殑鏃跺�欎細灏嗕竴浜岀骇鍖哄煙鎵�鏈夌殑鐐归兘鏄剧ず鍦ㄩ〉闈笂
+  html.show = isVisibleDistance(
+    config.minVisibleDistance,
+    config.maxVisibleDistance
+  );
 
   htmlEntityList.push(html);
 }
@@ -524,7 +535,7 @@
         res = await getDangerPoint(item.districtCode);
       } else if (route.path === "/zhjc") {
         // 璇锋眰鐩戞祴璁惧鏁版嵁
-        res = await getDeviceInfo(null,item.districtCode);
+        res = await getDeviceInfo(null, item.districtCode);
       } else {
         loadingInstance.close();
         return;
@@ -553,7 +564,7 @@
           point.name = point.hdName; // 闅愭偅鐐瑰悕绉�
           point.className = "district";
         } else if (route.path === "/zhjc") {
-          point.name = point.deviceForShort; // 璁惧绠�绉�
+          point.name = point.deviceName; // 璁惧绠�绉�
           point.className = "device";
         }
 
@@ -626,24 +637,28 @@
   });
 }
 
-// 璺敱鐩戝惉
+// 鍦ㄨ矾鐢辩洃鍚櫒涓�
 const validPaths = ["/", "/yhgl", "/zhjc"];
+
 watch(
   () => route.fullPath,
   (val) => {
     const isValidPath = validPaths.includes(val);
 
-    // 鎺у埗HTML瀹炰綋鏄剧ず
-    htmlEntityList.forEach((item) => {
-      item.show = isValidPath
-        ? isVisibleDistance(item.minVisibleDistance, item.maxVisibleDistance)
-        : false;
-    });
-
     // 鎺у埗鐩告満鍙樺寲鐩戝惉
     if (isValidPath) {
+      initAllDistrictCounts();
       handleCameraChange();
+      // 鎺у埗HTML瀹炰綋鏄剧ず
+      htmlEntityList.forEach((item) => {
+        item.show = isValidPath
+          ? isVisibleDistance(item.minVisibleDistance, item.maxVisibleDistance)
+          : false;
+      });
     } else {
+      htmlEntityList.forEach((item) => {
+        item.show = false;
+      });
       removeCameraChange();
     }
   }
@@ -679,8 +694,8 @@
 
 // 鍒濆鍖栧嚱鏁�
 function initAllDistrictCounts() {
-  initDistrictCount("secondary"); // 浜岀骇鍖哄煙
   initDistrictCount("primary"); // 涓�绾у尯鍩�
+  initDistrictCount("secondary"); // 浜岀骇鍖哄煙
 }
 
 onMounted(() => {
@@ -688,8 +703,8 @@
   addCityPolygon();
   initHandler();
   // initView()
-  loadAreaPolygon("/json/nsl_area.geojson");
-  loadAreaPolygonAll("/json/geometry.json", true);
+  // loadAreaPolygon("/json/nsl_area.geojson");
+  // loadAreaPolygonAll("/json/geometry.json", true);
   flyToHomeView();
   // 椤甸潰鍔犺浇鏃跺垵濮嬪寲
   initAllDistrictCounts();

--
Gitblit v1.9.3