import { useEffect, useState } from 'react' import { Card, Button, Typography, Space, Badge, Spin, Row, Col } from 'antd' import { ReloadOutlined } from '@ant-design/icons' import { apiService } from '../services/api' import { useTranslation } from 'react-i18next' import { useMediaQuery } from 'react-responsive' const { Title, Text } = Typography interface ApiHealthStatus { name: string url: string status: string message: string responseTime?: number } const ApiHealthStatus: React.FC = () => { const { t } = useTranslation() const isMobile = useMediaQuery({ maxWidth: 768 }) const [apiHealthStatus, setApiHealthStatus] = useState([]) const [checkingApiHealth, setCheckingApiHealth] = useState(false) useEffect(() => { checkApiHealth() }, []) const checkApiHealth = async () => { setCheckingApiHealth(true) try { const response = await apiService.proxyConfig.checkApiHealth() if (response.data.code === 0 && response.data.data) { setApiHealthStatus(response.data.data.apis) } else { // message.error(response.data.msg || 'API 健康检查失败') } } catch (error: any) { // message.error(error.message || 'API 健康检查失败') } finally { setCheckingApiHealth(false) } } const getStatusColor = (status: string) => { if (status === 'success') { return '#52c41a' } else if (status === 'skipped') { return '#999' } else { return '#ff4d4f' } } const getStatusText = (status: string) => { if (status === 'success') { return t('apiHealthStatus.normal') || '正常' } else if (status === 'skipped') { return t('apiHealthStatus.notConfigured') || '未配置' } else { return t('apiHealthStatus.abnormal') || '异常' } } return (
{t('apiHealthStatus.title') || 'API 健康状态'}
} onClick={checkApiHealth} loading={checkingApiHealth} size="small" > {t('common.refresh') || '刷新'} } > {apiHealthStatus.map((item, index) => ( {isMobile ? (
{item.name} {item.responseTime !== undefined && item.responseTime !== null && ( {item.responseTime}ms )}
{item.url}
{item.message && item.message !== '连接成功' && (
{item.message}
)}
) : (
{item.name}
{item.url}
{item.message && item.message !== '连接成功' && (
{item.message}
)} {item.responseTime !== undefined && item.responseTime !== null && (
{t('apiHealthStatus.responseTime') || '响应时间'}: {item.responseTime}ms
)}
)} ))}
) } export default ApiHealthStatus