import React from 'react' import { Provider, ProviderStatus } from '../../shared/types' import './ProviderList.css' interface ProviderListProps { providers: Record currentProviderId: string statuses: Record checkingStatus: Record onSwitch: (id: string) => void onDelete: (id: string) => void onEdit: (id: string) => void onCheckStatus: (id: string) => void } const ProviderList: React.FC = ({ providers, currentProviderId, statuses, checkingStatus, onSwitch, onDelete, onEdit, onCheckStatus }) => { const formatResponseTime = (time: number) => { if (time < 0) return '-' return `${time}ms` } const getStatusIcon = (status?: ProviderStatus) => { if (!status) return '⏳' return status.isOnline ? '✅' : '❌' } const getStatusText = (status?: ProviderStatus, isChecking?: boolean) => { if (isChecking) return '检查中...' if (!status) return '未检查' if (status.isOnline) return '正常' return status.error || '连接失败' } return (
{Object.values(providers).length === 0 ? (

还没有添加任何供应商

点击右上角的"添加供应商"按钮开始

) : (
{Object.values(providers).map((provider) => { const status = statuses[provider.id] const isChecking = checkingStatus[provider.id] const isCurrent = provider.id === currentProviderId return (
onSwitch(provider.id)} disabled={!status?.isOnline} /> {provider.name} {isCurrent && 当前使用}
{provider.apiUrl}
{isChecking ? '🔄' : getStatusIcon(status)} {getStatusText(status, isChecking)} {status?.isOnline && !isChecking && ( {formatResponseTime(status.responseTime)} )}
) })}
)}
) } export default ProviderList