guonan
6 天以前 a57caa72a54efe9de3fe26a6c36d3e8038267377
src/components/monifangzhen/schemeCard.vue
@@ -79,6 +79,10 @@
  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
@@ -114,7 +118,144 @@
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("孙胡沟"));
  // 孙胡沟设备经纬度映射
  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];
  }
  console.log(
    displayedData,
    areaName.includes("区")
      ? "全部泥位计设备列表"
      : "孙胡沟泥位计 + 额外点位列表"
  );
  // 7. 创建点
  displayedData.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;
@@ -180,7 +321,7 @@
        return; // 阻止后续操作
      } else {
        simStore.rePlayList = res.data;
        console.log(simStore.rePlayList, "lisi");
        console.log(simStore.rePlayList, "实时模拟历史回放列表");
      }
      // 使用 nextTick 确保 DOM 更新后再执行后续操作
      nextTick(() => {
@@ -221,7 +362,7 @@
        item.result == "创建仿真" ||
        item.result == "完成" ||
        item.result == "-1" ||
        item.result == "停止" ||
        item.result == "已停止" ||
        item.result == "运行中"
    );
    simAPIStore.shouldPoll = !shouldStop; // 修改 Pinia 状态