From 66032f62b4a3b6a649fc02b392ae41278399b58b Mon Sep 17 00:00:00 2001 From: wangjuncheng <1> Date: 星期二, 08 七月 2025 15:23:19 +0800 Subject: [PATCH] 添加打印加坝数据代码, 但调用被注释 --- src/views/left/KGSimOption/RealTimeSimulation.vue | 205 +++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 166 insertions(+), 39 deletions(-) diff --git a/src/views/left/KGSimOption/RealTimeSimulation.vue b/src/views/left/KGSimOption/RealTimeSimulation.vue index 4dc917b..288a377 100644 --- a/src/views/left/KGSimOption/RealTimeSimulation.vue +++ b/src/views/left/KGSimOption/RealTimeSimulation.vue @@ -81,7 +81,8 @@ import { useSimStore } from "@/store/simulation.js"; import { EventBus } from "@/eventBus"; // 寮曞叆浜嬩欢鎬荤嚎 import { getDeviceInfoSHG, getYLJData } from "@/api/hpApi"; -import { getSimStart, getSimDataById } from "@/api/trApi"; +import { getSimStart, getSimDataById, getSimresult } from "@/api/trApi"; +import { ControlSchemeType } from "@/assets/js/lib-pixelstreamingfrontend.esm"; // 鑾峰彇 Store 瀹炰緥 const simAPIStore = SimAPIStore(); @@ -209,6 +210,8 @@ updateSelectedGauges(); formData.geom = props.selectedArea; await simAPIStore.addSimCheme(formData); + // 鎵撳嵃鎷︽尅鍧濇墍闇�瑕佺殑鏁版嵁 + // printDamEntities(); resetForm(); EventBus.emit("close-selectArea"); } catch (err) {} @@ -219,14 +222,15 @@ // 瀹炴椂妯℃嫙瀹氭椂鍣� let pollingInterval = null; +// 鐢ㄤ簬璁板綍涓婃鏁版嵁鏉℃暟 +let lastDataLength = 0; + +let pollingTimer = null; // 鐢ㄤ簬淇濆瓨瀹氭椂鍣ㄥ紩鐢� async function startPlay() { - // 寮�濮嬫ā鎷熷墠闇�瑕佸厛淇濆瓨鏂规 updateSelectedGauges(); - formData.geom = props.selectedArea; - // 淇濆瓨鏂规 const resApi = await simAPIStore.addSimCheme(formData); const schemeId = resApi.data?.data?.id; @@ -237,7 +241,6 @@ EventBus.emit("close-selectArea"); - // 鏄剧ず鍔犺浇涓彁绀� const loadingMessage = ElMessage({ type: "info", message: "姝e湪鍚姩妯℃嫙...", @@ -246,58 +249,130 @@ }); try { - // 璋冪敤姹傝В鍣ㄥ苟鍒濆鍖栨ā鎷� - const resStart = await getSimStart(schemeId); + await getSimStart(schemeId); - // 璇锋眰瀹屾垚鍚庡叧闂姞杞芥彁绀� - loadingMessage.close(); - - if (resStart.code === 200) { - const res = await getSimDataById(schemeId); - simStore.setSelectedScheme(res.data[0]); - - simStore.layerDate = resStart.data; - initeWaterPrimitiveView(); - + // 瀹氫箟涓�涓嚱鏁扮敤浜庤疆璇㈣幏鍙栨暟鎹� + const pollForResult = async () => { try { - startSimulate(); // 杩欓噷鍙兘浼氭姤閿� - } catch (error) { - console.error("璋冪敤 startSimulate 鍑洪敊锛�", error); - } + const res = await getSimresult(schemeId); + console.log(res.data, "瀹炴椂妯℃嫙 - 杞缁撴灉"); - // 寮�濮嬭疆璇换鍔★細姣� 5 鍒嗛挓璋冪敤涓�娆� getSimStart 骞舵洿鏂版柟妗堟暟鎹� - startPolling(schemeId); - } else { - ElMessage.error(resStart.message || "璋冪敤姹傝В鍣ㄥけ璐�"); - } + if (res.code === 200 && res.data.length > 0) { + // 鎴愬姛鎷垮埌鏁版嵁 + loadingMessage.close(); + handleNewData(res.data, schemeId); + startPolling(schemeId); + + // 鉁� 娓呴櫎瀹氭椂鍣� + if (pollingTimer) { + clearTimeout(pollingTimer); + pollingTimer = null; + } + } else { + // 鏁版嵁鏃犳晥锛岀户缁疆璇� + pollingTimer = setTimeout(pollForResult, 10 * 1000); + } + } catch (error) { + console.error("璇锋眰妯℃嫙缁撴灉澶辫触", error); + pollingTimer = setTimeout(pollForResult, 10 * 1000); // 璇锋眰鍑洪敊涔熺户缁疆璇� + } + }; + + // 棣栨寤惰繜 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; + } } } -// 鍚姩杞鍑芥暟 +// 瀹氭椂浜斿垎閽熻姹� function startPolling(schemeId) { - stopPolling(); // 閬垮厤閲嶅鍚姩 + stopPolling(); // 纭繚涓嶄細閲嶅鍚姩 pollingInterval = setInterval(async () => { try { - const resStart = await getSimStart(schemeId); + const res = await getSimresult(schemeId); - if (resStart.code === 200) { - const res = await getSimDataById(schemeId); - simStore.setSelectedScheme(res.data[0]); // 鏇存柊鏂规鏁版嵁 - simStore.layerDate = resStart.data; // 鏇存柊 layer 鏁版嵁 + if (res.data && res.data.length > 0) { + if (res.data.length === lastDataLength) { + console.log("涓昏疆璇細鏃犳柊鏁版嵁锛屽垏鎹负 10 绉掗珮棰戣疆璇�"); - console.log("杞鑾峰彇鏈�鏂版暟鎹垚鍔�"); - } else { - console.warn("杞璇锋眰澶辫触锛�", resStart.message); + clearInterval(pollingInterval); + pollingInterval = null; + + startFastPolling(schemeId); // 鍚姩楂橀杞 + } else { + handleNewData(res.data, schemeId); + } } } catch (error) { - console.error("杞璇锋眰寮傚父锛�", error); + console.error("杞鑾峰彇妯℃嫙缁撴灉澶辫触", error); } - }, 5 * 60 * 1000); // 姣� 5 鍒嗛挓鎵ц涓�娆� + }, 5.6 * 60 * 1000); // 姣� 5.5 鍒嗛挓鎵ц涓�娆� +} + +let fastPollingInterval = null; +// 濡傛灉浜斿垎閽熸病鎷垮埌鏈�鏂扮殑鏁版嵁锛屽垯寮�鍚崄绉掗挓璋冪敤涓�娆★紝鎷垮埌鏈�鏂扮殑鏁版嵁灏卞仠姝� +function startFastPolling(schemeId) { + fastPollingInterval = setInterval(async () => { + try { + const res = await getSimresult(schemeId); + + if (res.data && res.data.length > 0) { + if (res.data.length !== lastDataLength) { + console.log("楂橀杞锛氭娴嬪埌鏂版暟鎹紝鎭㈠涓昏疆璇�"); + + clearInterval(fastPollingInterval); + fastPollingInterval = null; + + handleNewData(res.data, schemeId); + + startPolling(schemeId); // 閲嶆柊鍚姩涓昏疆璇� + } + } + } catch (error) { + console.error("楂橀杞鑾峰彇妯℃嫙缁撴灉澶辫触", error); + } + }, 10 * 1000); // 姣� 10 绉掓墽琛屼竴娆� +} + +// 鎷垮彇鏈�鏂扮殑layer.json瀛樺偍鍒皃inia涓� +async function handleNewData(dataArray, schemeId) { + // 鎷挎湇鍔″悕绉� + const res = await getSimDataById(schemeId); + simStore.setSelectedScheme(res.data[0]); // 鏇存柊鏂规鏁版嵁 + + const latestItem = dataArray[dataArray.length - 1]; + const currentLength = dataArray.length; + + if (currentLength <= lastDataLength) { + console.log("鏈疆鏃犳柊鏁版嵁锛堥暱搴︽湭鍙樺寲锛�"); + return; + } + + // 鏇存柊鏍囪瘑 + lastDataLength = currentLength; + + // 鎵ц鏇存柊閫昏緫 + console.log("妫�娴嬪埌鏂版暟鎹紝鏇存柊涓�..."); + console.log(latestItem, "last"); + simStore.layerDate = latestItem; + initeWaterPrimitiveView(); + + try { + startSimulate(); + } catch (error) { + console.error("璋冪敤 startSimulate 鍑洪敊锛�", error); + } } // 鍋滄杞鍑芥暟 @@ -305,8 +380,14 @@ if (pollingInterval) { clearInterval(pollingInterval); pollingInterval = null; - console.log("杞宸插仠姝�"); } + + if (fastPollingInterval) { + clearInterval(fastPollingInterval); + fastPollingInterval = null; + } + + console.log("杞宸插仠姝�"); } EventBus.on("close-time", () => { @@ -325,6 +406,52 @@ EventBus.off("close-time"); stopPolling(); }); +// ========================================鎷︽尅鍧�=============================================================== +// 鑾峰彇鎷︽尅鍧濇暟鎹� +function printDamEntities() { + const entities = viewer.entities.values; + const damDataList = []; + + for (let i = 0; i < entities.length; i++) { + const entity = entities[i]; + + if (entity.name && (entity.name === '鏍忔。鍧�1' || entity.name === '鏍忔。鍧�2')) { + damDataList.push({ + name: entity.name, + position: entity.position?._value, + heading: entity.heading?._value ?? entity.heading, + pitch: entity.pitch?._value ?? entity.pitch, + roll: entity.roll?._value ?? entity.roll, + modelScale: entity.model?.scale?._value ?? entity.model?.scale + }); + } + } + if (damDataList.length > 0) { + console.log("銆愭爮妗e潩瀹炰綋鏁版嵁鍒楄〃銆戯細", damDataList); + deleteDamEntitiesAfterDelay(); + } else { + console.log("鏈壘鍒颁换浣曞悕涓� '鏍忔。鍧�1' 鎴� '鏍忔。鍧�2' 鐨勫疄浣�"); + } +} +// 淇濆瓨鏂规鍚庡畾鏃舵竻闄ゆ柊寤虹殑鎷︽尅鍧濇暟鎹� +function deleteDamEntitiesAfterDelay() { + setTimeout(() => { + const entities = Array.from(viewer.entities.values); + const damsToDelete = entities.filter( + entity => entity.name === '鏍忔。鍧�1' || entity.name === '鏍忔。鍧�2' + ); + + damsToDelete.forEach(entity => { + viewer.entities.remove(entity); + }); + + if (damsToDelete.length > 0) { + console.log(`銆愬凡鍒犻櫎銆戝叡 ${damsToDelete.length} 涓爮妗e潩瀹炰綋`); + } else { + console.log("鏈壘鍒颁换浣曞彲鍒犻櫎鐨勬爮妗e潩瀹炰綋"); + } + }, 5000); +} </script> <style scoped> -- Gitblit v1.9.3