| | |
| | | async function startPlay(item) { |
| | | simStore.openDia = false; |
| | | clearAllPoints(); |
| | | const areaName = item.areaName; |
| | | |
| | | const areaName = item.areaName; |
| | | let districtCode; |
| | | |
| | | // 1. 判断是否包含 “区” |
| | |
| | | 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("孙胡沟")); |
| | | |
| | | // 孙胡沟设备经纬度映射 |
| | | const deviceMapping = { |
| | | 怀柔区琉璃庙镇孙胡沟椴树底下东沟泥位计5007: { |
| | | lon: 116.598891, |
| | | lat: 40.554979, |
| | | }, |
| | | 怀柔区琉璃庙镇孙胡沟村上台子河东南沟泥位计5006: { |
| | | lon: 116.593215, |
| | | lat: 40.554399, |
| | | }, |
| | | }; |
| | | |
| | | let displayedData = filteredPageData; |
| | | |
| | | if (!areaName.includes("区")) { |
| | | // 添加 lon 和 lan 字段 |
| | | displayedData = filteredPageData.map((device) => { |
| | | const mapping = deviceMapping[device.deviceName]; |
| | | return { |
| | | ...device, |
| | | ...(mapping && { lon: mapping.lon, lat: mapping.lat }), // 如果 mapping 存在,才添加 |
| | | }; |
| | | }); |
| | | |
| | | // 添加额外的两个点位 |
| | | const extraPoint1 = { |
| | | deviceName: "弯沟1", |
| | | longitude: 116.597836, |
| | | latitude: 40.564962, |
| | | // height: 530.14, |
| | | type: "泥位计", |
| | | lon: 116.597836, |
| | | lat: 40.564962, |
| | | dictDeviceType: "1437295811", |
| | | deviceId: "custom_extraPoint1", // 手动加一个唯一 ID |
| | | }; |
| | | |
| | | const extraPoint2 = { |
| | | deviceName: "弯沟2", |
| | | longitude: 116.591571, |
| | | latitude: 40.573093, |
| | | // height: 483.89, |
| | | type: "泥位计", |
| | | lon: 116.591571, |
| | | lat: 40.573093, |
| | | dictDeviceType: "1437295811", |
| | | deviceId: "custom_extraPoint2", // 手动加一个唯一 ID |
| | | }; |
| | | |
| | | displayedData = [...displayedData, extraPoint1, extraPoint2]; |
| | | // displayedData = [...displayedData, extraPoint1]; |
| | | let areaRes; |
| | | try { |
| | | areaRes = await getAeraTownCode(districtCode); |
| | | } catch (error) { |
| | | console.error("getAeraTownCode 请求失败", error); |
| | | ElMessage.warning("乡镇区域数据加载失败,部分设备可能无法显示"); |
| | | areaRes = { data: [] }; // 赋默认值,防止后续出错 |
| | | } |
| | | |
| | | console.log( |
| | | displayedData, |
| | | areaName.includes("区") |
| | | ? "全部泥位计设备列表" |
| | | : "孙胡沟泥位计 + 额外点位列表" |
| | | ); |
| | | const districtCodes = areaRes.data.map((item) => item.districtCode); |
| | | |
| | | // 7. 创建点 |
| | | |
| | | let displayedData = []; |
| | | |
| | | if (districtCodes.length == 0) { |
| | | ElMessage.warning("未获取到乡镇编码,跳过设备请求"); |
| | | } else { |
| | | const ids = "1437295811"; |
| | | |
| | | // 构建请求列表 |
| | | const requests = districtCodes.map((code) => |
| | | getDeviceNWJ(ids, code) |
| | | .then((res) => res.data?.pageData || []) |
| | | .catch((err) => { |
| | | console.error(`请求失败 (code: ${code})`, err); |
| | | return []; |
| | | }) |
| | | ); |
| | | |
| | | // 使用 Promise.allSettled 避免中断 |
| | | const results = await Promise.allSettled(requests); |
| | | |
| | | // 提取所有成功的结果 |
| | | const mergedPageData = results |
| | | .filter((result) => result.status === "fulfilled") |
| | | .flatMap((result) => result.value || []); |
| | | |
| | | // 如果不是“区”,则过滤出 deviceName 包含 "孙胡沟" 的设备 |
| | | const filteredPageData = areaName.includes("区") |
| | | ? mergedPageData |
| | | : mergedPageData.filter((device) => device.deviceName.includes("孙胡沟")); |
| | | |
| | | // 孙胡沟设备经纬度映射 |
| | | const deviceMapping = { |
| | | 怀柔区琉璃庙镇孙胡沟椴树底下东沟泥位计5007: { |
| | | lon: 116.598891, |
| | | lat: 40.554979, |
| | | }, |
| | | 怀柔区琉璃庙镇孙胡沟村上台子河东南沟泥位计5006: { |
| | | lon: 116.593215, |
| | | lat: 40.554399, |
| | | }, |
| | | }; |
| | | |
| | | displayedData = filteredPageData; |
| | | |
| | | if (!areaName.includes("区")) { |
| | | displayedData = filteredPageData.map((device) => { |
| | | const mapping = deviceMapping[device.deviceName]; |
| | | return { |
| | | ...device, |
| | | ...(mapping && { lon: mapping.lon, lat: mapping.lat }), |
| | | }; |
| | | }); |
| | | |
| | | // 添加额外的两个点位 |
| | | const extraPoint1 = { |
| | | deviceName: "弯沟1", |
| | | longitude: 116.597836, |
| | | latitude: 40.564962, |
| | | type: "泥位计", |
| | | lon: 116.597836, |
| | | lat: 40.564962, |
| | | dictDeviceType: "1437295811", |
| | | deviceId: "custom_extraPoint1", |
| | | }; |
| | | |
| | | const extraPoint2 = { |
| | | deviceName: "弯沟2", |
| | | longitude: 116.591571, |
| | | latitude: 40.573093, |
| | | type: "泥位计", |
| | | lon: 116.591571, |
| | | lat: 40.573093, |
| | | dictDeviceType: "1437295811", |
| | | deviceId: "custom_extraPoint2", |
| | | }; |
| | | |
| | | displayedData = [...displayedData, extraPoint1, extraPoint2]; |
| | | } |
| | | |
| | | console.log( |
| | | displayedData, |
| | | areaName.includes("区") |
| | | ? "全部泥位计设备列表" |
| | | : "孙胡沟泥位计 + 额外点位列表" |
| | | ); |
| | | } |
| | | |
| | | // 创建点(即使 displayedData 为空也不会报错) |
| | | displayedData.forEach((item) => { |
| | | // 根据需求可增删 |
| | | item.type = getDictName(deviceDictList, item.dictDeviceType); |
| | | item.name = item.deviceName; |
| | | item.id = item.deviceId; |
| | |
| | | createPoint(item); |
| | | }); |
| | | |
| | | // 后续模拟流程继续执行,不受影响 |
| | | if (item.status === 2) { |
| | | ElMessage.warning("当前方案正在分析中,无法进入模拟!"); |
| | | return; |
| | |
| | | return; |
| | | } |
| | | |
| | | // 如果是已完成的方案(status == 10) |
| | | if (item.status === 10) { |
| | | const flyHeight = item.areaType === 1 ? 100000 : 50000; |
| | | simStore.setSelectedScheme(item); |
| | |
| | | return; |
| | | } |
| | | |
| | | // 新建方案,没有 status 和 serviceName 且 type != 2 |
| | | if (!item.status && !item.serviceName && item.type !== 2) { |
| | | try { |
| | | await getSimStart(item.id); |
| | |
| | | return; |
| | | } |
| | | |
| | | // 默认情况:有服务名称 |
| | | simStore.setSelectedScheme(item); |
| | | } |
| | | |