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(); } }); // 其他原有代码保持不变...