fix: 修复关闭SSH终端标签页时会话状态未更新的问题

This commit is contained in:
2026-04-18 02:35:38 +08:00
commit 6e2e2f9387
43467 changed files with 5489040 additions and 0 deletions
+77
View File
@@ -0,0 +1,77 @@
import {Button, Form, Input, InputNumber} from 'antd';
import React, {useState} from 'react';
import {baseUrl, getToken} from "@/api/core/requests";
import {useTranslation} from "react-i18next";
const ToolsPing = () => {
let {t} = useTranslation();
const [host, setHost] = useState("");
const [attempts, setAttempts] = useState<number>(4);
const [logs, setLogs] = useState<string[]>([]);
const [running, setRunning] = useState(false);
let eventSource: EventSource | null = null;
const onSearch = (host: string) => {
if (running) return;
setRunning(true);
setLogs([]);
eventSource = new EventSource(`${baseUrl()}/admin/tools/ping?X-Auth-Token=${getToken()}&host=${host}&attempts=${attempts}`);
eventSource.onmessage = (event) => {
setLogs((prevLogs) => [...prevLogs, event.data]);
};
eventSource.onerror = () => {
eventSource?.close();
setRunning(false);
};
}
return (
<div className={'flex flex-col gap-4 min-h-[75vh]'}>
<Form layout="inline" className="w-full">
<Form.Item
label={t('sysops.tools.target')}
>
<Input
value={host}
onChange={(e) => setHost(e.target.value)}
placeholder={t('sysops.tools.target_placeholder')}
style={{
width: '200px'
}}
/>
</Form.Item>
<Form.Item
label={t('sysops.tools.attempts')}
tooltip={t('sysops.tools.attempts_tips')}
>
<InputNumber
value={attempts}
onChange={(value) => setAttempts(value || 4)}
min={1}
max={100}
style={{width: '100px'}}
/>
</Form.Item>
<Form.Item>
<Button
type={'primary'}
disabled={!host || running}
onClick={() => onSearch(host)}
>
{t('sysops.tools.testing')}
</Button>
</Form.Item>
</Form>
<div className='border rounded-lg p-4 flex-grow'>
<pre>{logs.join("\n")}</pre>
</div>
</div>
);
};
export default ToolsPing;