guonan
2025-06-12 b23bc4d88ed6215fdda94dc94a15dd62e9f4a5cc
src/views/GisView.vue
@@ -41,13 +41,19 @@
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 { getDangerPoint, getDeviceInfo } from "@/api/hpApi";
import {
  getDangerPoint,
  getDeviceInfo,
  getAeraCode,
  getAeraTownCode,
  getDeviceCount,
} from "@/api/hpApi";
/////////////////////////地图影像选择/////////////////////////
const views = [
  { label: "地图", value: "map", icon: "地图.png" },
@@ -111,7 +117,6 @@
};
/////////////////////////地图影像选择/////////////////////////
const route = useRoute();
let handler = null;
/////////////////////////初始化地图/////////////////////////
function initMap() {
@@ -418,23 +423,67 @@
  },
};
const showDeviceCount = ref(false);
// 监听路由变化
watch(
  () => route.name,
  (newName) => {
    console.log("路由名称变化:", newName);
    // 使用三元运算符来决定 showDeviceCount 的值
    showDeviceCount.value = newName === "zhjc" ? true : false;
    initDistrictCount("primary");
  },
  { immediate: true }
);
// 初始化区域统计
function initDistrictCount(level = "secondary") {
  const getPoint =
    level === "secondary" ? getDistrictCount : getDistrictCountByCity;
  const config = LEVEL_CONFIG[level];
  getPoint()
    .then((res) => {
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) => {
        processDistrictItem(item, config, level); // 添加level参数
        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);
      });
    })
    .catch((error) => {
      console.error(`初始化${level}级区域统计失败:`, error);
    });
}
    } else if (level === "secondary") {
      // 二级区域:先获取一级区域,再遍历每个一级区域的 code 查询二级区域
      const primaryRes = await getAeraCode();
      // 遍历所有一级区域的 districtCode,并发请求二级区域数据
      const townPromises = primaryRes.data.map((item) =>
        getAeraTownCode(item.districtCode)
      );
      // 等待所有二级区域请求完成
      const townResults = await Promise.all(townPromises);
      // 处理所有二级区域数据
      townResults.forEach((townRes) => {
        townRes.data.forEach((townItem) => {
          processDistrictItem(townItem, LEVEL_CONFIG[level], level);
        });
      });
    } else {
      console.error("未知的 level 类型:", level);
    }
  } catch (error) {
    console.error(`初始化 ${level} 级区域统计失败:`, error);
  }
}
// 处理单个区域项
function processDistrictItem(item, config, level = "secondary") {
  // 添加默认值
@@ -475,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;