diff --git a/apps/web/src/pages/Home.tsx b/apps/web/src/pages/Home.tsx index 2cd75a5..411bcaa 100644 --- a/apps/web/src/pages/Home.tsx +++ b/apps/web/src/pages/Home.tsx @@ -1,37 +1,97 @@ -import { Typography, Card, Row, Col, Statistic } from 'antd'; +import { useEffect, useState } from 'react'; +import { Typography, Card, Row, Col, Statistic, Spin } from 'antd'; import { UserOutlined, TeamOutlined, FileTextOutlined, BellOutlined, } from '@ant-design/icons'; +import client from '../api/client'; +import { useMessageStore } from '../stores/message'; + +interface DashboardStats { + userCount: number; + roleCount: number; + processInstanceCount: number; + unreadMessages: number; +} export default function Home() { + const [stats, setStats] = useState({ + userCount: 0, + roleCount: 0, + processInstanceCount: 0, + unreadMessages: 0, + }); + const [loading, setLoading] = useState(true); + const { unreadCount, fetchUnreadCount } = useMessageStore(); + + useEffect(() => { + async function loadStats() { + setLoading(true); + try { + // 并行请求各模块统计数据 + const [usersRes, rolesRes, instancesRes] = await Promise.allSettled([ + client.get('/users', { params: { page: 1, page_size: 1 } }), + client.get('/roles', { params: { page: 1, page_size: 1 } }), + client.get('/workflow/instances', { params: { page: 1, page_size: 1 } }), + ]); + + const extractTotal = (res: PromiseSettledResult<{ data: { data?: { total?: number } } }>) => + res.status === 'fulfilled' ? (res.value.data?.data?.total ?? 0) : 0; + + setStats({ + userCount: extractTotal(usersRes), + roleCount: extractTotal(rolesRes), + processInstanceCount: extractTotal(instancesRes), + unreadMessages: unreadCount, + }); + } catch { + // 静默处理,显示默认值 + } finally { + setLoading(false); + } + } + + fetchUnreadCount(); + loadStats(); + }, [fetchUnreadCount, unreadCount]); + return (
工作台 - - - - } /> - - - - - } /> - - - - - } /> - - - - - } /> - - - + + + + + } /> + + + + + } /> + + + + + } + /> + + + + + } + /> + + + +
); }