import { History, ShieldCheck } from 'lucide-react';
import type { GatewayAuditLog } from '@easyai-ai-gateway/contracts';
import { Badge, Card, CardContent, CardHeader, CardTitle, Table, TableCell, TableHead, TableRow } from '../../components/ui';
export function AuditLogsPanel(props: { auditLogs: GatewayAuditLog[]; message?: string }) {
return (
审计日志
敏感管理动作独立记录,便于追踪操作者、对象和前后状态。
{props.auditLogs.length}
{props.message && {props.message}
}
{props.auditLogs.length ? (
动作
操作者
目标
摘要
时间
{props.auditLogs.map((item) => (
{actionLabel(item.action)}
{item.category}
{item.actorUsername || item.actorUserId || '系统'}
{targetLabel(item.targetType)}
{shortId(item.targetId)}
{auditSummary(item)}
{formatDateTime(item.createdAt)}
))}
) : (
暂无审计日志
后台余额调整后会在这里留下独立记录。
)}
);
}
function actionLabel(action: string) {
if (action === 'wallet.balance.set') return '余额调整';
return action;
}
function targetLabel(targetType: string) {
if (targetType === 'gateway_user') return '用户';
return targetType;
}
function auditSummary(item: GatewayAuditLog) {
const metadata = item.metadata ?? {};
const direction = typeof metadata.direction === 'string' ? metadata.direction : '';
const amount = typeof metadata.amount === 'number' ? metadata.amount : undefined;
const currency = typeof metadata.currency === 'string' ? metadata.currency : 'resource';
const reason = typeof metadata.reason === 'string' ? metadata.reason : '';
const prefix = amount === undefined ? '' : `${direction === 'debit' ? '-' : '+'}${formatBalance(amount)} ${currency}`;
return [prefix, reason].filter(Boolean).join(' · ') || '已记录';
}
function formatDateTime(value: string) {
return value ? new Date(value).toLocaleString() : '-';
}
function formatBalance(value: number) {
return new Intl.NumberFormat('zh-CN', { maximumFractionDigits: 6 }).format(value);
}
function shortId(value: string) {
return value.length > 12 ? `${value.slice(0, 8)}...${value.slice(-4)}` : value;
}