import KFIcon from '@/components/KFIcon'; import ModelEvolution from '@/pages/Model/components/ModelEvolution'; import { to } from '@/utils/promise'; import { useParams, useSearchParams } from '@umijs/max'; import { Flex, Tabs } from 'antd'; import { useEffect, useState } from 'react'; import { ResourceData, ResourceType, resourceConfig } from '../../config'; import ResourceVersion from '../ResourceVersion'; import styles from './index.less'; export enum ResourceInfoTabKeys { Introduction = 'introduction', Version = 'version', Evolution = 'evolution', } type ResourceIntroProps = { resourceType: ResourceType; }; const ResourceIntro = ({ resourceType }: ResourceIntroProps) => { const [info, setInfo] = useState({} as ResourceData); const locationParams = useParams(); const [searchParams] = useSearchParams(); const defaultTab = searchParams.get('tab') || ResourceInfoTabKeys.Introduction; let versionParam = searchParams.get('version'); const [versionList, setVersionList] = useState([]); const [version, setVersion] = useState(undefined); const [activeTab, setActiveTab] = useState(defaultTab); const resourceId = Number(locationParams.id); const config = resourceConfig[resourceType]; const typeName = config.name; // 数据集/模型 useEffect(() => { getModelByDetail(); getVersionList(); }, [resourceId]); // 获取详情 const getModelByDetail = async () => { const request = config.getInfo; const [res] = await to(request(resourceId)); if (res) { setInfo(res.data); } }; // 获取版本列表 const getVersionList = async () => { const request = config.getVersions; const [res] = await to(request(resourceId)); if (res && res.data && res.data.length > 0) { setVersionList( res.data.map((item: string) => { return { label: item, value: item, }; }), ); if (versionParam) { setVersion(versionParam); versionParam = null; } else { setVersion(res.data[0]); } } else { setVersion(undefined); } }; // 版本变化 const handleVersionChange = (value: string) => { setVersion(value); }; const items = [ { key: ResourceInfoTabKeys.Introduction, label: `${typeName}简介`, icon: , children: ( <>
简介
{info.description}
), }, { key: ResourceInfoTabKeys.Version, label: `${typeName}文件/版本`, icon: , children: ( ), }, ]; if (resourceType === ResourceType.Model) { items.push({ key: ResourceInfoTabKeys.Evolution, label: `模型演化`, icon: , children: ( ), }); } const infoTypePropertyName = config.infoTypePropertyName as keyof ResourceData; const infoTagPropertyName = config.infoTagPropertyName as keyof ResourceData; return (
{info.name}
{typeName} id:{info.id}
{info[infoTypePropertyName] && (
{info[infoTypePropertyName] || '--'}
)} {info[infoTagPropertyName] && (
{info[infoTagPropertyName] || '--'}
)}
setActiveTab(key)}>
); }; export default ResourceIntro;