| | |
| | | @click="startPlay(item)" |
| | | >进入模拟</el-button |
| | | > |
| | | <el-button size="small" v-show="item.type == 2" @click="rePlay(item)" |
| | | >历史回放</el-button |
| | | > |
| | | <!-- :disabled="item.status !== 2" --> |
| | | </div> |
| | | </div> |
| | |
| | | |
| | | <script setup> |
| | | import { EventBus } from "@/eventBus"; // 引入事件总线 |
| | | import { onMounted, ref, watch, defineEmits, onUnmounted } from "vue"; |
| | | import { |
| | | nextTick, |
| | | onMounted, |
| | | ref, |
| | | watch, |
| | | defineEmits, |
| | | onUnmounted, |
| | | inject, |
| | | } from "vue"; |
| | | import dayjs from "dayjs"; |
| | | import { initeWaterPrimitiveView } from "@/utils/water"; |
| | | import Message from "@/components/tools/Message.vue"; |
| | |
| | | import { ElMessage, ElMessageBox } from "element-plus"; |
| | | const emit = defineEmits(["start", "end", "reset", "closeBtn"]); |
| | | import { |
| | | getRegionData, |
| | | getSimData, |
| | | deleteSimData, |
| | | getSimStart, |
| | | getSimDataById, |
| | | getSimresult, |
| | | } from "@/api/trApi.js"; |
| | | |
| | | const simStore = useSimStore(); |
| | |
| | | // 实时模拟五分钟请求一次的定时器 |
| | | const realTimeSimInterval = ref(null); |
| | | |
| | | const { startSimulate, endSimulate } = inject("simulateActions"); |
| | | |
| | | async function startPlay(item) { |
| | | console.log(item, "item"); |
| | | if (item.status === 2) { |
| | | ElMessage.warning("当前方案正在分析中,无法进入模拟!"); |
| | | return; |
| | |
| | | currentScheme.value = item; |
| | | schemeInfoShow.value = true; |
| | | emit("closeBtn", false); |
| | | emit("start"); |
| | | startSimulate(); |
| | | return; |
| | | } |
| | | |
| | |
| | | return; |
| | | } |
| | | |
| | | // 处理 type == 2 的情况(实时模拟) |
| | | if (item.type === 2) { |
| | | // 清除已有定时器,防止重复启动 |
| | | if (realTimeSimInterval.value) { |
| | | clearInterval(realTimeSimInterval.value); |
| | | } |
| | | |
| | | // 即刻执行一次 |
| | | await executeRealTimeSimulation(item); |
| | | |
| | | // 每隔 5 分钟执行一次 |
| | | realTimeSimInterval.value = setInterval(() => { |
| | | executeRealTimeSimulation(item); |
| | | }, 5 * 60 * 1000); // 5分钟 |
| | | |
| | | return; |
| | | } |
| | | |
| | | // 默认情况:有服务名称 |
| | | simStore.setSelectedScheme(item); |
| | | } |
| | | |
| | | // 封装实时模拟的异步操作 |
| | | async function executeRealTimeSimulation(item) { |
| | | 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) { |
| | | simStore.layerDate = ress.data; |
| | | initeWaterPrimitiveView(); |
| | | emit("start"); |
| | | } |
| | | } catch (e) { |
| | | console.error("实时模拟获取模拟数据失败:", e); |
| | | } |
| | | // 实时模拟历史回放 |
| | | function rePlay(item) { |
| | | // 当前选中的方案 |
| | | simStore.setSelectedScheme(item); |
| | | // 拿id去请求results接口,如果长度不为0,则可以进行历史回放 |
| | | getSimresult(item.id) |
| | | .then((res) => { |
| | | if (res.code == 500) { |
| | | // 如果长度为0,提示用户并且不进行后续操作 |
| | | ElMessage.warning("提示:没有可回放的数据!"); |
| | | return; // 阻止后续操作 |
| | | } else { |
| | | simStore.rePlayList = res.data; |
| | | console.log(simStore.rePlayList, "lisi"); |
| | | } |
| | | // 使用 nextTick 确保 DOM 更新后再执行后续操作 |
| | | nextTick(() => { |
| | | initeWaterPrimitiveView(); |
| | | startSimulate(); |
| | | }); |
| | | }) |
| | | .catch((error) => { |
| | | console.log("请求失败:", error); |
| | | // 错误处理 |
| | | }); |
| | | } |
| | | |
| | | function handleBack(value) { |
| | |
| | | item.result == "创建仿真" || |
| | | item.result == "完成" || |
| | | item.result == "-1" || |
| | | item.result == null |
| | | item.result == "停止" || |
| | | item.result == "进行中" |
| | | ); |
| | | simAPIStore.shouldPoll = !shouldStop; // 修改 Pinia 状态 |
| | | console.log(shouldStop, "aaaaaaaaaaaaaaaa"); |
| | | // 3. 如果需要停止 |
| | | if (shouldStop) { |
| | | if (intervalId) { |