guonan
2025-06-12 b23bc4d88ed6215fdda94dc94a15dd62e9f4a5cc
src/views/GisView.vue
@@ -41,10 +41,10 @@
import { loadAreaPolygon } from "@/utils/area.js";
import { loadAreaPolygonAll } from "@/utils/area_all.js";
import { isVisibleDistance } from "@/utils/customEntity";
import { getDistrictCount, getDistrictCountByCity } from "@/api/index";
import { useRoute } from "vue-router";
import { EventBus } from "@/eventBus"; // 引入事件总线
import { useSimStore } from "@/store/simulation";
const route = useRoute();
const simStore = useSimStore();
import {
@@ -52,6 +52,7 @@
  getDeviceInfo,
  getAeraCode,
  getAeraTownCode,
  getDeviceCount,
} from "@/api/hpApi";
/////////////////////////地图影像选择/////////////////////////
const views = [
@@ -116,7 +117,6 @@
};
/////////////////////////地图影像选择/////////////////////////
const route = useRoute();
let handler = null;
/////////////////////////初始化地图/////////////////////////
function initMap() {
@@ -423,13 +423,40 @@
  },
};
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([]);
    if (level === "primary") {
      // 一级区域:直接调用 getAeraCode()
      // 如果是 "/zhjc" 路由,先获取设备统计接口数据
      if (showDeviceCount.value) {
        deviceTotal.value = await getDeviceCount();
      }
      const res = await getAeraCode();
      res.data.forEach((item) => {
        if (showDeviceCount.value) {
          const matchedDistrict = deviceTotal.value.data.find(
            (d) => d.districtName === item.districtName
          );
          if (matchedDistrict) {
            item.count = matchedDistrict.count; // 更新 count
          }
        }
        processDistrictItem(item, LEVEL_CONFIG[level], level);
      });
    } else if (level === "secondary") {
@@ -497,7 +524,7 @@
        res = await getDangerPoint(item.districtCode);
      } else if (route.path === "/zhjc") {
        // 请求监测设备数据
        res = await getDeviceInfo(item.districtCode);
        res = await getDeviceInfo(null,item.districtCode);
      } else {
        loadingInstance.close();
        return;