| | |
| | | <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> |
| | |
| | | onBeforeUnmount, |
| | | inject, |
| | | reactive, |
| | | watchEffect, |
| | | } from "vue"; |
| | | import ratelevel from "@/components/menu/flowRate_waterLevel.vue"; |
| | | import crossanalysis from "@/components/menu/CrossSectionalAnalysis.vue"; |
| | |
| | | new Set(waterTimestamps.value.map((ts) => dayjs(ts).format("YYYY-MM-DD"))) |
| | | ).map((date) => dayjs(date).toDate()) |
| | | ); |
| | | |
| | | // 我需要加一个判断 |
| | | const finishPlay = ref(false); |
| | | // 播放控制 |
| | | const togglePlay = () => { |
| | | // 这里应该再设定几个限制,如果缺少什么数据,无法进行仿真 |
| | |
| | | 8: 125, // 8倍速 |
| | | }; |
| | | // 播放逻辑 |
| | | // const startPlayback = () => { |
| | | // clearInterval(playInterval); |
| | | |
| | | // playInterval = setInterval(() => { |
| | | // // 找到当前时间对应的索引 |
| | | // const currentIndex = findClosestTimestampIndex(currentTime.value); |
| | | // const nextIndex = currentIndex + 1; |
| | | |
| | | // // 如果已经是最后一个时间点,停止播放 |
| | | // if (nextIndex >= waterTimestamps.value.length) { |
| | | // currentTime.value = duration.value; |
| | | // stopPlayback(); |
| | | // isPlaying.value = false; |
| | | // emit("isPlaying", false); |
| | | // emit("playbackFinished", true); |
| | | // return; |
| | | // } |
| | | |
| | | // // 更新时间为下一个时间点的时间差(秒) |
| | | // const nextTimestamp = waterTimestamps.value[nextIndex]; |
| | | // const baseTimestamp = waterTimestamps.value[0]; |
| | | // currentTime.value = (nextTimestamp - baseTimestamp) / 1000; |
| | | |
| | | // // 触发更新 |
| | | // if (selectedScheme.value.type !== 2) { |
| | | // updateWaterColorByTime(); |
| | | // updateWeatherByProgress(); |
| | | // } |
| | | |
| | | // const progress = currentTime.value / duration.value; |
| | | // emit("timeUpdate", progress * 100); |
| | | // }, 1000 / playbackRate.value); // 根据播放速率调整间隔 |
| | | // }; |
| | | const startPlayback = () => { |
| | | clearInterval(playInterval); |
| | | |
| | | playInterval = setInterval(() => { |
| | | // 找到当前时间对应的索引 |
| | | const currentIndex = findClosestTimestampIndex(currentTime.value); |
| | | const nextIndex = currentIndex + 1; |
| | | if (selectedScheme.value.type === 2) { |
| | | // 类型为 2:每 5 秒跳动一次 |
| | | playInterval = setInterval(() => { |
| | | const fiveSeconds = 5; |
| | | const totalDuration = duration.value; // 总时长(秒) |
| | | |
| | | // 如果已经是最后一个时间点,停止播放 |
| | | if (nextIndex >= waterTimestamps.value.length) { |
| | | currentTime.value = duration.value; |
| | | stopPlayback(); |
| | | isPlaying.value = false; |
| | | emit("isPlaying", false); |
| | | emit("playbackFinished", true); |
| | | return; |
| | | } |
| | | currentTime.value += fiveSeconds; |
| | | |
| | | // 更新时间为下一个时间点的时间差(秒) |
| | | const nextTimestamp = waterTimestamps.value[nextIndex]; |
| | | const baseTimestamp = waterTimestamps.value[0]; |
| | | currentTime.value = (nextTimestamp - baseTimestamp) / 1000; |
| | | if (currentTime.value >= totalDuration) { |
| | | currentTime.value = totalDuration; |
| | | stopPlayback(); |
| | | isPlaying.value = false; |
| | | finishPlay.value = true; |
| | | emit("isPlaying", false); |
| | | emit("playbackFinished", true); |
| | | return; |
| | | } |
| | | |
| | | // 触发更新 |
| | | if (selectedScheme.value.type !== 2) { |
| | | // 触发进度更新 |
| | | const progress = currentTime.value / totalDuration; |
| | | emit("timeUpdate", progress * 100); |
| | | |
| | | // 如果需要触发某些更新函数,也可以保留 |
| | | updateWaterColorByTime(); |
| | | updateWeatherByProgress(); |
| | | } |
| | | }, 5000); // 每 5 秒执行一次 |
| | | } else { |
| | | // 这里面还是你的播放代码,上面的if中是五秒钟跳动一次的实时模拟 |
| | | playInterval = setInterval(() => { |
| | | const currentIndex = findClosestTimestampIndex(currentTime.value); |
| | | const nextIndex = currentIndex + 1; |
| | | |
| | | const progress = currentTime.value / duration.value; |
| | | emit("timeUpdate", progress * 100); |
| | | }, 1000 / playbackRate.value); // 根据播放速率调整间隔 |
| | | if (nextIndex >= waterTimestamps.value.length) { |
| | | currentTime.value = duration.value; |
| | | stopPlayback(); |
| | | isPlaying.value = false; |
| | | emit("isPlaying", false); |
| | | emit("playbackFinished", true); |
| | | return; |
| | | } |
| | | |
| | | const nextTimestamp = waterTimestamps.value[nextIndex]; |
| | | const baseTimestamp = waterTimestamps.value[0]; |
| | | currentTime.value = (nextTimestamp - baseTimestamp) / 1000; |
| | | |
| | | if (selectedScheme.value.type !== 2) { |
| | | updateWaterColorByTime(); |
| | | updateWeatherByProgress(); |
| | | } |
| | | |
| | | const progress = currentTime.value / duration.value; |
| | | emit("timeUpdate", progress * 100); |
| | | }, 1000 / playbackRate.value); |
| | | } |
| | | }; |
| | | // 降雨变化部分 |
| | | // 降雨数据相关变量 |
| | |
| | | } |
| | | // 全局状态记录 |
| | | const colorState = { |
| | | maxStage: 0, // 记录历史最高阶段 |
| | | maxAlpha: -0.3, // 记录历史最小透明度(负值) |
| | | maxStage: 0, // 记录历史最高阶段 |
| | | maxAlpha: -0.3, // 记录历史最小透明度(负值) |
| | | maxLuminance: 240.4, // 记录历史最低亮度(对应stage 0初始值) |
| | | currentColor: "#F5F0E6" // 当前颜色 |
| | | currentColor: "#F5F0E6", // 当前颜色 |
| | | }; |
| | | |
| | | function updateWaterColorByTime() { |
| | |
| | | { hex: "#D4B483", luminance: 184.0 }, // stage 3 |
| | | { hex: "#B78B6A", luminance: 148.4 }, // stage 4 |
| | | { hex: "#8B5A3A", luminance: 101.0 }, // stage 5 |
| | | { hex: "#4A3123", luminance: 54.9 } // stage 6 |
| | | { hex: "#4A3123", luminance: 54.9 }, // stage 6 |
| | | ]; |
| | | const alphaStops = [1 |
| | | -0.3, // stage 0 |
| | | -0.4, // stage 1 |
| | | -0.5, // stage 2 |
| | | -0.6, // stage 3 |
| | | -0.7, // stage 4 |
| | | -0.75, // stage 5 |
| | | -0.8 // stage 6 |
| | | const alphaStops = [ |
| | | 1 - 0.3, // stage 0 |
| | | -0.4, // stage 1 |
| | | -0.5, // stage 2 |
| | | -0.6, // stage 3 |
| | | -0.7, // stage 4 |
| | | -0.75, // stage 5 |
| | | -0.8, // stage 6 |
| | | ]; |
| | | // 3. 更新阶段状态 |
| | | updateStageState(intensity, IR); |
| | |
| | | function calculateRainData() { |
| | | const initialTimestamp = new Date(rainTotalInfo.value[0].time).getTime(); |
| | | const currentTimestamp = new Date( |
| | | rainTotalInfo.value[Math.min( |
| | | Math.floor(currentTime.value / duration.value * (rainTotalInfo.value.length - 1)), |
| | | rainTotalInfo.value.length - 2 |
| | | )].time |
| | | rainTotalInfo.value[ |
| | | Math.min( |
| | | Math.floor( |
| | | (currentTime.value / duration.value) * |
| | | (rainTotalInfo.value.length - 1) |
| | | ), |
| | | rainTotalInfo.value.length - 2 |
| | | ) |
| | | ].time |
| | | ).getTime(); |
| | | |
| | | // 降雨强度计算(带插值) |
| | |
| | | index = rainTotalInfo.value.length - 2; // 防止 index+1 越界 |
| | | } |
| | | const lerpAlpha = floatIndex - index; |
| | | const intensity = rainTotalInfo.value[index].intensity * (1 - lerpAlpha) + |
| | | const intensity = |
| | | rainTotalInfo.value[index].intensity * (1 - lerpAlpha) + |
| | | rainTotalInfo.value[index + 1].intensity * lerpAlpha; |
| | | |
| | | // 临界降雨强度计算 |
| | |
| | | const stageThresholds = [0, 0.2, 0.4, 0.6, 0.8, 1.0]; |
| | | const lowerThreshold = stageThresholds[colorState.maxStage - 1] * IR; |
| | | const upperThreshold = stageThresholds[colorState.maxStage] * IR; |
| | | const ratio = Math.min(1, Math.max(0, (intensity - lowerThreshold) / (upperThreshold - lowerThreshold))); |
| | | const ratio = Math.min( |
| | | 1, |
| | | Math.max( |
| | | 0, |
| | | (intensity - lowerThreshold) / (upperThreshold - lowerThreshold) |
| | | ) |
| | | ); |
| | | |
| | | // 颜色插值 |
| | | const startColor = colorStops[colorState.maxStage]; |
| | |
| | | colorState.maxLuminance = newLuminance; |
| | | colorState.maxAlpha = Math.min( |
| | | colorState.maxAlpha, |
| | | lerp(alphaStops[colorState.maxStage], alphaStops[colorState.maxStage + 1], ratio) |
| | | lerp( |
| | | alphaStops[colorState.maxStage], |
| | | alphaStops[colorState.maxStage + 1], |
| | | ratio |
| | | ) |
| | | ); |
| | | } |
| | | |
| | | console.log(`阶段: ${colorState.maxStage} | 亮度: ${colorState.maxLuminance.toFixed(1)} | 颜色: ${colorState.currentColor}`); |
| | | console.log( |
| | | `阶段: ${colorState.maxStage} | 亮度: ${colorState.maxLuminance.toFixed( |
| | | 1 |
| | | )} | 颜色: ${colorState.currentColor}` |
| | | ); |
| | | } |
| | | |
| | | // 颜色插值工具函数 |
| | | function lerpColor(c1, c2, t) { |
| | | const [r1, g1, b1] = hexToRgb(c1); |
| | | const [r2, g2, b2] = hexToRgb(c2); |
| | | return rgbToHex( |
| | | r1 + (r2 - r1) * t, |
| | | g1 + (g2 - g1) * t, |
| | | b1 + (b2 - b1) * t |
| | | ); |
| | | return rgbToHex(r1 + (r2 - r1) * t, g1 + (g2 - g1) * t, b1 + (b2 - b1) * t); |
| | | } |
| | | |
| | | function calculateLuminance(hex) { |
| | |
| | | } |
| | | |
| | | function rgbToHex(r, g, b) { |
| | | return `#${[r, g, b].map(x => Math.round(x).toString(16).padStart(2, '0')).join('')}`; |
| | | return `#${[r, g, b] |
| | | .map((x) => Math.round(x).toString(16).padStart(2, "0")) |
| | | .join("")}`; |
| | | } |
| | | |
| | | function lerp(a, b, t) { |
| | |
| | | { immediate: true } |
| | | ); |
| | | |
| | | onMounted(async () => { |
| | | const jsonFetch = ref(null); |
| | | |
| | | // 提取为独立函数 |
| | | async function initializeSimulationData(force = false) { |
| | | try { |
| | | // 当前方案的所有信息 |
| | | const schemeInfo = selectedScheme.value; |
| | | const jsonFetch = ref(null); |
| | | serviceInfo = schemeInfo.serviceName; |
| | | if (selectedScheme.value.type == 2) { |
| | | |
| | | if (schemeInfo.type == 2) { |
| | | speedShow.value = false; |
| | | jsonFetch.value = layerDate.value; |
| | | // serviceInfo = layerDate.value; |
| | | } else { |
| | | getRainfallData(); |
| | | speedShow.value = true; |
| | |
| | | |
| | | // console.log('获取到的 serviceName:', serviceInfo); |
| | | |
| | | // 根据layer.json去获取时间轴信息 |
| | | // 根据 layer.json 获取时间轴信息 |
| | | const { |
| | | waterTimestamps: timestamps, |
| | | watersMaxHeight, |
| | | watersMinHeight, |
| | | } = await fetchWaterSimulationData(serviceInfo, jsonFetch.value); |
| | | |
| | | console.log( |
| | | "当前方案下的最大水位深度和最小水位深度", |
| | | watersMaxHeight, |
| | | watersMinHeight |
| | | ); |
| | | |
| | | // 现在是按照总共有多少个点来渲染时间轴 |
| | | // 更新时间轴相关数据 |
| | | if (timestamps) { |
| | | frameNum.value = timestamps.length; |
| | | waterTimestamps.value = timestamps; |
| | |
| | | "YYYY-MM-DD HH:mm:ss" |
| | | ); |
| | | } |
| | | |
| | | minFlowRate = watersMinHeight; |
| | | maxFlowRate = watersMaxHeight; |
| | | } catch (error) { |
| | |
| | | type: "warning", |
| | | }); |
| | | } |
| | | } |
| | | |
| | | // 挂载时调用 |
| | | onMounted(async () => { |
| | | // 因为这个函数实时模拟监听也需要使用,所以封装了一个函数 |
| | | await initializeSimulationData(); |
| | | }); |
| | | |
| | | const shouldAutoPlay = ref(false); |
| | | |
| | | // 监听 layerDate 变化后标记准备播放 |
| | | watch( |
| | | () => layerDate.value, |
| | | async (newVal) => { |
| | | if (selectedScheme.value.type === 2 && newVal) { |
| | | shouldAutoPlay.value = true; |
| | | } |
| | | }, |
| | | { deep: true } |
| | | ); |
| | | |
| | | // 等待 finishPlay 成功后再播放 |
| | | watchEffect(() => { |
| | | if (shouldAutoPlay.value && finishPlay.value && !isPlaying.value) { |
| | | initializeSimulationData(); |
| | | togglePlay(); |
| | | shouldAutoPlay.value = false; |
| | | } |
| | | }); |
| | | |
| | | // 根据返回数据的个数去渲染时间轴 |
| | | function updateTimelineRange() { |
| | | if (waterTimestamps.value.length > 0) { |
| | |
| | | const { endSimulate } = inject("simulateActions"); |
| | | function handleBack() { |
| | | endSimulate(); |
| | | // 停止实时模拟定时器 |
| | | EventBus.emit("close-time"); |
| | | |
| | | isWaterPrimitiveCreated.value = false; |
| | | if (ratelevelRef.value) { |
| | | ratelevelRef.value.endCalculation(); |