"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 { toast } from "sonner"; import { statusMeta } from "@/lib/status"; import type { Finding, FindingStats, FindingStatus, Severity } from "@/lib/types"; const FINDING_STATUSES: FindingStatus[] = [ "pending", "in_progress", "confirmed", "resolved", "false_positive", "ignored", "duplicate", "risk_accepted", ]; const EMPTY_STATS: FindingStats = { total: 0, pending: 0, critical: 0, high: 0, medium: 0, low: 0, vulnclasses: [], }; 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 [status, setStatus] = React.useState<"all" | FindingStatus>("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 [total, setTotal] = React.useState(0); const [stats, setStats] = React.useState(EMPTY_STATS); const [page, setPage] = React.useState(1); const [pageSize, setPageSize] = React.useState(20); // reset to page 1 whenever filters change React.useEffect(() => { setPage(1); }, [severity, status, vulnclass, sort]); // Server-driven list: paging + filtering + sorting all happen in SQL. Polls the // current page every 5s, and refetches immediately when any query input changes. React.useEffect(() => { let alive = true; const load = () => { api .findingsPage({ page, pageSize, severity, status, vulnclass, sort }) .then((res) => { if (!alive) return; setFindings(res.items); setTotal(res.total); }) .catch(() => {}); }; load(); const t = setInterval(load, 5000); return () => { alive = false; clearInterval(t); }; }, [page, pageSize, severity, status, vulnclass, sort]); // Whole-table aggregates (stat cards + vuln-class options) — independent of the // current page, so they stay exact. React.useEffect(() => { let alive = true; const load = () => { api .findingStats() .then((s) => { if (alive) setStats(s); }) .catch(() => {}); }; load(); const t = setInterval(load, 5000); return () => { alive = false; clearInterval(t); }; }, []); // updateStatus optimistically flips one finding's triage state, reverting on error. const updateStatus = React.useCallback( async (f: Finding, next: FindingStatus) => { if (!f.finding_id || next === f.status) return; const prev = f.status; setFindings((cur) => cur.map((x) => (x.id === f.id ? { ...x, status: next } : x)), ); try { await api.setFindingStatus(f.finding_id, next); toast.success(`已标记为「${statusMeta("finding", next).label}」`); // refresh stat cards (pending count) and drop the row if it no longer matches the status filter api.findingStats().then(setStats).catch(() => {}); if (status !== "all" && next !== status) { setFindings((cur) => cur.filter((x) => x.id !== f.id)); setTotal((t) => Math.max(0, t - 1)); } } catch (e) { setFindings((cur) => cur.map((x) => (x.id === f.id ? { ...x, status: prev } : x)), ); toast.error("更新失败:" + (e as Error).message); } }, [status], ); const statCards: { label: string; value: number; tone?: string }[] = [ { label: "发现总数", value: stats.total }, { label: "待处理", value: stats.pending, tone: "text-amber-500" }, { label: "严重", value: stats.critical, tone: "text-rose-600" }, { label: "高危", value: stats.high, tone: "text-red-500" }, { label: "中危", value: stats.medium, tone: "text-amber-500" }, { label: "低危", value: stats.low, tone: "text-slate-500" }, ]; return (

发现

跨任务漏洞汇总

{statCards.map((s) => ( {s.label} {s.value} ))}
{( [ ["all", "全部"], ["critical", "严重"], ["high", "高危"], ["medium", "中危"], ["low", "低危"], ] as const ).map(([val, label]) => ( ))}
共 {total} 条
严重度 漏洞名称 资产 状态 所属任务 时间 {findings.map((f) => { const open = expanded === f.id; return ( setExpanded(open ? null : f.id)} >
{f.name || f.vulnclass || "未分类"} {f.summary}
{f.assets && f.assets.length > 0 ? (
{f.assets.slice(0, 3).map((a) => ( {a.label} ))} {f.assets.length > 3 && ( +{f.assets.length - 3} )}
) : ( — )}
e.stopPropagation()}> {f.finding_id ? ( ) : ( )} {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.vulnclass && ( · 类型: {f.vulnclass} )} {f.param_id && ( {f.param_id} )} {f.assets && f.assets.length > 0 && ( · 资产: {f.assets.map((a) => ( {a.label} ))} )}
                                {f.evidence}
                              
)}
); })} {findings.length === 0 && ( 没有匹配的发现。 )}
); }