2
wangjuncheng
2025-07-01 9aed93946a567c874c847b4d3e356058b0455ae7
src/components/monifangzhen/echartInfo.vue
@@ -309,7 +309,6 @@
  if (nowTime.value) {
    const timeParts = nowTime.value.split(" ");
    const timeOnly = timeParts[1]; // 获取 "mm:ss" 部分
    console.log(nowTime.value, "nowTime.valuenowTime.value");
    return timeOnly;
  }
};
@@ -451,16 +450,33 @@
    }
  };
  // 控制方法:精确控制动画时间,最后一帧在第 90 秒
  let fixedFrameNum = null;
  let startTime = null; // 将startTime移到外层
  let elapsedBeforePause = 0; // 记录暂停前已经过去的时间
  const startUpdating = () => {
    if (updateInterval || dataIndex.value >= rainfallData.value.length) return;
    if (updateInterval || dataIndex.value >= rainfallData.value.length) {
      // console.log("Animation already running or completed");
      return;
    }
    const totalDuration = simStore.frameNum * 1000; // 90秒
    // 如果是首次启动或重新开始
    if (fixedFrameNum === null) {
      fixedFrameNum = simStore.frameNum;
      elapsedBeforePause = 0;
      startTime = Date.now();
    } else {
      // 如果是暂停后继续,调整startTime以反映已经过去的时间
      startTime = Date.now() - elapsedBeforePause;
    }
    const totalDuration = fixedFrameNum * 1000;
    const totalPoints = rainfallData.value.length;
    const startTime = Date.now();
    const animate = (index = 0) => {
    const animate = (index) => {
      if (index >= totalPoints) {
        console.log("Animation completed");
        stopUpdating();
        return;
      }
@@ -470,7 +486,7 @@
      const delay = Math.max(0, startTime + expectedTime - now);
      updateInterval = setTimeout(() => {
        dataIndex.value = index + 1; // 因为是从 0 开始 push 的
        dataIndex.value = index;
        updateData();
        animate(index + 1);
      }, delay);
@@ -479,13 +495,26 @@
    animate(dataIndex.value);
  };
  // 暂停函数需要记录已经过去的时间
  const stopUpdating = () => {
    clearTimeout(updateInterval);
    updateInterval = null;
    if (updateInterval) {
      clearTimeout(updateInterval);
      updateInterval = null;
      // 记录暂停时已经过去的时间
      elapsedBeforePause = Date.now() - startTime;
    }
  };
  // const stopUpdating = () => {
  //   clearTimeout(updateInterval);
  //   updateInterval = null;
  // };
  const resetLoading = () => {
    stopUpdating();
    fixedFrameNum = null;
    startTime = null;
    elapsedBeforePause = 0;
    dataIndex.value = 0;
    data1.value = [0];
    data2.value = [0];