'use client'; import { useState } from 'react'; import type { ColumnsType } from 'antd/es/table'; import { Button, Input, Space, Table, Tag } from 'antd'; import { formatUtcTime } from '@/lib/format'; import { usePagedList } from '@/lib/usePagedList'; import type { AuditLog } from '@/lib/types'; // 审计 created_at 为 UTC 口径(server_default now()),按北京显示(勿用 new Date().toLocaleString) const dt = (v: string) => formatUtcTime(v, 'YYYY-MM-DD HH:mm:ss'); export default function AuditLogsPage() { const [action, setAction] = useState(''); const [filters, setFilters] = useState>({}); const { items, total, page, pageSize, loading, onChange: onPageChange } = usePagedList('/admin/api/audit-logs', filters, 50); const search = () => setFilters({ action: action || undefined }); const columns: ColumnsType = [ { title: '时间', dataIndex: 'created_at', render: dt, width: 180 }, { title: '操作者', dataIndex: 'admin_username', width: 120 }, { title: '动作', dataIndex: 'action', render: (a: string) => {a}, width: 170 }, { title: '对象', key: 'target', width: 140, render: (_: unknown, l: AuditLog) => `${l.target_type}${l.target_id ? '#' + l.target_id : ''}`, }, { title: '详情', dataIndex: 'detail', render: (d: Record | null) => d ? {JSON.stringify(d)} : '-', }, { title: 'IP', dataIndex: 'ip', render: (v: string | null) => v || '-', width: 130 }, ]; return (

审计日志

setAction(e.target.value)} onPressEnter={search} allowClear style={{ width: 240 }} /> `共 ${t} 条`, onChange: onPageChange, }} scroll={{ x: 1000 }} /> ); }