import { useEffect, useState, type ReactNode } from 'react' import { Card, Col, Progress, Row, Space, Statistic, Typography, Spin, message, Tag } from 'antd' import { ApiOutlined, CheckCircleOutlined, ClockCircleOutlined, CloseCircleOutlined, CodeOutlined, DatabaseOutlined, DollarOutlined, FileTextOutlined, PlusOutlined, ShopOutlined, ShoppingOutlined, TeamOutlined, WalletOutlined, } from '@ant-design/icons' import { useNavigate } from 'react-router-dom' import { dashboardApi } from '../api' import type { DashboardStats } from '../types' import { PageHeader } from '../components/PageHeader' import { useAuth } from '../store/auth' const numberText = (value?: number) => (value ?? 0).toLocaleString('zh-CN') function ratio(part: number, total: number) { if (total <= 0) return 0 return Math.round((part / total) * 100) } function ModernMetricCard({ title, value, icon, unit = '', iconTheme = '', footerText, footerValue, }: { title: string value: number icon: ReactNode unit?: string iconTheme?: string footerText?: string footerValue?: string | number }) { return (
{title}
{icon}
{numberText(value)} {unit && {unit}}
{footerText && (
{footerText} {footerValue}
)}
) } function CustomStatusLine({ label, value, total, color, tagClass, }: { label: string value: number total: number color: string tagClass: string }) { const percent = ratio(value, total) return (
{label}
{numberText(value)} 单 ({percent}%)
) } export default function Dashboard() { const [stats, setStats] = useState(null) const [loading, setLoading] = useState(true) const { user, isAdmin } = useAuth() const navigate = useNavigate() useEffect(() => { dashboardApi .stats() .then(setStats) .catch((e) => message.error(e.message)) .finally(() => setLoading(false)) }, []) if (loading) { return (
) } return (
{stats?.scope === 'platform' ? '全局视图' : '商户视图'} } /> {/* 顶部欢迎卡片 & 快捷 LaunchPad */}

你好,{user?.nickname || user?.username} 👋

欢迎回到 Skin Hub 游戏皮肤分销管理平台。以下是系统的最新业务状态与发货订单追踪数据。

{isAdmin && ( <> )}
{/* 第一组:核心业务指标 */} 基础数据指标 } iconTheme="" footerText="活跃商品库" footerValue="已上线" /> } iconTheme="metric-card-icon--purple" footerText="商户状态" footerValue="正常运行" /> } iconTheme="metric-card-icon--emerald" footerText="团队成员" footerValue="活跃" /> } iconTheme="metric-card-icon--amber" footerText="今日新增订单" footerValue={`${stats?.today_order_count ?? 0} 单`} /> } iconTheme="" footerText="占比全量" footerValue={`${ratio(stats?.today_order_count ?? 0, stats?.order_count ?? 0)}%`} /> } iconTheme={(stats?.paid_order_count ?? 0) > 0 ? 'metric-card-icon--rose' : ''} footerText="需及时发货" footerValue={(stats?.paid_order_count ?? 0) > 0 ? '需处理' : '无积压'} /> {/* 第二组:积分与资金监控 */} 积分变动与账户额度 } iconTheme="metric-card-icon--emerald" /> } iconTheme="metric-card-icon--amber" /> } iconTheme="metric-card-icon--purple" /> } iconTheme="" /> {/* 第三组:订单发货分布与 API 监控 */} } suffix={`/ ${numberText(stats?.api_client_count)}`} /> } /> } /> } valueStyle={(stats?.failed_callback_count ?? 0) > 0 ? { color: '#dc2626' } : undefined} />
) }