diff --git a/src/pages/ideContainer/logBar.tsx b/src/pages/ideContainer/logBar.tsx index 1271cb8..a8b709f 100644 --- a/src/pages/ideContainer/logBar.tsx +++ b/src/pages/ideContainer/logBar.tsx @@ -164,20 +164,24 @@ const LogBar: React.FC = () => { }; }, [dispatch, currentAppData]); - // 实现轮询获取运行数据 + // 获取当前应用的运行状态 + const currentAppKey = getCurrentAppKey(); + const isRunning = currentAppKey && appRuntimeData[currentAppKey]?.isRunning; + + // 实现轮询获取运行数据 - 只在应用运行时轮询 useEffect(() => { let intervalId: NodeJS.Timeout | null = null; - const currentAppKey = getCurrentAppKey(); + const appKey = getCurrentAppKey(); - // 只有在当前tab是运行数据且有当前应用时才开始轮询 - if (activeTab === '3' && currentAppKey && logBarStatus && appRuntimeData[currentAppKey]?.runId) { + // 只有在应用正在运行且有 runId 时才开始轮询 + if (appKey && appRuntimeData[appKey]?.isRunning && appRuntimeData[appKey]?.runId) { const fetchRuntimeData = async () => { try { setLoading(true); - const response = await getNodeData(appRuntimeData[currentAppKey].runId); + const response = await getNodeData(appRuntimeData[appKey].runId); setRuntimeData(prev => ({ ...prev, - [currentAppKey]: response.data + [appKey]: response.data })); } catch (error) { console.error('获取运行数据失败:', error); @@ -189,17 +193,30 @@ const LogBar: React.FC = () => { // 立即获取一次数据 fetchRuntimeData(); - // 设置轮询,每5秒获取一次数据 + // 设置轮询,每3秒获取一次数据 intervalId = setInterval(fetchRuntimeData, 3000); } - // 清理函数,组件卸载或条件不满足时清除定时器 + // 清理函数,组件卸载或应用停止运行时清除定时器 return () => { if (intervalId) { clearInterval(intervalId); } }; - }, [activeTab, currentAppData, logBarStatus]); + }, [currentAppData, appRuntimeData]); + + // 当应用停止运行时,清除运行数据 + useEffect(() => { + const appKey = getCurrentAppKey(); + if (appKey && !appRuntimeData[appKey]?.isRunning) { + // 清除当前应用的运行数据 + setRuntimeData(prev => { + const newData = { ...prev }; + delete newData[appKey]; + return newData; + }); + } + }, [isRunning, currentAppData]); // 渲染校验日志内容 const renderValidationLogs = () => {