import { useEffect, useState } from 'react'; import { Card, Spin, Statistic, message, Empty, Result, Row, Col } from 'antd'; import { ThunderboltOutlined, ExperimentOutlined, } from '@ant-design/icons'; import { useThemeMode } from '../../hooks/useThemeMode'; import { usePermission } from '../../hooks/usePermission'; import { usageApi, type UsageOverview, type TypeDistribution } from '../../api/ai/usage'; const ANALYSIS_TYPE_MAP: Record = { lab_report_interpretation: '化验单解读', health_trend_analysis: '趋势分析', personalized_checkup_plan: '体检方案', report_summary_generation: '报告摘要', }; const TYPE_COLORS: Record = { lab_report_interpretation: '#1890ff', health_trend_analysis: '#52c41a', personalized_checkup_plan: '#722ed1', report_summary_generation: '#fa8c16', }; export default function AiUsageDashboard() { const { hasPermission } = usePermission('ai.usage.list'); if (!hasPermission) return ; const [overview, setOverview] = useState(null); const [types, setTypes] = useState([]); const [loading, setLoading] = useState(true); const isDark = useThemeMode(); useEffect(() => { const fetchData = async () => { setLoading(true); try { const [ov, tp] = await Promise.all([ usageApi.overview(), usageApi.byType(), ]); setOverview(ov); setTypes(tp); } catch { message.error('加载用量统计失败'); } finally { setLoading(false); } }; fetchData(); }, []); if (loading) { return (
); } const cardStyle = { borderRadius: 12, background: isDark ? '#111827' : '#FFFFFF', border: `1px solid ${isDark ? '#0f172a' : '#f8fafc'}`, }; const totalCount = types.reduce((sum, t) => sum + t.count, 0); return (

AI 用量统计

查看 AI 分析服务的使用情况
} valueStyle={{ fontWeight: 600 }} /> } valueStyle={{ fontWeight: 600 }} /> } valueStyle={{ fontWeight: 600 }} /> {types.length === 0 ? ( ) : ( {types.map((t) => { const pct = totalCount > 0 ? Math.round((t.count / totalCount) * 100) : 0; const label = ANALYSIS_TYPE_MAP[t.analysis_type] || t.analysis_type; const color = TYPE_COLORS[t.analysis_type] || '#1890ff'; return (
{t.count}
{label}
{pct}%
); })}
)}
); }