From 35c2c3bb86f9ac520c76d274b95061b313ffbf8b Mon Sep 17 00:00:00 2001 From: JIANG Date: Tue, 18 Nov 2025 14:46:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BC=BA=E5=88=B6=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E5=90=8E=EF=BC=8C=E6=B8=85=E9=99=A4=E7=BC=93=E5=AD=98?= =?UTF-8?q?=EF=BC=8C=E4=BD=86=E6=98=AF=E6=B2=A1=E6=9C=89=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=BD=93=E5=89=8D=E6=97=B6=E5=88=BB=E7=9A=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/OlMap/Controls/Timeline.tsx | 74 ++++++++++++++--------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/app/OlMap/Controls/Timeline.tsx b/src/app/OlMap/Controls/Timeline.tsx index 0e8ebb2..1953e2f 100644 --- a/src/app/OlMap/Controls/Timeline.tsx +++ b/src/app/OlMap/Controls/Timeline.tsx @@ -426,6 +426,41 @@ const Timeline: React.FC = ({ } }, [map, handlePause]); + const clearCacheAndRefetch = (date: Date, timeInMinutes: number) => { + const dateStr = date.toISOString().split("T")[0]; + + const clearCache = ( + cacheRef: React.MutableRefObject> + ) => { + const cacheKeys = Array.from(cacheRef.current.keys()); + cacheKeys.forEach((key) => { + const keyParts = key.split("_"); + const cacheDate = keyParts[0].split("T")[0]; + const cacheTimeStr = keyParts[0].split("T")[1]; + + if (cacheDate === dateStr && cacheTimeStr) { + const [hours, minutes] = cacheTimeStr.split(":"); + const cacheTimeInMinutes = parseInt(hours) * 60 + parseInt(minutes); + + if (cacheTimeInMinutes >= timeInMinutes) { + cacheRef.current.delete(key); + } + } + }); + }; + + clearCache(nodeCacheRef); + clearCache(linkCacheRef); + + // 重新获取当前时刻的新数据 + fetchFrameData( + currentTimeToDate(selectedDate, currentTime), + junctionText, + pipeText, + schemeName + ); + }; + const handleForceCalculate = async () => { if (!NETWORK_NAME) { open?.({ @@ -467,43 +502,8 @@ const Timeline: React.FC = ({ ); if (response.ok) { - // 清空当天当前时刻及之后的缓存 - const currentDateStr = calculationDateStr; - const currentTimeInMinutes = calculationTime; - - // 清空node缓存 - const nodeCacheKeys = Array.from(nodeCacheRef.current.keys()); - nodeCacheKeys.forEach((key) => { - const keyParts = key.split("_"); - const cacheDate = keyParts[0].split("T")[0]; - const cacheTimeStr = keyParts[0].split("T")[1]; - - if (cacheDate === currentDateStr && cacheTimeStr) { - const [hours, minutes] = cacheTimeStr.split(":"); - const cacheTimeInMinutes = parseInt(hours) * 60 + parseInt(minutes); - - if (cacheTimeInMinutes >= currentTimeInMinutes) { - nodeCacheRef.current.delete(key); - } - } - }); - - // 清空link缓存 - const linkCacheKeys = Array.from(linkCacheRef.current.keys()); - linkCacheKeys.forEach((key) => { - const keyParts = key.split("_"); - const cacheDate = keyParts[0].split("T")[0]; - const cacheTimeStr = keyParts[0].split("T")[1]; - - if (cacheDate === currentDateStr && cacheTimeStr) { - const [hours, minutes] = cacheTimeStr.split(":"); - const cacheTimeInMinutes = parseInt(hours) * 60 + parseInt(minutes); - - if (cacheTimeInMinutes >= currentTimeInMinutes) { - linkCacheRef.current.delete(key); - } - } - }); + // 清空当天当前时刻及之后的缓存并重新获取数据 + clearCacheAndRefetch(calculationDate, calculationTime); open?.({ type: "success",