123
guonan
2025-07-08 f62af17e57e2feceddbaf956351d499876d35490
123
已添加1个文件
98 ■■■■■ 文件已修改
public/json/rainfall.js 98 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
public/json/rainfall.js
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,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();
  }
});
// å…¶ä»–原有代码保持不变...