import { Box, Flex, Text, Tooltip, Button } from '@chakra-ui/react'; import type { AppListItemType } from '@fastgpt/global/core/app/type.d'; import Avatar from '@fastgpt/web/components/common/Avatar'; import { useRouter } from 'next/router'; import React from 'react'; import { useTranslation } from 'next-i18next'; type Props = { app: AppListItemType; selectedId?: string; tagMap?: Map; }; const MAX_VISIBLE_TAGS = 2; const AppCard = ({ app, selectedId, tagMap }: Props) => { const router = useRouter(); const { t } = useTranslation(); const tags = app.tags || []; const visibleTags = tags.slice(0, MAX_VISIBLE_TAGS); const remainingCount = Math.max(0, tags.length - MAX_VISIBLE_TAGS); const renderTags = (showAll = false) => { const tagsToShow = showAll ? tags : visibleTags; return ( {tagsToShow.map((tagId) => { const tag = tagMap?.get(tagId); if (!tag) return null; return ( {tag.name} ); })} {!showAll && remainingCount > 0 && ( {tags.slice(MAX_VISIBLE_TAGS).map((tagId) => { const tag = tagMap?.get(tagId); if (!tag) return null; return ( {tag.name} ); })} } hasArrow placement="top" bg="white" color="inherit" p={0} boxShadow="lg" > +{remainingCount} )} ); }; return ( { // 防止按钮点击事件冒泡 if ((e.target as HTMLElement).tagName !== 'BUTTON') { router.push(`/chat/gate/application?appId=${app._id}`); } }} > {/* 头部区域 */} {/* 图标 */} {app.avatar ? ( ) : ( {app.name[0]?.toUpperCase()} )} {/* 文本信息 */} {app.name} {app.intro || '-'} {/* 底部标签区域 */} {/* 标签容器 */} {renderTags()} {/* 试用按钮 */} ); }; export default AppCard;