import React from 'react'; import { AlertCircle, RefreshCw, X, AlertTriangle, Info, CheckCircle } from 'lucide-react'; interface ErrorMessageProps { message: string; type?: 'error' | 'warning' | 'info' | 'success'; onRetry?: () => void; onDismiss?: () => void; title?: string; } /** * 增强的消息组件 * 支持多种消息类型和更好的视觉设计 */ export const ErrorMessage: React.FC = ({ message, type = 'error', onRetry, onDismiss, title }) => { const getConfig = () => { switch (type) { case 'warning': return { bgColor: 'bg-yellow-50', borderColor: 'border-yellow-200', textColor: 'text-yellow-800', iconColor: 'text-yellow-600', icon: AlertTriangle, defaultTitle: '警告' }; case 'info': return { bgColor: 'bg-blue-50', borderColor: 'border-blue-200', textColor: 'text-blue-800', iconColor: 'text-blue-600', icon: Info, defaultTitle: '信息' }; case 'success': return { bgColor: 'bg-green-50', borderColor: 'border-green-200', textColor: 'text-green-800', iconColor: 'text-green-600', icon: CheckCircle, defaultTitle: '成功' }; default: return { bgColor: 'bg-red-50', borderColor: 'border-red-200', textColor: 'text-red-800', iconColor: 'text-red-600', icon: AlertCircle, defaultTitle: '错误' }; } }; const config = getConfig(); const Icon = config.icon; return (
{/* 图标 */}
{/* 内容 */}
{/* 标题 */} {(title || config.defaultTitle) && (

{title || config.defaultTitle}

)} {/* 消息内容 */}

{message}

{/* 操作按钮 */} {(onRetry || onDismiss) && (
{onRetry && ( )} {onDismiss && ( )}
)}
{/* 右上角关闭按钮 */} {onDismiss && ( )}
); };