| | |
| | | } |
| | | }; |
| | | |
| | | // 控制方法:精确控制动画时间,最后一帧在第 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; |
| | | } |
| | |
| | | const delay = Math.max(0, startTime + expectedTime - now); |
| | | |
| | | updateInterval = setTimeout(() => { |
| | | dataIndex.value = index + 1; // 因为是从 0 开始 push 的 |
| | | dataIndex.value = index; |
| | | updateData(); |
| | | animate(index + 1); |
| | | }, delay); |
| | |
| | | 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]; |