wangjuncheng
2025-07-08 f373e0c0797e1800bf066fdfbb748bb9242230f6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const jsonFetch = ref(null);
const currentReplayIndex = ref(0);
const isReplaySequencePlaying = ref(false); // 新增:标记是否正在顺序播放
 
async function initializeSimulationData(force = false, replayItem = null) {
  try {
    const schemeInfo = selectedScheme.value;
    serviceInfo = schemeInfo.serviceName;
 
    if (schemeInfo.type == 2) {
      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;
      jsonFetch.value = null;
    }
 
    const {
      waterTimestamps: timestamps,
      watersMaxHeight,
      watersMinHeight,
    } = await fetchWaterSimulationData(serviceInfo, jsonFetch.value);
 
    if (timestamps) {
      frameNum.value = timestamps.length;
      waterTimestamps.value = timestamps;
      updateTimelineRange();
      timeMarkers.value = generateTimeMarkers(timestamps);
      sendCurrentPlayingTime.value = timestamps[0];
      currentPlayingTime.value = dayjs(timestamps[0]).format(
        "YYYY-MM-DD HH:mm:ss"
      );
    }
    minFlowRate = watersMinHeight;
    maxFlowRate = watersMaxHeight;
    
    // 如果是回放模式且不是强制刷新,则开始播放
    if (schemeInfo.type == 2 && !force && isReplaySequencePlaying.value) {
      togglePlay();
    }
  } catch (error) {
    console.error("Error loading water simulation data:", error);
    ElMessage({
      message: "降雨数据出错,请重新新建模拟方案!",
      type: "warning",
    });
  }
}
 
function handlePlayFinished() {
  if (selectedScheme.value.type !== 2 || !isReplaySequencePlaying.value) return;
  
  // 确保播放状态已停止
  isPlaying.value = false;
  
  // 播放下一个或结束序列
  currentReplayIndex.value++;
  
  if (currentReplayIndex.value < simStore.rePlayList.length) {
    // 短暂延迟确保状态完全重置
    setTimeout(() => {
      initializeSimulationData(false, simStore.rePlayList[currentReplayIndex.value]);
    }, 100);
  } else {
    // 序列播放结束
    isReplaySequencePlaying.value = false;
    currentReplayIndex.value = 0;
  }
}
 
// 开始顺序播放所有项目
function startReplaySequence() {
  if (simStore.rePlayList?.length > 0) {
    currentReplayIndex.value = 0;
    isReplaySequencePlaying.value = true;
    initializeSimulationData(false, simStore.rePlayList[0]);
  }
}
 
// 挂载时调用
onMounted(async () => {
  await initializeSimulationData();
});
 
// 监听播放完成事件
watch(() => finishPlay.value, (newVal) => {
  if (newVal && selectedScheme.value.type === 2 && isReplaySequencePlaying.value) {
    handlePlayFinished();
  }
});
 
// 其他原有代码保持不变...