wangjuncheng
2025-05-09 c3166cbe4614c3b15f8cf225e9b7b732e972699c
change
已修改1个文件
16 ■■■■■ 文件已修改
src/components/menu/TimeLine.vue 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/menu/TimeLine.vue
@@ -118,16 +118,12 @@
  ).map((date) => dayjs(date).toDate())
);
const currentTimeFormatted = computed(() => formatTime(currentTime.value));
// 播放控制
// 播放控制
const togglePlay = () => {
  if (!isPlaying.value && currentTime.value >= duration.value)
    currentTime.value = 0; // 如果已经播放完毕,重置时间
  isPlaying.value = !isPlaying.value;
  emit("isPlaying", isPlaying.value);
  if (isPlaying.value) {
    startPlayback();
    if (!isWaterPrimitiveCreated.value) {
@@ -139,9 +135,7 @@
      // 后续播放时调用恢复接口
      resumeWaterSimulation();
    }
    if (currentTime.value === 0) emit("playbackFinished", false);
    // 恢复下雨效果
    if (isRainEnabled.value) {
      mapUtils.toggleRain(rainParams, true);
@@ -149,7 +143,6 @@
  } else {
    stopPlayback();
    pauseWaterSimulation(); // 调用暂停接口
    // 停止下雨效果
    isRainEnabled.value = true; // 保存当前需要下雨的状态
    setTimeout(() => {
@@ -198,10 +191,8 @@
    console.warn("selectedScheme 或 data 不存在");
    return;
  }
  // 注意:有时 data 可能是一个字符串(例如 JSON 字符串)
  let data = selectedScheme.value.data;
  // 如果是字符串,则尝试解析成对象
  if (typeof data === 'string') {
    try {
@@ -217,7 +208,6 @@
  rainFallValues.value = rainfallList.map(r => r.intensity);
  minRainValue.value = Math.min(...rainFallValues.value);
  maxRainValue.value = Math.max(...rainFallValues.value);
  console.log(minRainValue.value, maxRainValue.value, 'min and max rain values');
}
// 定义降雨等级及其对应的视觉参数
@@ -280,24 +270,18 @@
// 根据播放进度更新天气效果(已优化)
let lastUsedIndex = -1; // 缓存上一次使用的索引,防止重复更新
let lastRainValue = null;
function updateWeatherByProgress() {
  if (rainFallValues.value.length === 0) return;
  console.log(`时间轴总时长: ${duration.value}, 当前时间: ${currentTime.value}`); // 打印时间轴信息
  const progress = currentTime.value / duration.value;
  const floatIndex = progress * (rainFallValues.value.length - 1);
  const index = Math.floor(floatIndex);            // 当前索引
  const nextIndex = Math.min(index + 1, rainFallValues.value.length - 1); // 下一索引
  const currentRain = rainFallValues.value[index];
  const nextRain = rainFallValues.value[nextIndex];
  // 启用插值(alpha 平滑过渡)
  const alpha = floatIndex - index;
  const rainValue = currentRain + (nextRain - currentRain) * alpha;
  // 打印当前处理的雨量数据
  console.log(`正在处理的雨量数据点: 当前=${currentRain}, 下一个=${nextRain}, 插值后=${rainValue.toFixed(2)}, 索引=${index}`);