| | |
| | | import { useSimStore } from "@/store/simulation"; |
| | | const simStore = useSimStore(); |
| | | |
| | | import { getDangerPoint, getDeviceInfo } from "@/api/hpApi"; |
| | | import { |
| | | getDangerPoint, |
| | | getDeviceInfo, |
| | | getAeraCode, |
| | | getAeraTownCode, |
| | | } from "@/api/hpApi"; |
| | | /////////////////////////地图影像选择///////////////////////// |
| | | const views = [ |
| | | { label: "地图", value: "map", icon: "地图.png" }, |
| | |
| | | }; |
| | | |
| | | // 初始化区域统计 |
| | | function initDistrictCount(level = "secondary") { |
| | | const getPoint = |
| | | level === "secondary" ? getDistrictCount : getDistrictCountByCity; |
| | | const config = LEVEL_CONFIG[level]; |
| | | |
| | | getPoint() |
| | | .then((res) => { |
| | | async function initDistrictCount(level = "secondary") { |
| | | try { |
| | | if (level === "primary") { |
| | | // 一级区域:直接调用 getAeraCode() |
| | | const res = await getAeraCode(); |
| | | res.data.forEach((item) => { |
| | | processDistrictItem(item, config, level); // 添加level参数 |
| | | 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") { |
| | | // 添加默认值 |