// 终端审计 — 会话命令子面板 // Logan.Li import { useMemo, useState } from 'react'; import { Card, CardContent } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@/components/ui/table'; import { Search, RefreshCw } from 'lucide-react'; import { useSessionCommands } from '@/hooks/api'; import { formatSize } from './helpers'; export function SessionCommandsPanel() { const [keyword, setKeyword] = useState(''); const [sessionIdInput, setSessionIdInput] = useState(''); const queryParams = useMemo( () => ({ page: 1, page_size: 200, ...(sessionIdInput ? { session_id: Number(sessionIdInput) } : {}), }), [sessionIdInput], ); const { data: commands = [], isLoading, refetch } = useSessionCommands(queryParams); const filtered = commands.filter((c) => { const kw = keyword.toLowerCase(); return ( !kw || (c.username || '').toLowerCase().includes(kw) || (c.command || '').toLowerCase().includes(kw) ); }); return ( <>
setKeyword(e.target.value)} className="pl-9 h-9 bg-slate-800/50 border-slate-700 text-slate-200 placeholder:text-slate-500" />
setSessionIdInput(e.target.value)} className="w-32 h-9 bg-slate-800/50 border-slate-700 text-slate-200 placeholder:text-slate-500" />
{isLoading ? (
) : filtered.length === 0 ? (

暂无会话命令记录

) : ( 时间 用户 命令 输出大小 关联会话 {filtered.map((c) => ( {c.created_at ? new Date(c.created_at).toLocaleString() : '--'} {c.username || '--'} {c.command || '--'} {formatSize(c.output_size)} #{c.session_id} ))}
)}
); }