"use client"; import * as React from "react"; import Link from "next/link"; import { ChevronRightIcon, ShieldAlertIcon, ArrowUpRightIcon, } from "lucide-react"; import { StatusBadge } from "@/components/status-badge"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { TablePagination } from "@/components/table-pagination"; import { cn } from "@/lib/utils"; import { api } from "@/lib/api"; import type { Finding, Severity } from "@/lib/types"; const SEVERITY_ORDER: Record = { high: 3, medium: 2, low: 1 }; function fmtTime(ts: string) { return new Date(ts).toLocaleString("zh-CN", { month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", }); } export default function FindingsPage() { const [severity, setSeverity] = React.useState<"all" | Severity>("all"); const [vulnclass, setVulnclass] = React.useState("all"); const [sort, setSort] = React.useState<"severity" | "time">("severity"); const [expanded, setExpanded] = React.useState(null); const [findings, setFindings] = React.useState([]); const [page, setPage] = React.useState(1); const [pageSize, setPageSize] = React.useState(20); React.useEffect(() => { let alive = true; const load = () => { api .findings() .then((fs) => { if (alive) setFindings(fs); }) .catch(() => {}); }; load(); const t = setInterval(load, 5000); return () => { alive = false; clearInterval(t); }; }, []); const vulnclasses = React.useMemo( () => Array.from(new Set(findings.map((f) => f.vulnclass))).sort(), [findings], ); const counts = React.useMemo(() => { const c = { high: 0, medium: 0, low: 0 }; for (const f of findings) c[f.severity]++; const tasks = new Set(findings.map((f) => f.task_id)).size; return { ...c, total: findings.length, tasks }; }, [findings]); const rows = React.useMemo(() => { let list = findings.slice(); if (severity !== "all") list = list.filter((f) => f.severity === severity); if (vulnclass !== "all") list = list.filter((f) => f.vulnclass === vulnclass); list.sort((a, b) => { if (sort === "severity") { const d = SEVERITY_ORDER[b.severity] - SEVERITY_ORDER[a.severity]; if (d !== 0) return d; } return new Date(b.ts).getTime() - new Date(a.ts).getTime(); }); return list; }, [findings, severity, vulnclass, sort]); // reset to page 1 whenever filters change React.useEffect(() => { setPage(1); }, [severity, vulnclass, sort]); const paginated = React.useMemo( () => rows.slice((page - 1) * pageSize, page * pageSize), [rows, page, pageSize], ); const statCards: { label: string; value: number; tone?: string }[] = [ { label: "发现总数", value: counts.total }, { label: "高危", value: counts.high, tone: "text-red-500" }, { label: "中危", value: counts.medium, tone: "text-amber-500" }, { label: "低危", value: counts.low, tone: "text-slate-500" }, { label: "涉及任务", value: counts.tasks }, ]; return (

发现

跨任务漏洞汇总

{statCards.map((s) => ( {s.label} {s.value} ))}
{( [ ["all", "全部"], ["high", "高危"], ["medium", "中危"], ["low", "低危"], ] as const ).map(([val, label]) => ( ))}
共 {rows.length} 条
严重度 漏洞类型 摘要 所属任务 时间 {paginated.map((f) => { const open = expanded === f.id; return ( setExpanded(open ? null : f.id)} > {f.vulnclass} {f.summary} {f.task_id ? ( e.stopPropagation()} className="inline-flex max-w-full items-center gap-1 text-primary hover:underline" title={f.task_description} > {f.task_description} ) : ( — )} {fmtTime(f.ts)} {open && (
证据 · {f.id} {f.param_id && ( {f.param_id} )}
                                {f.evidence}
                              
)}
); })} {rows.length === 0 && ( 没有匹配的发现。 )}
); }