Files
cc-switch/src/renderer/components/ProviderList.tsx

82 lines
2.5 KiB
TypeScript
Raw Normal View History

2025-08-04 22:16:26 +08:00
import React from 'react'
import { Provider } from '../../shared/types'
2025-08-04 22:16:26 +08:00
import './ProviderList.css'
interface ProviderListProps {
providers: Record<string, Provider>
currentProviderId: string
onSwitch: (id: string) => void
onDelete: (id: string) => void
onEdit: (id: string) => void
2025-08-04 22:16:26 +08:00
}
const ProviderList: React.FC<ProviderListProps> = ({
providers,
currentProviderId,
onSwitch,
onDelete,
onEdit
2025-08-04 22:16:26 +08:00
}) => {
return (
<div className="provider-list">
{Object.values(providers).length === 0 ? (
<div className="empty-state">
<p></p>
<p>"添加供应商"</p>
</div>
) : (
<div className="provider-items">
{Object.values(providers).map((provider) => {
const isCurrent = provider.id === currentProviderId
return (
<div
key={provider.id}
className={`provider-item ${isCurrent ? 'current' : ''}`}
>
<div className="provider-info">
<div className="provider-name">
<input
type="radio"
name="provider"
checked={isCurrent}
onChange={() => onSwitch(provider.id)}
/>
<span>{provider.name}</span>
{isCurrent && <span className="current-badge">使</span>}
</div>
<div className="provider-url">{provider.apiUrl}</div>
</div>
<div className="provider-actions">
<button
className="enable-btn"
onClick={() => onSwitch(provider.id)}
disabled={isCurrent}
>
</button>
<button
className="edit-btn"
onClick={() => onEdit(provider.id)}
>
</button>
2025-08-04 22:16:26 +08:00
<button
className="delete-btn"
onClick={() => onDelete(provider.id)}
disabled={isCurrent}
2025-08-04 22:16:26 +08:00
>
</button>
</div>
</div>
)
})}
</div>
)}
</div>
)
}
export default ProviderList