import * as React from 'react'; import { Dropdown, MenuProps, Button } from 'antd'; import { CodeBracketsSquare, EditPencil, Trash, ShareIos, Star, BrightStar, Eye, Heart, Calendar, BadgeCheck, Building, Menu, ArrowRight } from 'iconoir-react'; import './index.scss'; export interface AppCardProps { // 基本信息 id: string; name: string; description: string; icon?: string; iconImage?: string; iconBgColor?: 'blue' | 'indigo' | 'teal' | 'purple' | 'rose' | 'cyan' | 'amber' | 'green' | 'orange'; // 创建者信息 creator?: string; creatorId?: string; proName?: string; // 项目名称 // 标签和认证 tags?: Array<{ label: string; color: 'slate' | 'blue' | 'indigo' | 'teal' | 'purple' | 'rose' | 'cyan' | 'amber'; }>; certification?: string; // 状态标识 isHot?: boolean; status?: 'draft' | 'pending' | 'approved' | 'rejected'; // 统计数据 viewCount?: number; favoriteCount?: number; createTime?: string; // 其他信息 department?: string; visible?: 'public' | 'private' | 'vip'; appId?: string; isCollect?: boolean; isCreator?: boolean; // 显示控制 showCreator?: boolean; showActions?: boolean; showCertification?: boolean; showTags?: boolean; showHot?: boolean; showViewCount?: boolean; showFavoriteCount?: boolean; showCreateTime?: boolean; showStatus?: boolean; showDepartment?: boolean; showVisible?: boolean; showOperations?: boolean; // 回调函数 onPlay?: () => void; onShare?: () => void; onFavorite?: () => void; onEdit?: () => void; onDelete?: () => void; onView?: () => void; onApi?: () => void; onApiDirect?: () => void; // API 调用(非创建者显示) } const AppCard: React.FC = (props) => { const { // 基本信息 name, description, icon, iconImage, iconBgColor = 'blue', // 创建者信息 creator, proName, // 标签和认证 tags = [], certification, // 状态标识 isHot, status, // 统计数据 viewCount, favoriteCount, createTime, // 其他信息 department, visible, isCollect = false, isCreator = false, // 显示控制 showCreator = true, showActions = true, showCertification = true, showTags = true, showHot = true, showViewCount = false, showFavoriteCount = false, showCreateTime = false, showStatus = false, showDepartment = false, showVisible = false, showOperations = false, // 回调函数 onShare, onFavorite, onEdit, onDelete, onView, onApi, onApiDirect, } = props; // 配置对象 const statusConfig = { draft: { label: '草稿', color: '#9CA3AF' }, pending: { label: '审核中', color: '#F59E0B' }, approved: { label: '已通过', color: '#10B981' }, rejected: { label: '已拒绝', color: '#EF4444' }, }; const visibleConfig = { public: { label: '公开', color: '#005D80' }, private: { label: '私有', color: '#6B7280' }, vip: { label: 'VIP', color: '#F59E0B' }, }; // 构建操作菜单项 const operationItems: MenuProps['items'] = React.useMemo(() => { const items: any[] = []; if (onApi) { items.push({ key: 'api', label: 'API 调用', icon: , onClick: () => onApi(), }); } if (isCreator && onEdit) { items.push({ key: 'edit', label: '编辑', icon: , onClick: () => onEdit(), }); } if (isCreator && onDelete) { items.push({ key: 'delete', label: '删除', icon: , danger: true, onClick: () => onDelete(), }); } return items; }, [onApi, onEdit, onDelete, isCreator]); // 事件处理 const handleShareClick = () => { onShare?.(); }; const handleFavoriteClick = () => { onFavorite?.(); }; const handleViewClick = () => { onView?.(); }; return (
{/* Hot 标签 */} {showHot && isHot && ( Hot )} {/* 状态标签 */} {showStatus && status && ( {statusConfig[status].label} )} {/* 操作按钮 - 悬停显示 */} {showActions && (
)} {/* 卡片头部:图标 + 创建者信息 */}
{iconImage ? ( {name} ) : icon ? (
{/* 动态 icon 支持 - 如果传入的是 iconoir 组件名称则渲染,否则显示占位 */}
) : null}
{showCreator && creator && (
创建者 {creator} {proName && ( {proName} )}
)}
{/* 应用名称 */}
{name}
{/* 应用描述 */}

{description}

{/* 标签 */} {showTags && tags.length > 0 && (
{tags.map((tag, index) => ( {tag.label} ))}
)} {/* 统计信息 */} {(showViewCount || showFavoriteCount || showCreateTime) && (
{showViewCount && viewCount !== undefined && ( {viewCount} )} {showFavoriteCount && favoriteCount !== undefined && ( {favoriteCount} )}
{showCreateTime && createTime && (
{createTime}
)}
)} {/* 底部信息:认证/部门/可见性 */} {showCertification && (
{certification && (
{certification}
)} {showDepartment && department && (
{department}
)} {showVisible && visible && ( {visibleConfig[visible].label} )}
)} {/* 悬停操作按钮层 */} {showOperations && (
{/* 创建者显示【更多操作】,非创建者显示【API 调用】 */} {isCreator ? ( ) : ( )}
)}
); }; export default AppCard;