guonan
2025-06-24 d8e4d7a23117fa2945689e79fc7f66a1b1951825
src/components/menu/TimeLine.vue
@@ -190,7 +190,12 @@
const isColorRenderEnabled = ref(false); // 假设这是你的颜色渲染开关状态
const isWaterPrimitiveCreated = ref(false);
let playInterval = null;
<<<<<<< HEAD
let rainTotalInfo = [];
=======
let timeStepInfo = null;
let rainTotalInfo = ([]);
>>>>>>> 68e0faf021b54ab38bba0b07c76c3d5f43dfc311
const isRainEnabled = ref(false);
const rainParams = reactive({
  rainSize: 0.5,
@@ -347,7 +352,14 @@
  const rainfallList = data.rainfalls;
  console.log("最终的 rainfallList:", rainfallList);
<<<<<<< HEAD
  rainTotalInfo.value = rainfallList;
=======
  rainTotalInfo.value = rainfallList
  calculateTimeStep(rainTotalInfo.value)
  // 使用示例
 timeStepInfo = calculateTimeStep(rainTotalInfo.value);
>>>>>>> 68e0faf021b54ab38bba0b07c76c3d5f43dfc311
  // 提取 intensity 值
  rainFallValues.value = rainfallList.map((r) => r.intensity);
@@ -423,6 +435,40 @@
// 根据播放进度更新天气效果(已优化)
let lastUsedIndex = -1; // 缓存上一次使用的索引,防止重复更新
let lastRainValue = null;
function calculateTimeStep(dataArray) {
  if (!dataArray || dataArray.length < 2) {
    console.warn('数据不足,无法计算时间步长');
    return null;
  }
  // 解析时间字符串为 Date 对象
  function parseTime(timeStr) {
    return new Date(timeStr.replace(' ', 'T')); // 兼容 ISO 格式
  }
  const firstTime = parseTime(dataArray[0].time);
  const secondTime = parseTime(dataArray[1].time);
  // 计算时间差(毫秒)
  const diffMs = Math.abs(secondTime - firstTime);
  // 转换为小时数(保留小数)
  let timeStepHours = diffMs / (1000 * 60 * 60); // 毫秒 -> 小时
  // 可选:遍历所有相邻项检查是否一致
  for (let i = 1; i < dataArray.length - 1; i++) {
    const current = parseTime(dataArray[i].time);
    const next = parseTime(dataArray[i + 1].time);
    const step = Math.abs(next - current) / (1000 * 60 * 60); // 毫秒 -> 小时
    if (Math.abs(step - timeStepHours) > 0.01) {
      console.warn(`在索引 ${i} 处发现了不同的时间步长: ${step.toFixed(2)} 小时`);
    }
  }
  return timeStepHours;
}
function updateWaterColorByTime() {
  if (!rainTotalInfo.value || rainTotalInfo.value.length === 0) return;
  const progress = currentTime.value / duration.value;
@@ -436,10 +482,12 @@
  const currentTotal = currentData.total;
  const nextTotal = nextData.total;
  const total = currentTotal + (nextTotal - currentTotal) * alpha;
  console.log(`计算得到的时间步长为: ${timeStepInfo} 小时`);
  // 根据 total 设置颜色
  let color = "#D4F2E7"; // 默认蓝色
  if (total >= 150) {
<<<<<<< HEAD
    color = "#663300"; // 黄 - 大雨
  } else if (total >= 125) {
    color = "#B26633"; // 黄绿 - 中雨
@@ -451,6 +499,19 @@
    color = "#99CCFF"; // 天蓝 - 小雨
  } else if (total >= 25) {
    color = "#66B3FF"; // 浅蓝 - 微量
=======
    color = '#663300';
  } else if (total >= 125) {
    color = '#B26633';
  } else if (total >= 100) {
    color = '#CC9966';
  } else if (total >= 75) {
    color = '#CCE5FF';
  } else if (total >= 50) {
    color = '#99CCFF';
  } else if (total >= 25) {
    color = '#66B3FF';
>>>>>>> 68e0faf021b54ab38bba0b07c76c3d5f43dfc311
  }
  // console.log(`当前 total: ${total.toFixed(2)}, 颜色: ${color}`);
  // updateWaterColor(color)