| | |
| | | }, |
| | | // 一级区域 |
| | | 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) { |
| | |
| | | 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); |
| | | } |
| | |
| | | } else { |
| | | primaryHandler(html, item, config); |
| | | } |
| | | |
| | | // 此处必须加,不然二次调用初始化函数的时候会将一二级区域所有的点都显示在页面上 |
| | | html.show = isVisibleDistance( |
| | | config.minVisibleDistance, |
| | | config.maxVisibleDistance |
| | | ); |
| | | |
| | | htmlEntityList.push(html); |
| | | } |
| | |
| | | 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; |
| | |
| | | }); |
| | | } |
| | | |
| | | // 路由监听 |
| | | // 在路由监听器中 |
| | | 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(); |
| | | } |
| | | } |
| | |
| | | |
| | | // 初始化函数 |
| | | function initAllDistrictCounts() { |
| | | initDistrictCount("secondary"); // 二级区域 |
| | | initDistrictCount("primary"); // 一级区域 |
| | | initDistrictCount("secondary"); // 二级区域 |
| | | } |
| | | |
| | | onMounted(() => { |