| | |
| | | <div class="timeline-container"> |
| | | <div class="controls"> |
| | | <div class="control-btn" @click="skipBackward"> |
| | | <img src="@/assets/img/timeline/left.png" class="fas fa-step-backward" /> |
| | | <img |
| | | src="@/assets/img/timeline/left.png" |
| | | class="fas fa-step-backward" |
| | | /> |
| | | </div> |
| | | <div class="control-btn play-btn" @click="togglePlay"> |
| | | <img v-show="isPlaying" src="@/assets/img/timeline/stop.png" /> |
| | | <img v-show="!isPlaying" src="@/assets/img/timeline/start.png" /> |
| | | </div> |
| | | <div class="control-btn" @click="skipForward"> |
| | | <img src="@/assets/img/timeline/right.png" class="fas fa-step-forward" /> |
| | | <img |
| | | src="@/assets/img/timeline/right.png" |
| | | class="fas fa-step-forward" |
| | | /> |
| | | </div> |
| | | <div class="speed-control" v-show="speedShow"> |
| | | <div @click="toggleSpeedMenu">{{ playbackRate }}X</div> |
| | | <div class="speed-menu" v-show="showSpeedMenu"> |
| | | <div v-for="rate in playbackRates" :key="rate" @click.capture="setPlaybackRate(rate)" |
| | | :class="{ active: playbackRate === rate }"> |
| | | <div |
| | | v-for="rate in playbackRates" |
| | | :key="rate" |
| | | @click.capture="setPlaybackRate(rate)" |
| | | :class="{ active: playbackRate === rate }" |
| | | > |
| | | {{ rate }}X |
| | | </div> |
| | | </div> |
| | |
| | | <div class="timeline"> |
| | | <div class="dates"> |
| | | <div class="current-date">当前播放时间:{{ currentPlayingTime }}</div> |
| | | <div v-for="(date, index) in visibleDates" :key="index" class="date-label"> |
| | | <div |
| | | v-for="(date, index) in visibleDates" |
| | | :key="index" |
| | | class="date-label" |
| | | > |
| | | <!-- {{ formatDate(date) }} --> |
| | | </div> |
| | | <div> |
| | | 专题渲染: |
| | | <el-switch v-model="isColorRenderEnabled" @change="handleColorRenderChange" style="margin-top: -3px" |
| | | :disabled="!isPlaying || !isWaterPrimitiveCreated" /> |
| | | <el-switch |
| | | v-model="isColorRenderEnabled" |
| | | @change="handleColorRenderChange" |
| | | style="margin-top: -3px" |
| | | :disabled="!isPlaying || !isWaterPrimitiveCreated" |
| | | /> |
| | | <!-- active-text="开" inactive-text="关" --> |
| | | </div> |
| | | </div> |
| | | <div class="timeline-track" ref="timelineTrack" @click="seekToPosition"> |
| | | <div class="timeline-progress" :style="{ width: progressPercentage + '%' }"></div> |
| | | <div class="timeline-cursor" :style="{ left: progressPercentage + '%' }"></div> |
| | | <div |
| | | class="timeline-progress" |
| | | :style="{ width: progressPercentage + '%' }" |
| | | ></div> |
| | | <div |
| | | class="timeline-cursor" |
| | | :style="{ left: progressPercentage + '%' }" |
| | | ></div> |
| | | <div class="scale-markers"> |
| | | <div class="scale-marker" style="left: 0%"></div> |
| | | <div class="scale-marker" style="left: 25%"></div> |
| | |
| | | <div class="scale-marker" style="left: 100%"></div> |
| | | </div> |
| | | <div class="time-markers"> |
| | | <div v-for="(time, index) in timeMarkers" :key="index" class="time-marker" |
| | | :style="{ left: `${index * 25}%`, transform: 'translateX(-50%)' }"> |
| | | <div |
| | | v-for="(time, index) in timeMarkers" |
| | | :key="index" |
| | | class="time-marker" |
| | | :style="{ left: `${index * 25}%`, transform: 'translateX(-50%)' }" |
| | | > |
| | | <div class="date-part">{{ time.split(" ")[0] }}</div> |
| | | <div class="time-part">{{ time.split(" ")[1] }}</div> |
| | | </div> |
| | |
| | | </div> |
| | | <div> |
| | | <div style="display: flex"> |
| | | <ratelevel ref="ratelevelRef" :playing-time="sendCurrentPlayingTime" |
| | | @finish-calculation="handleFinishCalculation" style=" |
| | | <ratelevel |
| | | ref="ratelevelRef" |
| | | :playing-time="sendCurrentPlayingTime" |
| | | @finish-calculation="handleFinishCalculation" |
| | | style=" |
| | | margin-top: 12px; |
| | | margin-left: 28px; |
| | | margin-right: 10px; |
| | | justify-content: flex-end; |
| | | " /> |
| | | <crossanalysis ref="crossRef" style=" |
| | | " |
| | | /> |
| | | <crossanalysis |
| | | ref="crossRef" |
| | | style=" |
| | | margin-top: 12px; |
| | | margin-left: 16px; |
| | | margin-right: 20px; |
| | | justify-content: flex-end; |
| | | " /> |
| | | " |
| | | /> |
| | | </div> |
| | | <el-button @click="handleBack" style=" |
| | | <el-button |
| | | @click="handleBack" |
| | | style=" |
| | | margin-top: 3px; |
| | | margin-left: 28px; |
| | | margin-right: 10px; |
| | | width: 75%; |
| | | height: 30%; |
| | | ">结束模拟</el-button> |
| | | " |
| | | >结束模拟</el-button |
| | | > |
| | | </div> |
| | | </div> |
| | | </template> |
| | |
| | | updateWaterColor, |
| | | } from "@/utils/water"; |
| | | import mapUtils from "@/utils/tools.js"; |
| | | import { fetchWaterSimulationData } from "@/api/trApi.js"; |
| | | import { fetchWaterSimulationData, stopSim } from "@/api/trApi.js"; |
| | | import { EventBus } from "@/eventBus"; |
| | | import { ElMessage } from "element-plus"; |
| | | import { ElMessage, ElMessageBox } from "element-plus"; |
| | | // 状态管理器 |
| | | 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", |
| | |
| | | const startPlayback = () => { |
| | | clearInterval(playInterval); |
| | | |
| | | if (selectedScheme.value.type === 2) { |
| | | // 类型为 2:每 5 秒跳动一次 |
| | | // 新建方案中的实时模拟不能倍速 |
| | | if (selectedScheme.value.type === 2 && simStore.rePlayList.length == 0) { |
| | | 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); |
| | | |
| | |
| | | // 全局状态记录 |
| | | const colorState = { |
| | | currentColor: "#F5F0E6", // 当前颜色 |
| | | currentAlpha: -0.3, // 当前透明度 |
| | | colorStages: null, // 预计算的颜色阶段时间点 |
| | | maxColorTime: null // 记录达到最深颜色时的时间点 |
| | | currentAlpha: -0.3, // 当前透明度 |
| | | colorStages: null, // 预计算的颜色阶段时间点 |
| | | maxColorTime: null, // 记录达到最深颜色时的时间点 |
| | | }; |
| | | |
| | | // 预计算颜色阶段时间点 |
| | |
| | | { hex: "#D4B483", luminance: 184.0 }, // stage 2 |
| | | { hex: "#B78B6A", luminance: 148.4 }, // stage 3 |
| | | { hex: "#8B5A3A", luminance: 101.0 }, // stage 4 |
| | | { hex: "#744C33", luminance: 84.5 }, // stage 5 |
| | | { hex: "#5D3D2C", luminance: 68.1 } // stage 6 |
| | | { hex: "#744C33", luminance: 84.5 }, // stage 5 |
| | | { hex: "#5D3D2C", luminance: 68.1 }, // stage 6 |
| | | ]; |
| | | const alphaStops = [ |
| | | -0.2, // stage 0 |
| | | -0.3, // stage 1 |
| | | -0.4, // stage 2 |
| | | -0.5, // stage 3 |
| | | -0.6, // stage 4 |
| | | -0.7, // stage 5 |
| | | -0.8 // stage 6 |
| | | -0.2, // stage 0 |
| | | -0.3, // stage 1 |
| | | -0.4, // stage 2 |
| | | -0.5, // stage 3 |
| | | -0.6, // stage 4 |
| | | -0.7, // stage 5 |
| | | -0.8, // stage 6 |
| | | ]; |
| | | // 累计降雨量阈值(mm) |
| | | const R_THRESHOLDS = [0, 200, 240, 280, 310, 350]; // 共6个阶段对应6个阈值 |
| | |
| | | const total = rainTotalInfo.value[i].total; // 使用 total 替代 intensity |
| | | timeTotals.push({ |
| | | time, |
| | | total |
| | | total, |
| | | }); |
| | | } |
| | | |
| | |
| | | startTime: time, |
| | | color: COLOR_STOPS[stage].hex, |
| | | alpha: alphaStops[stage], |
| | | threshold |
| | | threshold, |
| | | }; |
| | | break; |
| | | } |
| | |
| | | startTime: 0, |
| | | color: COLOR_STOPS[0].hex, |
| | | alpha: alphaStops[0], |
| | | threshold: 0 |
| | | threshold: 0, |
| | | }; |
| | | |
| | | colorState.colorStages = stages; |
| | |
| | | // 查找当前时间点所属的阶段 |
| | | let currentStage = 0; |
| | | for (let i = colorState.colorStages.length - 1; i >= 0; i--) { |
| | | if (colorState.colorStages[i] && currentTime.value >= colorState.colorStages[i].startTime) { |
| | | if ( |
| | | colorState.colorStages[i] && |
| | | currentTime.value >= colorState.colorStages[i].startTime |
| | | ) { |
| | | currentStage = i; |
| | | break; |
| | | } |
| | |
| | | |
| | | // 记录达到最深颜色的时间点 |
| | | if (currentStage >= colorState.colorStages.length - 1) { |
| | | if (colorState.maxColorTime === null || currentTime.value > colorState.maxColorTime) { |
| | | if ( |
| | | colorState.maxColorTime === null || |
| | | currentTime.value > colorState.maxColorTime |
| | | ) { |
| | | colorState.maxColorTime = currentTime.value; |
| | | } |
| | | } |
| | | |
| | | // 判断是否需要强制更新颜色 |
| | | const isTimeGoingBackward = currentTime.value < colorState.lastTime; |
| | | const isBeforeMaxColorTime = colorState.maxColorTime !== null && currentTime.value <= colorState.maxColorTime; |
| | | const shouldForceUpdate = isForceUpdate && (isTimeGoingBackward || isBeforeMaxColorTime); |
| | | const isBeforeMaxColorTime = |
| | | colorState.maxColorTime !== null && |
| | | currentTime.value <= colorState.maxColorTime; |
| | | const shouldForceUpdate = |
| | | isForceUpdate && (isTimeGoingBackward || isBeforeMaxColorTime); |
| | | |
| | | // 更新颜色逻辑 |
| | | if (shouldForceUpdate || isTimeGoingBackward) { |
| | |
| | | const newAlpha = colorState.colorStages[currentStage].alpha; |
| | | |
| | | // 只应用更暗的颜色和更低的透明度 |
| | | if (calculateLuminance(newColor) < calculateLuminance(colorState.currentColor)) { |
| | | if ( |
| | | calculateLuminance(newColor) < calculateLuminance(colorState.currentColor) |
| | | ) { |
| | | colorState.currentColor = newColor; |
| | | } |
| | | if (newAlpha < colorState.currentAlpha) { |
| | |
| | | // 打印信息 |
| | | // 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("========================================"); |
| | | // 应用颜色 |
| | |
| | | |
| | | // 判断是否需要强制更新颜色 |
| | | const isGoingBackward = newTime < currentTime.value; |
| | | const isBeforeMaxColor = colorState.maxColorTime !== null && newTime <= colorState.maxColorTime; |
| | | const isBeforeMaxColor = |
| | | colorState.maxColorTime !== null && newTime <= colorState.maxColorTime; |
| | | const shouldForceUpdate = isGoingBackward || isBeforeMaxColor; |
| | | |
| | | currentTime.value = newTime; |
| | |
| | | rainDensity: rainLevel.density, |
| | | rainColor: rainLevel.color, |
| | | }; |
| | | // console.log("当前雨量数据:", rainValue, "当前雨形:", rainLevel); |
| | | console.log("当前雨量数据:", rainValue, "当前雨形:", rainLevel); |
| | | // 调用工具方法更新雨效 |
| | | mapUtils.toggleRain(rainParams, true); |
| | | } |
| | |
| | | ); |
| | | |
| | | const jsonFetch = ref(null); |
| | | |
| | | const currentReplayIndex = ref(0); // 当前播放的rePlayList索引 |
| | | // 提取为独立函数 |
| | | async function initializeSimulationData(force = false) { |
| | | async function initializeSimulationData(replayItem = null) { |
| | | try { |
| | | const schemeInfo = selectedScheme.value; |
| | | serviceInfo = schemeInfo.serviceName; |
| | | |
| | | if (schemeInfo.type == 2) { |
| | | speedShow.value = false; |
| | | jsonFetch.value = layerDate.value; |
| | | if ( |
| | | replayItem || |
| | | (simStore.rePlayList && simStore.rePlayList.length != 0) |
| | | ) { |
| | | jsonFetch.value = |
| | | replayItem || simStore.rePlayList[currentReplayIndex.value]; |
| | | speedShow.value = true; |
| | | } else { |
| | | jsonFetch.value = layerDate.value; |
| | | speedShow.value = false; |
| | | } |
| | | } else { |
| | | getRainfallData(); |
| | | speedShow.value = 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; |
| | | finishPlay.value = false; |
| | | currentReplayIndex.value++; |
| | | |
| | | // 挂载时调用 |
| | | onMounted(async () => { |
| | | // 因为这个函数实时模拟监听也需要使用,所以封装了一个函数 |
| | | await initializeSimulationData(); |
| | | }); |
| | | if (currentReplayIndex.value < simStore.rePlayList.length) { |
| | | // 自动播放下一个 |
| | | initializeSimulationData(simStore.rePlayList[currentReplayIndex.value]); |
| | | togglePlay(); |
| | | shouldAutoPlay.value = false; |
| | | } else { |
| | | // 所有项目播放完成 |
| | | currentReplayIndex.value = 0; // 重置索引 |
| | | isPlaying.value = false; // 停止播放 |
| | | emit("timeUpdate", 100); // 在所有项目播放完毕后触发 |
| | | } |
| | | } |
| | | |
| | | // 监听播放完成事件 |
| | | watch( |
| | | () => finishPlay.value, |
| | | (newVal) => { |
| | | if ( |
| | | newVal && |
| | | selectedScheme.value.type === 2 && |
| | | simStore.rePlayList.length > 0 |
| | | ) { |
| | | handlePlayFinished(); |
| | | } |
| | | } |
| | | ); |
| | | |
| | | const shouldAutoPlay = ref(false); |
| | | // 监听 layerDate 变化后标记准备播放 |
| | | watch( |
| | |
| | | shouldAutoPlay.value = false; |
| | | } |
| | | }); |
| | | |
| | | // 挂载时调用 |
| | | onMounted(async () => { |
| | | // 因为这个函数实时模拟监听也需要使用,所以封装了一个函数 |
| | | await initializeSimulationData(); |
| | | }); |
| | | |
| | | // 根据返回数据的个数去渲染时间轴 |
| | | function updateTimelineRange() { |
| | | if (waterTimestamps.value.length > 0) { |
| | |
| | | }); |
| | | |
| | | const { endSimulate } = inject("simulateActions"); |
| | | function handleBack() { |
| | | endSimulate(); |
| | | // 停止实时模拟定时器 |
| | | EventBus.emit("close-time"); |
| | | |
| | | async function handleBack() { |
| | | // 实时模拟弹窗确认是返回方案列表还是停止模拟 |
| | | if (selectedScheme.value.type === 2) { |
| | | try { |
| | | await ElMessageBox.confirm("方案未停止时结束模拟后,后台将停止计算", { |
| | | confirmButtonText: "结束模拟", |
| | | cancelButtonText: "返回列表", |
| | | type: "warning", |
| | | }); |
| | | |
| | | const res = await stopSim(selectedScheme.value.id); |
| | | if (res.code == 404) { |
| | | ElMessage.warning("该服务已停止"); |
| | | } else { |
| | | ElMessage.success("服务正在停止中"); |
| | | } |
| | | } catch (error) { |
| | | // 用户点击了【返回列表】或者出现错误 |
| | | // return; |
| | | } |
| | | } |
| | | |
| | | // 不管 type 是不是 2,最终都执行结束模拟操作 |
| | | endSimulation(); |
| | | } |
| | | |
| | | async function endSimulation() { |
| | | clearAllPoints(); |
| | | simStore.openDia = true; |
| | | simStore.crossSection = []; |
| | | // 结束模拟之后清除layer列表 |
| | | simStore.rePlayList = []; |
| | | EventBus.emit("close-time"); |
| | | endSimulate(); |
| | | isWaterPrimitiveCreated.value = false; |
| | | |
| | | // 结束计算和停止拾取 |
| | | if (ratelevelRef.value) { |
| | | ratelevelRef.value.endCalculation(); |
| | | ratelevelRef.value.stopPicking(); |
| | | } |
| | | |
| | | // 清除点 |
| | | if (crossRef.value) { |
| | | crossRef.value.clearPoints(); |
| | | console.log("执行删除点功能"); |
| | | } |
| | | |
| | | emit("isColorRender", false); |
| | | |
| | | // 延迟删除雨量图层 |
| | | setTimeout(() => { |
| | | mapUtils.delRain(); |
| | | }, 3000); |
| | | |
| | | destoryWaterPrimitive(); |
| | | |
| | | // 发送事件隐藏相关信息 |
| | | EventBus.emit("hide-schemeInfo"); |
| | | EventBus.emit("clear-water-depth"); |
| | | EventBus.emit("clear-water-velocity"); |
| | | |
| | | ElMessage({ message: "模拟进程正在关闭中...", type: "success" }); |
| | | } |
| | | </script> |