import { useRef, useState, useEffect, forwardRef, useImperativeHandle } from 'react'; import { Button, Space, App, Divider, Flex, Tooltip } from 'antd' import { UsergroupAddOutlined } from '@ant-design/icons'; import { useTranslation } from 'react-i18next'; import type { ModelPlaza, ModelPlazaItem, ModelSquareDetailRef, BaseRef } from './types' import RbCard from '@/components/RbCard/Card' import { getModelPlaza, addModelPlaza } from '@/api/models' import PageEmpty from '@/components/Empty/PageEmpty'; import Tag from '@/components/Tag'; import ModelSquareDetail from './components/ModelSquareDetail' import { getLogoUrl } from './utils' const ModelSquare = forwardRef void; }>(({ query, handleEdit }, ref) => { const { t } = useTranslation(); const { message } = App.useApp() const modelSquareDetailRef = useRef(null) const [list, setList] = useState([]) useEffect(() => { getList() }, [query]) const getList = () => { getModelPlaza(query) .then(res => { setList((res as ModelPlaza[]) || []) }) } const handleMore = (vo: ModelPlaza) => { modelSquareDetailRef.current?.handleOpen(vo) } const handleAdd = (item: ModelPlazaItem) => { addModelPlaza(item.id) .then(() => { message.success(`${item.name}${t('modelNew.addSuccess')}`) getList() }) } useImperativeHandle(ref, () => ({ getList, })); return ( <> {list.length === 0 ? : list.map(vo => (
{t(`modelNew.${vo.provider}`)}
{vo.models.slice(0, 6).map(item => ( {t(`modelNew.${item.type}`)}} avatarUrl={getLogoUrl(item.logo)} avatar={
{item.name[0]}
} bodyClassName="rb:relative rb:pb-[80px]! rb:h-[calc(100%-64px)]!" >
{item.description}
{item.tags.map((tag, tagIndex) => {tag})}
{item.add_count} {!item.is_official && } {item.is_added ? : }
))}
)) } ) }) export default ModelSquare