| | |
| | | inject, |
| | | reactive, |
| | | onMounted, |
| | | onUnmounted, |
| | | } from "vue"; |
| | | import { ElMessage } from "element-plus"; |
| | | import { initeWaterPrimitiveView } from "@/utils/water"; |
| | | import { SimAPIStore } from "@/store/simAPI"; |
| | | import { useSimStore } from "@/store/simulation.js"; |
| | | import { EventBus } from "@/eventBus"; // 引入事件总线 |
| | | import { getDeviceInfoShg } from "@/api/hpApi"; |
| | | import { getDeviceInfoSHG, getYLJData } from "@/api/hpApi"; |
| | | import { getSimStart, getSimDataById } from "@/api/trApi"; |
| | | |
| | | // 获取 Store 实例 |
| | | const simStore = SimAPIStore(); |
| | | const simAPIStore = SimAPIStore(); |
| | | |
| | | const simStore = useSimStore(); |
| | | |
| | | // 表单数据 |
| | | const formData = reactive({ |
| | |
| | | // 获取所有雨量计数据(来自接口) |
| | | const getRainListAll = () => { |
| | | // 雨量计类型id |
| | | const ids = "1874719366287368194"; |
| | | getDeviceInfoShg(ids).then((res) => { |
| | | const ids = "1917487171642212354"; |
| | | getDeviceInfoSHG(ids).then((res) => { |
| | | rainListNoFilter.value = res.data.pageData; |
| | | // 根据当前选择的区域自动过滤 |
| | | updateShgListByArea(); |
| | |
| | | ...device, |
| | | selected: true, // 默认选中 |
| | | })); |
| | | |
| | | console.log(shgList.value, "shgList.valueshgList.value"); |
| | | }; |
| | | |
| | | // 下拉框选中值的表格数据变化 |
| | |
| | | // 保存方案 |
| | | const saveSim = async () => { |
| | | try { |
| | | // getYLJData("1101160300070101") |
| | | updateSelectedGauges(); |
| | | formData.geom = props.selectedArea; |
| | | await simStore.addSimCheme(formData); |
| | | await simAPIStore.addSimCheme(formData); |
| | | resetForm(); |
| | | EventBus.emit("close-selectArea"); |
| | | } catch (err) {} |
| | |
| | | // 注入模拟操作方法 |
| | | const { startSimulate, endSimulate } = inject("simulateActions"); |
| | | |
| | | // 实时模拟定时器 |
| | | let pollingInterval = null; |
| | | |
| | | async function startPlay() { |
| | | const selectedItems = filteredTableData.value.filter((item) => item.selected); |
| | | if (selectedItems.length > 0) { |
| | | console.log( |
| | | "选中的项:", |
| | | selectedItems.map((item) => item.name) |
| | | ); |
| | | } else { |
| | | console.log("未选中任何项"); |
| | | } |
| | | console.log("当前选中的区域:", props.selectedArea); |
| | | // 开始模拟前需要先保存方案 |
| | | updateSelectedGauges(); |
| | | |
| | | formData.geom = props.selectedArea; |
| | | await simStore.addSimCheme(formData); |
| | | |
| | | // 保存方案 |
| | | const resApi = await simAPIStore.addSimCheme(formData); |
| | | const schemeId = resApi.data?.data?.id; |
| | | |
| | | if (!schemeId) { |
| | | ElMessage.error("方案保存失败,未获取到有效 ID"); |
| | | return; |
| | | } |
| | | |
| | | EventBus.emit("close-selectArea"); |
| | | initeWaterPrimitiveView(); |
| | | startSimulate(); |
| | | |
| | | // 显示加载中提示 |
| | | const loadingMessage = ElMessage({ |
| | | type: "info", |
| | | message: "正在启动模拟...", |
| | | duration: 0, |
| | | offset: 80, |
| | | }); |
| | | |
| | | try { |
| | | // 调用求解器并初始化模拟 |
| | | const resStart = await getSimStart(schemeId); |
| | | |
| | | // 请求完成后关闭加载提示 |
| | | loadingMessage.close(); |
| | | |
| | | if (resStart.code === 200) { |
| | | const res = await getSimDataById(schemeId); |
| | | simStore.setSelectedScheme(res.data[0]); |
| | | |
| | | simStore.layerDate = resStart.data; |
| | | initeWaterPrimitiveView(); |
| | | |
| | | try { |
| | | startSimulate(); // 这里可能会报错 |
| | | } catch (error) { |
| | | console.error("调用 startSimulate 出错:", error); |
| | | } |
| | | |
| | | // 开始轮询任务:每 5 分钟调用一次 getSimStart 并更新方案数据 |
| | | startPolling(schemeId); |
| | | } else { |
| | | ElMessage.error(resStart.message || "调用求解器失败"); |
| | | } |
| | | } catch (error) { |
| | | loadingMessage.close(); |
| | | ElMessage.error("请求失败:" + (error.message || "未知错误")); |
| | | console.error("调用 getSimStart 出错:", error); |
| | | } |
| | | } |
| | | |
| | | // 启动轮询函数 |
| | | function startPolling(schemeId) { |
| | | stopPolling(); // 避免重复启动 |
| | | |
| | | pollingInterval = setInterval(async () => { |
| | | try { |
| | | const resStart = await getSimStart(schemeId); |
| | | |
| | | if (resStart.code === 200) { |
| | | const res = await getSimDataById(schemeId); |
| | | simStore.setSelectedScheme(res.data[0]); // 更新方案数据 |
| | | simStore.layerDate = resStart.data; // 更新 layer 数据 |
| | | |
| | | console.log("轮询获取最新数据成功"); |
| | | } else { |
| | | console.warn("轮询请求失败:", resStart.message); |
| | | } |
| | | } catch (error) { |
| | | console.error("轮询请求异常:", error); |
| | | } |
| | | }, 5 * 60 * 1000); // 每 5 分钟执行一次 |
| | | } |
| | | |
| | | // 停止轮询函数 |
| | | function stopPolling() { |
| | | if (pollingInterval) { |
| | | clearInterval(pollingInterval); |
| | | pollingInterval = null; |
| | | console.log("轮询已停止"); |
| | | } |
| | | } |
| | | |
| | | EventBus.on("close-time", () => { |
| | | stopPolling(); |
| | | }); |
| | | |
| | | const toggleDetails = () => { |
| | | isCollapsed.value = !isCollapsed.value; |
| | |
| | | const futurePredictions = () => { |
| | | console.log("未来预测按钮被点击"); |
| | | }; |
| | | |
| | | onUnmounted(() => { |
| | | EventBus.off("close-time"); |
| | | stopPolling(); |
| | | }); |
| | | </script> |
| | | |
| | | <style scoped> |