2
wangjuncheng
2025-06-25 fa541dda36e58de1d491b3ff4073c51b16606515
src/components/monifangzhen/schemeCard.vue
@@ -74,7 +74,6 @@
  selectedId.value = id;
}
function formatTime(time) {
  return dayjs(time).format("YYYY-MM-DD HH:mm:ss");
}
@@ -93,6 +92,9 @@
function close() {
  messageShow.value = false;
}
// 实时模拟五分钟请求一次的定时器
const realTimeSimInterval = ref(null);
async function startPlay(item) {
  if (item.status === 2) {
@@ -127,7 +129,7 @@
    return;
  }
  // 调用求解器(不在实时模拟的情况下)
  // 新建方案,没有 status 和 serviceName 且 type != 2
  if (!item.status && !item.serviceName && item.type !== 2) {
    try {
      await getSimStart(item.id);
@@ -143,23 +145,21 @@
    return;
  }
  // 实时模拟
  // 处理 type == 2 的情况(实时模拟)
  if (item.type === 2) {
    try {
      // 实时模拟调用求解器会直接在接口中返回结果
      const ress = await getSimStart(item.id);
      const res = await getSimDataById(item.id);
      item.serviceName = res.data[0]?.serviceName || null;
      simStore.setSelectedScheme(item);
      getScheme();
      if (ress.code === 200) {
        initeWaterPrimitiveView();
        emit("start");
      }
    } catch (e) {
      console.error("实时模拟获取模拟数据失败:", e);
    // 清除已有定时器,防止重复启动
    if (realTimeSimInterval.value) {
      clearInterval(realTimeSimInterval.value);
    }
    // 即刻执行一次
    await executeRealTimeSimulation(item);
    // 每隔 5 分钟执行一次
    realTimeSimInterval.value = setInterval(() => {
      executeRealTimeSimulation(item);
    }, 5 * 60 * 1000); // 5分钟
    return;
  }
@@ -167,7 +167,28 @@
  simStore.setSelectedScheme(item);
}
// 封装实时模拟的异步操作
async function executeRealTimeSimulation(item) {
  try {
    const ress = await getSimStart(item.id);
    console.log(ress, "resssssssss");
    const res = await getSimDataById(item.id);
    item.serviceName = res.data[0]?.serviceName || null;
    simStore.setSelectedScheme(item);
    getScheme();
    if (ress.code === 200) {
      simStore.layerDate = ress.data;
      console.log(simStore.layerDate,'aaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbb')
      initeWaterPrimitiveView();
      emit("start");
    }
  } catch (e) {
    console.error("实时模拟获取模拟数据失败:", e);
  }
}
function handleBack(value) {
  if (value === false) {