| | |
| | | import { useSimStore } from "@/store/simulation"; |
| | | import { storeToRefs } from "pinia"; |
| | | const simStore = useSimStore(); |
| | | const { selectedScheme, frameNum, layerDate } = storeToRefs(simStore); |
| | | const { selectedScheme, frameNum, layerDate, schemWaterInfo } = |
| | | storeToRefs(simStore); |
| | | import { clearAllPoints } from "@/utils/map"; |
| | | |
| | | const emit = defineEmits([ |
| | | "timeUpdate", |
| | |
| | | |
| | | // 新建方案中的实时模拟不能倍速 |
| | | if (selectedScheme.value.type === 2 && simStore.rePlayList.length == 0) { |
| | | // 类型为 2:每 5 秒跳动一次 |
| | | console.log("新建方案实时模拟五秒一跳"); |
| | | // 实时模拟:每 5 秒跳动一次 |
| | | playInterval = setInterval(() => { |
| | | const fiveSeconds = 5; |
| | | const totalDuration = duration.value; // 总时长(秒) |
| | |
| | | } |
| | | |
| | | // 触发进度更新 |
| | | const progress = currentTime.value / totalDuration; |
| | | emit("timeUpdate", progress * 100); |
| | | // const progress = currentTime.value / totalDuration; |
| | | // 实时模拟应该不用显示弹窗吧 |
| | | // emit("timeUpdate", progress * 100); |
| | | |
| | | // 如果需要触发某些更新函数,也可以保留 |
| | | updateWaterColorByTime(); |
| | |
| | | currentTime.value = duration.value; |
| | | stopPlayback(); |
| | | isPlaying.value = false; |
| | | finishPlay.value = true; |
| | | emit("isPlaying", false); |
| | | emit("playbackFinished", true); |
| | | return; |
| | |
| | | } |
| | | |
| | | const progress = currentTime.value / duration.value; |
| | | emit("timeUpdate", progress * 100); |
| | | if (selectedScheme.value.type !== 2) { |
| | | emit("timeUpdate", progress * 100); |
| | | } |
| | | }, 1000 / playbackRate.value); |
| | | } |
| | | }; |
| | |
| | | // 降雨数据相关变量 |
| | | let rainFallValues = ref([]); // 存储原始降雨量数据 |
| | | let minRainValue = ref(Infinity); |
| | | let averageRainIntensity = ref(); |
| | | let maxRainValue = ref(-Infinity); |
| | | // 获取降雨数据 |
| | | function getRainfallData() { |
| | |
| | | |
| | | // 提取 intensity 值 |
| | | rainFallValues.value = hourlyRainfallList.map((r) => r.intensity); |
| | | // 计算平均雨强 |
| | | if (rainFallValues.value.length > 0) { |
| | | const sumIntensity = rainFallValues.value.reduce( |
| | | (sum, val) => sum + val, |
| | | 0 |
| | | ); |
| | | averageRainIntensity.value = sumIntensity / rainFallValues.value.length; |
| | | } else { |
| | | averageRainIntensity.value = 0; // 或者 null 表示无数据 |
| | | } |
| | | |
| | | console.log("平均雨强为:", averageRainIntensity.value); |
| | | |
| | | minRainValue.value = Math.min(...rainFallValues.value); |
| | | maxRainValue.value = Math.max(...rainFallValues.value); |
| | | |
| | |
| | | // 打印信息 |
| | | // console.log("========================================"); |
| | | // console.log(`【时间戳】: ${new Date(currentTimeMs).toLocaleString()}`); |
| | | // console.log(`【累计降雨量 R】: ${currentTotal !== null ? currentTotal.toFixed(2) : '未知'} mm`); |
| | | console.log( |
| | | `【累计降雨量 R】: ${ |
| | | currentTotal !== null ? currentTotal.toFixed(2) : "未知" |
| | | } mm` |
| | | ); |
| | | // console.log(`【当前阶段】: 第 ${currentStage} 阶段`); |
| | | // console.log(`【颜色 HEX】: ${colorState.colorStages[currentStage]?.color || '未定义'}`); |
| | | console.log( |
| | | `【颜色 HEX】: ${colorState.colorStages[currentStage]?.color || "未定义"}` |
| | | ); |
| | | // console.log(`【透明度 Alpha】: ${colorState.colorStages[currentStage]?.alpha || '未定义'}`); |
| | | // console.log("========================================"); |
| | | // 应用颜色 |
| | |
| | | rainDensity: rainLevel.density, |
| | | rainColor: rainLevel.color, |
| | | }; |
| | | // console.log("当前雨量数据:", rainValue, "当前雨形:", rainLevel); |
| | | console.log("当前雨量数据:", rainValue, "当前雨形:", rainLevel); |
| | | // 调用工具方法更新雨效 |
| | | mapUtils.toggleRain(rainParams, true); |
| | | } |
| | |
| | | watersMaxHeight, |
| | | watersMinHeight |
| | | ); |
| | | |
| | | const waterInfoArr = [ |
| | | watersMaxHeight, |
| | | maxRainValue.value, |
| | | averageRainIntensity.value, |
| | | ]; |
| | | schemWaterInfo.value = waterInfoArr; |
| | | // 更新时间轴相关数据 |
| | | if (timestamps) { |
| | | frameNum.value = timestamps.length; |
| | |
| | | }); |
| | | } |
| | | } |
| | | |
| | | // 播放完成后的回调 |
| | | function handlePlayFinished() { |
| | | if (selectedScheme.value.type !== 2) return; |
| | |
| | | currentReplayIndex.value++; |
| | | |
| | | if (currentReplayIndex.value < simStore.rePlayList.length) { |
| | | console.log(currentReplayIndex.value); |
| | | |
| | | // 自动播放下一个 |
| | | initializeSimulationData(simStore.rePlayList[currentReplayIndex.value]); |
| | | togglePlay(); |
| | |
| | | // 所有项目播放完成 |
| | | currentReplayIndex.value = 0; // 重置索引 |
| | | isPlaying.value = false; // 停止播放 |
| | | emit("timeUpdate", 100); // 在所有项目播放完毕后触发 |
| | | } |
| | | } |
| | | |
| | |
| | | watch( |
| | | () => finishPlay.value, |
| | | (newVal) => { |
| | | if (newVal && selectedScheme.value.type === 2) { |
| | | if ( |
| | | newVal && |
| | | selectedScheme.value.type === 2 && |
| | | simStore.rePlayList.length > 0 |
| | | ) { |
| | | handlePlayFinished(); |
| | | } |
| | | } |
| | |
| | | if (selectedScheme.value.type === 2) { |
| | | try { |
| | | await ElMessageBox.confirm("方案未停止时结束模拟后,后台将停止计算", { |
| | | confirmButtonText: "返回列表", |
| | | cancelButtonText: "结束模拟", |
| | | confirmButtonText: "结束模拟", |
| | | cancelButtonText: "返回列表", |
| | | type: "warning", |
| | | }); |
| | | // 用户点击了确认,这里不执行任何操作,仅关闭对话框 |
| | | |
| | | const res = await stopSim(selectedScheme.value.id); |
| | | if (res.code == 404) { |
| | | ElMessage.warning("该服务已停止"); |
| | | } else { |
| | | ElMessage.success("服务正在停止中"); |
| | | } |
| | | } catch (error) { |
| | | stopSim(selectedScheme.value.id).then((res) => { |
| | | if (res.code == 404) { |
| | | ElMessage.warning("该服务已停止"); |
| | | } else { |
| | | ElMessage.success("服务正在停止中"); |
| | | } |
| | | }); |
| | | // 用户点击了【返回列表】或者出现错误 |
| | | // return; |
| | | } |
| | | } |
| | | // 不管type是不是2,最终都执行结束模拟的操作 |
| | | |
| | | // 不管 type 是不是 2,最终都执行结束模拟操作 |
| | | endSimulation(); |
| | | } |
| | | |
| | | async function endSimulation() { |
| | | clearAllPoints(); |
| | | simStore.openDia = true; |
| | | simStore.crossSection = []; |
| | | // 结束模拟之后清除layer列表 |
| | | simStore.rePlayList = []; |
| | | EventBus.emit("close-time"); |
| | | endSimulate(); |
| | | isWaterPrimitiveCreated.value = false; |