import * as React from 'react'; import { Dropdown, MenuProps, Button } from 'antd'; import { Code, Pen, Trash2, Share2, Star, Eye, Heart, Calendar, BadgeCheck, Building, Menu, ArrowRight } from 'lucide-react'; import AppCardApiDoc from './AppCardApiDoc'; 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; fieldId?: string; // 字段 ID isCollect?: boolean; isCreator?: boolean; isMaintainer?: boolean; // 是否为维护者(非创建者) // 显示控制 showCreator?: boolean; showActions?: boolean; showCertification?: boolean; showTags?: boolean; showHot?: boolean; showViewCount?: boolean; showFavoriteCount?: boolean; showCreateTime?: boolean; showStatus?: boolean; showDepartment?: boolean; showVisible?: boolean; showFieldId?: boolean; // 是否显示字段 ID 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 { // 基本信息 id, name, description, icon, iconImage, iconBgColor = 'blue', // 创建者信息 creator, proName, // 标签和认证 tags = [], certification, // 状态标识 isHot, status, // 统计数据 viewCount, favoriteCount, createTime, // 其他信息 department, visible, appId, fieldId, isCollect = false, isCreator = false, isMaintainer = false, // 显示控制 showCreator = true, showActions = true, showCertification = true, showTags = true, showHot = true, showViewCount = false, showFavoriteCount = false, showCreateTime = false, showStatus = false, showDepartment = false, showVisible = false, showFieldId = false, showOperations = false, // 回调函数 onShare, onFavorite, onEdit, onDelete, onView, onApi, onApiDirect, } = props; // API 文档弹窗状态 const [apiDocOpen, setApiDocOpen] = React.useState(false); // 使用 appId 或 id 作为应用标识 const applicationId = appId || id; // 配置对象 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 || isMaintainer) && 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, isMaintainer]); // 事件处理 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}
{/* 字段 ID */} {showFieldId && fieldId && (
ID: {fieldId}
)} {/* 应用描述 */}

{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 || department || visible) && (
{certification && (
{certification}
)} {showDepartment && department && (
{department}
)} {showVisible && visible && ( {visibleConfig[visible].label} )}
)} {/* 悬停操作按钮层 */} {showOperations && (
{/* 创建者/维护者显示【更多操作】+【立即使用】,非创建者显示【API 接入】+【立即使用】 */} {(isCreator || isMaintainer) ? ( <> ) : ( <> )}
)} {/* API 文档抽屉 */} setApiDocOpen(false)} />
); }; export default AppCard;