import { useEffect, useRef, useState } from 'react' import { Row, Col, Card, Statistic, Timeline, Spin } from 'antd' import { UserOutlined, TeamOutlined, FileOutlined, WarningOutlined } from '@ant-design/icons' import { userApi } from '@/api/user.api' import { roleApi } from '@/api/role.api' import { exceptionLogApi } from '@/api/exceptionLog' import { operationLogApi } from '@/api/operationLog' interface DashboardData { userCount: number roleCount: number opLogCount: number exLogCount: number recentOps: { operation: string; username: string; time: string }[] } export default function Dashboard() { const [data, setData] = useState({ userCount: 0, roleCount: 0, opLogCount: 0, exLogCount: 0, recentOps: [], }) const [loading, setLoading] = useState(true) const chartRef = useRef(null) async function loadDashboard() { try { const [users, roles, opLogs, exLogs] = await Promise.all([ userApi.getAll().catch(() => []), roleApi.getAll().catch(() => []), operationLogApi.getCount().catch(() => 0), exceptionLogApi.getCount().catch(() => 0), ]) setData({ userCount: Array.isArray(users) ? users.length : 0, roleCount: Array.isArray(roles) ? roles.length : 0, opLogCount: typeof opLogs === 'number' ? opLogs : 0, exLogCount: typeof exLogs === 'number' ? exLogs : 0, recentOps: [], }) } finally { setLoading(false) } } useEffect(() => { loadDashboard() }, []) if (loading) { return } return (
} /> } /> } /> } valueStyle={{ color: data.exLogCount > 0 ? '#cf1322' : undefined }} />

G2 图表区域 (待集成 @antv/g2)

0 ? data.recentOps.map((op) => ({ children: `${op.username}: ${op.operation}`, color: 'blue' })) : [{ children: '暂无最近操作记录', color: 'gray' }]} />
) }