guonan
2025-06-16 a950e27408790e4a64e0e425a48ca4a542f6d06d
提交乡镇监测设备数量
已修改2个文件
107 ■■■■■ 文件已修改
src/api/hpApi.js 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/GisView.vue 97 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/hpApi.js
@@ -85,7 +85,7 @@
  return response.data;
}
// 按照行政区code查询乡镇code
// 按照行政区code查询乡镇code(此接口包含隐患点数量查询)
export async function getAeraTownCode(data) {
  const response = await axios.post("/hp/sinoDzHiddenDangerPoint/getHiddenDangerTownCount", {
    "dictDisasterGrade": "",
@@ -98,7 +98,7 @@
  return response.data;
}
// 根据乡镇Code获取隐患点
// 根据乡镇Code获取隐患点(此接口包含隐患点数量查询)
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;
}
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(() => {