From f37845dd0a787dd42bf6c72e923433f30fcd8cc3 Mon Sep 17 00:00:00 2001 From: guonan <guonan201020@163.com> Date: 星期四, 03 七月 2025 15:40:09 +0800 Subject: [PATCH] 实时模拟 --- src/views/left/CitySim.vue | 2 +- src/components/monifangzhen/schemeCard.vue | 2 +- src/views/left/KGSimOption/RealTimeSimulation.vue | 49 ++++++++++++++++++++++++++++++++----------------- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/components/monifangzhen/schemeCard.vue b/src/components/monifangzhen/schemeCard.vue index 413b52c..c8c6c6e 100644 --- a/src/components/monifangzhen/schemeCard.vue +++ b/src/components/monifangzhen/schemeCard.vue @@ -222,7 +222,7 @@ item.result == "瀹屾垚" || item.result == "-1" || item.result == "鍋滄" || - item.result == "杩涜涓�" + item.result == "杩愯涓�" ); simAPIStore.shouldPoll = !shouldStop; // 淇敼 Pinia 鐘舵�� // 3. 濡傛灉闇�瑕佸仠姝� diff --git a/src/views/left/CitySim.vue b/src/views/left/CitySim.vue index 9ecf788..f74e646 100644 --- a/src/views/left/CitySim.vue +++ b/src/views/left/CitySim.vue @@ -186,7 +186,7 @@ const intensityOptions = ref([ { value: "mm/h", label: "mm/h" }, { value: "mm/5min", label: "mm/5min" }, - { value: "mm/1min", label: "mm/1min" }, + { value: "mm/min", label: "mm/min" }, ]); // 瀹氫箟涓�涓柟娉曪紝鐢ㄤ簬鏍规嵁 type 鑾峰彇鍖哄煙鏁版嵁 diff --git a/src/views/left/KGSimOption/RealTimeSimulation.vue b/src/views/left/KGSimOption/RealTimeSimulation.vue index 7db609f..14c3105 100644 --- a/src/views/left/KGSimOption/RealTimeSimulation.vue +++ b/src/views/left/KGSimOption/RealTimeSimulation.vue @@ -223,13 +223,12 @@ // 鐢ㄤ簬璁板綍涓婃鏁版嵁鏉℃暟 let lastDataLength = 0; -async function startPlay() { - // 寮�濮嬫ā鎷熷墠闇�瑕佸厛淇濆瓨鏂规 - updateSelectedGauges(); +let pollingTimer = null; // 鐢ㄤ簬淇濆瓨瀹氭椂鍣ㄥ紩鐢� +async function startPlay() { + updateSelectedGauges(); formData.geom = props.selectedArea; - // 淇濆瓨鏂规 const resApi = await simAPIStore.addSimCheme(formData); const schemeId = resApi.data?.data?.id; @@ -240,7 +239,6 @@ EventBus.emit("close-selectArea"); - // 鏄剧ず鍔犺浇涓彁绀� const loadingMessage = ElMessage({ type: "info", message: "姝e湪鍚姩妯℃嫙...", @@ -249,31 +247,48 @@ }); try { - // 鍚姩妯℃嫙 await getSimStart(schemeId); - // 棣栨璇锋眰寤惰繜 90s - setTimeout(async () => { + // 瀹氫箟涓�涓嚱鏁扮敤浜庤疆璇㈣幏鍙栨暟鎹� + const pollForResult = async () => { try { const res = await getSimresult(schemeId); - console.log(res.data, "瀹炴椂妯℃嫙 - 鍒濆缁撴灉"); + console.log(res.data, "瀹炴椂妯℃嫙 - 杞缁撴灉"); - if (res.data.length > 0) { + if (res.code === 200 && res.data.length > 0) { + // 鎴愬姛鎷垮埌鏁版嵁 + loadingMessage.close(); handleNewData(res.data, schemeId); - } + startPolling(schemeId); - // 鏄剧ず缁撴灉骞跺紑濮嬭疆璇� - loadingMessage.close(); - startPolling(schemeId); + // 鉁� 娓呴櫎瀹氭椂鍣� + if (pollingTimer) { + clearTimeout(pollingTimer); + pollingTimer = null; + } + } else { + // 鏁版嵁鏃犳晥锛岀户缁疆璇� + pollingTimer = setTimeout(pollForResult, 10 * 1000); + } } catch (error) { - console.error("棣栨璇锋眰妯℃嫙缁撴灉澶辫触", error); - loadingMessage.close(); + console.error("璇锋眰妯℃嫙缁撴灉澶辫触", error); + pollingTimer = setTimeout(pollForResult, 10 * 1000); // 璇锋眰鍑洪敊涔熺户缁疆璇� } - }, 3 * 60 * 1000); // 1.5 鍒嗛挓鍚庣涓�娆¤姹� + }; + + // 棣栨寤惰繜 2 鍒嗛挓寮�濮嬭疆璇� + pollingTimer = setTimeout(async () => { + await pollForResult(); // 寮�濮嬬涓�娆¤疆璇� + }, 3 * 60 * 1000); // 3鍒嗛挓鍚庣涓�娆¤姹� } catch (error) { loadingMessage.close(); ElMessage.error("璇锋眰澶辫触锛�" + (error.message || "鏈煡閿欒")); console.error("璋冪敤 getSimStart 鍑洪敊锛�", error); + + if (pollingTimer) { + clearTimeout(pollingTimer); + pollingTimer = null; + } } } -- Gitblit v1.9.3