import React from 'react'; interface SkeletonLoaderProps { variant?: 'card' | 'list' | 'text' | 'avatar' | 'button' | 'model' | 'material' | 'template' | 'table-row'; count?: number; className?: string; width?: string; height?: string; } /** * 骨架屏加载组件 * 提供多种预设样式和自定义选项 */ export const SkeletonLoader: React.FC = ({ variant = 'text', count = 1, className = '', width, height }) => { const baseClasses = 'animate-pulse bg-gradient-to-r from-gray-200 via-gray-300 to-gray-200 bg-[length:200%_100%] animate-loading-shimmer rounded-lg'; const getVariantClasses = () => { switch (variant) { case 'card': return 'h-48 w-full'; case 'list': return 'h-16 w-full'; case 'avatar': return 'h-12 w-12 rounded-full'; case 'button': return 'h-10 w-24'; case 'model': return 'h-40 w-full'; case 'material': return 'h-44 w-full'; case 'template': return 'h-52 w-full'; case 'table-row': return 'h-12 w-full'; default: return 'h-4 w-full'; } }; const renderSkeleton = (index: number) => { const variantClasses = getVariantClasses(); const customStyle = { width: width || undefined, height: height || undefined, }; if (variant === 'card') { return (
{/* 卡片头部 */}
{/* 卡片内容 */}
{/* 统计区域 */}
{/* 底部按钮 */}
); } if (variant === 'list') { return (
); } if (variant === 'model') { return (
{/* 模特头像和基本信息 */}
{/* 描述 */}
{/* 标签 */}
{/* 操作按钮 */}
); } if (variant === 'material') { return (
{/* 缩略图 */}
{/* 标题和信息 */}
{/* 进度条 */}
{/* 操作按钮 */}
); } if (variant === 'template') { return (
{/* 预览图 */}
{/* 标题和描述 */}
{/* 统计信息 */}
{/* 操作按钮 */}
); } if (variant === 'table-row') { return (
); } return (
); }; return (
{Array.from({ length: count }, (_, index) => renderSkeleton(index))}
); }; /** * 项目卡片骨架屏 */ export const ProjectCardSkeleton: React.FC<{ count?: number }> = ({ count = 4 }) => { return (
{Array.from({ length: count }, (_, index) => ( ))}
); }; /** * 列表项骨架屏 */ export const ListItemSkeleton: React.FC<{ count?: number }> = ({ count = 5 }) => { return (
{Array.from({ length: count }, (_, index) => ( ))}
); }; /** * 模特卡片骨架屏 */ export const ModelCardSkeleton: React.FC<{ count?: number }> = ({ count = 8 }) => { return (
{Array.from({ length: count }, (_, index) => ( ))}
); }; /** * 素材卡片骨架屏 */ export const MaterialCardSkeleton: React.FC<{ count?: number }> = ({ count = 6 }) => { return (
{Array.from({ length: count }, (_, index) => ( ))}
); }; /** * 模板卡片骨架屏 */ export const TemplateCardSkeleton: React.FC<{ count?: number }> = ({ count = 8 }) => { return (
{Array.from({ length: count }, (_, index) => ( ))}
); }; /** * 表格骨架屏 */ export const TableSkeleton: React.FC<{ rows?: number; columns?: number }> = ({ rows = 5, columns = 4 }) => { return (
{/* 表头 */}
{Array.from({ length: columns }, (_, index) => (
))}
{/* 表格行 */}
{Array.from({ length: rows }, (_, index) => ( ))}
); }; /** * 页面加载骨架屏 */ export const PageLoadingSkeleton: React.FC<{ showHeader?: boolean; showStats?: boolean; cardCount?: number; }> = ({ showHeader = true, showStats = true, cardCount = 6 }) => { return (
{/* 页面头部 */} {showHeader && (
)} {/* 统计卡片 */} {showStats && (
{Array.from({ length: 4 }, (_, index) => (
))}
)} {/* 主要内容 */}
); };