From a950e27408790e4a64e0e425a48ca4a542f6d06d Mon Sep 17 00:00:00 2001
From: guonan <guonan201020@163.com>
Date: 星期一, 16 六月 2025 17:39:18 +0800
Subject: [PATCH] 提交乡镇监测设备数量

---
 src/views/GisView.vue |   97 ++++++++++++++++++++++++++++--------------------
 src/api/hpApi.js      |   10 +++--
 2 files changed, 62 insertions(+), 45 deletions(-)

diff --git a/src/api/hpApi.js b/src/api/hpApi.js
index 9d0e86f..6be05d2 100644
--- a/src/api/hpApi.js
+++ b/src/api/hpApi.js
@@ -85,7 +85,7 @@
   return response.data;
 }
 
-// 鎸夌収琛屾斂鍖篶ode鏌ヨ涔¢晣code
+// 鎸夌収琛屾斂鍖篶ode鏌ヨ涔¢晣code(姝ゆ帴鍙e寘鍚殣鎮g偣鏁伴噺鏌ヨ)
 export async function getAeraTownCode(data) {
   const response = await axios.post("/hp/sinoDzHiddenDangerPoint/getHiddenDangerTownCount", {
     "dictDisasterGrade": "",
@@ -98,7 +98,7 @@
   return response.data;
 }
 
-// 鏍规嵁涔¢晣Code鑾峰彇闅愭偅鐐�
+// 鏍规嵁涔¢晣Code鑾峰彇闅愭偅鐐�(姝ゆ帴鍙e寘鍚殣鎮g偣鏁伴噺鏌ヨ)
 export async function getDangerPoint(data) {
   const response = await axios.post("/hp/sinoDzHiddenDangerPoint/getData", {
     filterObject: {
@@ -211,7 +211,9 @@
 
 
 // 鏌ヨ鍖椾含甯傜洃娴嬭澶囩殑鏁伴噺
-export async function getDeviceCount() {
-  const response = await axios.get("/hp/device/statisticsCountyByDeviceType");
+export async function getDeviceCount(params = {}) {
+  const response = await axios.get("/hp/device/statisticsCountyByDeviceType", {
+    params
+  });
   return response.data;
 }
\ No newline at end of file
diff --git a/src/views/GisView.vue b/src/views/GisView.vue
index f286edd..6abc398 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;
@@ -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(() => {

--
Gitblit v1.9.3