| | |
| | | getSimresult, |
| | | } from "@/api/trApi.js"; |
| | | |
| | | import { getAeraTownCode, getDeviceNWJ } from "@/api/hpApi"; |
| | | import { createPoint, removeEntities, clearAllPoints } from "@/utils/map"; |
| | | import { deviceDictList, getDictName } from "@/constant/dict.js"; |
| | | |
| | | const simStore = useSimStore(); |
| | | const simAPIStore = SimAPIStore(); |
| | | // 选中的方案 ID |
| | |
| | | |
| | | const { startSimulate, endSimulate } = inject("simulateActions"); |
| | | |
| | | const BJCode = ref([ |
| | | { label: "密云区", value: "110118000000" }, |
| | | { label: "房山区", value: "110111000000" }, |
| | | { label: "门头沟区", value: "110109000000" }, |
| | | { label: "延庆区", value: "110119000000" }, |
| | | { label: "怀柔区", value: "110116000000" }, |
| | | { label: "昌平区", value: "110114000000" }, |
| | | { label: "平谷区", value: "110117000000" }, |
| | | { label: "海淀区", value: "110108000000" }, |
| | | { label: "石景山区", value: "110107000000" }, |
| | | { label: "丰台区", value: "110106000000" }, |
| | | ]); |
| | | |
| | | async function startPlay(item) { |
| | | simStore.openDia = false; |
| | | clearAllPoints(); |
| | | const areaName = item.areaName; |
| | | |
| | | let districtCode; |
| | | |
| | | // 1. 判断是否包含 “区” |
| | | if (!areaName.includes("区")) { |
| | | console.log( |
| | | `方案中模拟【${areaName}】不包含“区”,使用默认编码:怀柔区(110116000000)` |
| | | ); |
| | | districtCode = "110116000000"; // 手动指定为怀柔区编码 |
| | | } else { |
| | | // 2. 在 BJCode 中查找匹配的区域 value |
| | | const matchedArea = BJCode.value.find((area) => area.label === areaName); |
| | | |
| | | if (!matchedArea) { |
| | | console.warn(`未找到 ${areaName} 对应的区域编码`); |
| | | return; |
| | | } |
| | | |
| | | districtCode = matchedArea.value; |
| | | } |
| | | |
| | | // 1. 获取乡镇区域编码 |
| | | const areaRes = await getAeraTownCode(districtCode); |
| | | const districtCodes = areaRes.data.map((item) => item.districtCode); |
| | | |
| | | // 2. 泥位计类型ID |
| | | const ids = "1437295811"; |
| | | |
| | | // 3. 并行请求所有设备数据 |
| | | const requests = districtCodes.map((code) => |
| | | getDeviceNWJ(ids, code) |
| | | .then((res) => res.data?.pageData || []) // 安全提取 pageData |
| | | .catch((err) => { |
| | | console.error(`请求失败 (code: ${code})`, err); |
| | | return []; // 出错时也返回空数组,避免 Promise.all 中断 |
| | | }) |
| | | ); |
| | | |
| | | // 4. 等待所有请求完成 |
| | | const allPageDataArrays = await Promise.all(requests); |
| | | |
| | | // 5. 合并二维数组为一维数组 |
| | | const mergedPageData = allPageDataArrays.flat(); |
| | | |
| | | // 6. 如果不是“区”,则过滤出 deviceName 包含 "孙胡沟" 的设备 |
| | | const filteredPageData = areaName.includes("区") |
| | | ? mergedPageData |
| | | : mergedPageData.filter((device) => device.deviceName.includes("孙胡沟")); |
| | | |
| | | console.log( |
| | | filteredPageData, |
| | | areaName.includes("区") ? "全部泥位计设备列表" : "孙胡沟泥位计设备列表" |
| | | ); |
| | | |
| | | // 7. 创建点 |
| | | filteredPageData.forEach((item) => { |
| | | // 根据需求可增删 |
| | | item.type = getDictName(deviceDictList, item.dictDeviceType); |
| | | item.name = item.deviceName; |
| | | item.id = item.deviceId; |
| | | item.className = "device"; |
| | | item.showLabel = true; |
| | | |
| | | createPoint(item); |
| | | }); |
| | | |
| | | if (item.status === 2) { |
| | | ElMessage.warning("当前方案正在分析中,无法进入模拟!"); |
| | | return; |