"use client"; /** 权限与合规:查看三类角色权限范围、审计日志与越权拒绝事件(可按操作者过滤)。 */ import { useCallback, useEffect, useState } from "react"; import { ShieldCheck } from "lucide-react"; import { EmptyState, ErrorBanner, Loading, PageHeading, } from "@/components/feedback"; import { Button } from "@/components/ui/button"; import { Card, CardAction, CardContent, CardHeader, CardTitle, } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { UsageGuide } from "@/components/usage-guide"; import { ApiError } from "@/lib/api"; import { adminComplianceApi } from "@/lib/services"; /* eslint-disable @typescript-eslint/no-explicit-any */ export default function AdminCompliancePage() { const [scopes, setScopes] = useState([]); const [auditLogs, setAuditLogs] = useState([]); const [denials, setDenials] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [actorId, setActorId] = useState(""); const load = useCallback(async () => { setLoading(true); setError(null); try { const [sc, logs, dn] = await Promise.all([ adminComplianceApi.permissionScopes(), adminComplianceApi.auditLogs(actorId || undefined), adminComplianceApi.denialEvents(actorId || undefined), ]); setScopes(Array.isArray(sc) ? sc : []); setAuditLogs(Array.isArray(logs) ? logs : []); setDenials(Array.isArray(dn) ? dn : []); } catch (err) { setError(err instanceof ApiError ? err.message : "加载失败"); } finally { setLoading(false); } }, [actorId]); useEffect(() => { load(); }, [load]); return (
} title="权限与合规" description="查看角色权限范围、审计日志与越权拒绝事件。" /> 角色权限范围 {loading ? ( ) : error ? ( ) : (
{scopes.map((sc: any, i: number) => (

{sc.role}

    {(sc.permissions ?? []).map((p: any, pi: number) => (
  • {typeof p === "string" ? ( <>· {p} ) : ( <> ·{" "} {p.resourceType} : {Array.isArray(p.actions) ? p.actions.join(" / ") : ""} )}
  • ))}
))}
)}
审计与越权事件
setActorId(e.target.value)} placeholder="按操作者标识过滤" />

审计日志({auditLogs.length})

{auditLogs.length === 0 ? ( ) : (
    {auditLogs.map((log: any, i: number) => (
  •                         {JSON.stringify(log, null, 2)}
                          
  • ))}
)}

越权拒绝事件({denials.length})

{denials.length === 0 ? ( ) : (
    {denials.map((d: any, i: number) => (
  •                         {JSON.stringify(d, null, 2)}
                          
  • ))}
)}
); }