import { useEffectEvent } from '../../../hooks/common/useEffectEvent'; import React, { useState, useEffect } from 'react'; import { Card, Row, Col, Typography, Tag, Spin, Empty } from '@/components/ui'; import { API, showError } from '../../../helpers'; import { MODEL_CATEGORY_NAMES } from '../../../constants'; const { Title, Text } = Typography; const ModelsCategoryStats = ({ t }) => { const [stats, setStats] = useState({}); const [loading, setLoading] = useState(false); const loadStats = async () => { setLoading(true); try { const res = await API.get('/api/models/category-stats'); const { success, message, data } = res.data; if (success) { setStats(data || {}); } else { showError(message || t('获取统计数据失败')); } } catch (error) { console.error('Load category stats failed:', error); showError(t('获取统计数据失败')); } setLoading(false); }; const onMount = useEffectEvent(() => { loadStats(); }); useEffect(() => onMount(), [onMount]); const getCategoryColor = (category) => { const colorMap = { text_generation: 'blue', image_generation: 'purple', video_generation: 'pink', audio_tts: 'cyan', audio_stt: 'teal', audio_generation: 'green', embedding: 'violet', multimodal: 'indigo', rerank: 'orange', other: 'grey', }; return colorMap[category] || 'grey'; }; const totalModels = Object.values(stats).reduce( (sum, count) => sum + count, 0, ); if (loading) { return (
); } if (totalModels === 0) { return ( ); } return ( {t('模型分类统计')} {t('总计')}: {totalModels} } style={{ marginBottom: '16px' }} > {Object.entries(MODEL_CATEGORY_NAMES).map(([category, name]) => { const count = stats[category] || 0; const percentage = totalModels > 0 ? ((count / totalModels) * 100).toFixed(1) : 0; return (
{ e.currentTarget.style.transform = 'translateY(-2px)'; e.currentTarget.style.boxShadow = '0 4px 12px rgba(0,0,0,0.1)'; }} onMouseLeave={(e) => { e.currentTarget.style.transform = 'translateY(0)'; e.currentTarget.style.boxShadow = 'none'; }} >
{name}
{count} {percentage}%
); })}
); }; export default ModelsCategoryStats;