diff --git a/frontend/src/components/kubernetes/PodExecTerminal.tsx b/frontend/src/components/kubernetes/PodExecTerminal.tsx index e7c6da2..c471007 100644 --- a/frontend/src/components/kubernetes/PodExecTerminal.tsx +++ b/frontend/src/components/kubernetes/PodExecTerminal.tsx @@ -55,6 +55,7 @@ export function PodExecTerminal({ const wsRef = useRef(null); const fitRef = useRef(null); const mountedRef = useRef(false); + const errorShownRef = useRef(false); const [connState, setConnState] = useState('idle'); const [fullscreen, setFullscreen] = useState(false); @@ -118,13 +119,12 @@ export function PodExecTerminal({ try { const msg = JSON.parse(event.data); if (msg.status === 0 && typeof msg.data === 'string') { - console.debug('[PodExec:ws] RX stdout, len=', msg.data.length); term.write(msg.data); } else if (msg.status === 2 || msg.error) { const errMsg = msg.data || msg.message || msg.error || '执行错误'; - console.warn('[PodExec] error:', errMsg.substring(0, 200)); if (errMsg.includes('not found') && shell === 'bash') { term.writeln('\r\n\x1b[33m⚠ bash 不可用,请切换 /bin/sh 后重连。\x1b[0m'); + errorShownRef.current = true; return; } term.write(errMsg.includes('\x1b') ? errMsg : `\r\n\x1b[31m${errMsg}\x1b[0m\r\n`); @@ -135,9 +135,10 @@ export function PodExecTerminal({ }; ws.onclose = (ev) => { - console.log('[PodExec:connect] WS closed: code=', ev.code, 'reason=', ev.reason, 'wasClean=', ev.wasClean); setConnState((s) => (s === 'error' ? s : 'closed')); - term.write('\r\n\x1b[33m[连接已断开]\x1b[0m\r\n'); + if (!errorShownRef.current) { + term.write('\r\n\x1b[33m[连接已关闭]\x1b[0m\r\n'); + } }; ws.onerror = (ev) => {