import React from 'react'; import { cn } from '@/lib/utils'; import { Loader2, AlertCircle, CheckCircle2, XCircle, Inbox } from 'lucide-react'; /** * 控制台状态面板组件 * 统一展示 loading/empty/error/success/disabled 状态 */ type PanelState = 'loading' | 'empty' | 'error' | 'success' | 'disabled'; interface StatePanelProps { /** 面板状态 */ state: PanelState; /** 标题 */ title?: string; /** 描述信息 */ description?: string; /** 错误时的错误信息 */ error?: string; /** 自定义图标 */ icon?: React.ReactNode; /** 操作按钮 */ action?: React.ReactNode; /** 额外的 className */ className?: string; } // 状态图标映射 const stateIcons: Record = { loading: , empty: , error: , success: , disabled: , }; // 状态默认文案 const stateTexts: Record = { loading: { title: '加载中', description: '正在获取数据...' }, empty: { title: '暂无数据', description: '当前没有可显示的内容' }, error: { title: '加载失败', description: '数据获取出错,请稍后重试' }, success: { title: '操作成功', description: '已完成' }, disabled: { title: '已禁用', description: '此功能当前不可用' }, }; /** * 状态面板组件 * 用于控制台中统一展示各种状态场景 */ export function StatePanel({ state, title, description, error, icon, action, className, }: StatePanelProps) { const defaults = stateTexts[state]; const displayTitle = title || defaults.title; const displayDescription = error || description || defaults.description; return (
{/* 图标 */}
{icon || stateIcons[state]}
{/* 标题 */}

{displayTitle}

{/* 描述 */}

{displayDescription}

{/* 操作按钮 */} {action && (
{action}
)}
); }