import { useCallback, useEffect, useState } from 'react'; import { Link } from 'react-router-dom'; import { Button, Card, Col, Descriptions, Modal, Row, Space, Statistic, Table, Typography, message, } from 'antd'; import { CloudUploadOutlined, ReloadOutlined } from '@ant-design/icons'; import { request, type DashboardStats, type DeployTriggerResult, type HqProfile, type SystemVersion, } from '../lib/api'; import { fmtTime } from '../lib/constants'; const STATUS_LABELS: Record = { PENDING_PAY: '待付款', PENDING_SHIP: '待发货', OUT_WAREHOUSE: '已出库', SHIPPING: '配送中', PENDING_RECEIVE: '待收货', COMPLETED: '已完成', CANCELLED: '已取消', REFUNDING: '退款中', REFUNDED: '已退款', }; const DEPLOYED_BY_LABELS: Record = { webhook: 'Webhook', manual: '手动脚本', admin: 'Admin 发布', }; export default function DashboardPage() { const [stats, setStats] = useState(null); const [version, setVersion] = useState(null); const [loading, setLoading] = useState(true); const [versionLoading, setVersionLoading] = useState(true); const [profile, setProfile] = useState(null); const [deploying, setDeploying] = useState(false); const isSuperAdmin = profile?.adminRole === 'SUPER_ADMIN'; const loadVersion = useCallback(() => { setVersionLoading(true); return request('/admin/dashboard/version') .then(setVersion) .catch(() => setVersion(null)) .finally(() => setVersionLoading(false)); }, []); useEffect(() => { request('/admin/dashboard/stats') .then(setStats) .finally(() => setLoading(false)); void loadVersion(); request('/admin/auth/me').then(setProfile).catch(() => {}); }, [loadVersion]); function handleDeploy() { Modal.confirm({ title: '确认发布更新?', content: '将触发服务器 webhook,拉取 auto-release.env 中配置的 GIT_BRANCH 并执行发版。发版通常需要数分钟,完成后可刷新版本信息。', okText: '开始发布', cancelText: '取消', onOk: async () => { setDeploying(true); try { const result = await request('/admin/deploy/trigger', { method: 'POST' }); message.success(result.message || '已触发发布'); } catch (e) { message.error(e instanceof Error ? e.message : '触发发布失败'); throw e; } finally { setDeploying(false); } }, }); } const shortSha = version?.commitId ? version.commitId.slice(0, 7) : '—'; return (
数据概览 {isSuperAdmin && ( )} } > {version ? ( {version.branch || '—'} {version.gitTag || '—'} {shortSha} {version.commitMessage} {fmtTime(version.deployedAt)} {DEPLOYED_BY_LABELS[version.deployedBy || ''] || version.deployedBy || '—'} ) : ( 尚未记录发版信息 )} 去处理} > 0 ? '#fa8c16' : undefined }} /> 合伙人已确认申请,待总部通过或驳回 {(stats?.pendingPartnerDraftBills ?? 0) > 0 ? `(另有 ${stats?.pendingPartnerDraftBills} 笔待合伙人确认)` : ''} 去处理} > 0 ? '#fa8c16' : undefined }} /> STATUS_LABELS[s] || s, }, { title: '数量', dataIndex: 'count' }, ]} /> ); }