You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 4.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import KFIcon from '@/components/KFIcon';
  2. import ModelEvolution from '@/pages/Model/components/ModelEvolution';
  3. import { to } from '@/utils/promise';
  4. import { useParams, useSearchParams } from '@umijs/max';
  5. import { Flex, Tabs } from 'antd';
  6. import { useEffect, useState } from 'react';
  7. import { ResourceData, ResourceType, resourceConfig } from '../../config';
  8. import ResourceVersion from '../ResourceVersion';
  9. import styles from './index.less';
  10. export enum ResourceInfoTabKeys {
  11. Introduction = 'introduction',
  12. Version = 'version',
  13. Evolution = 'evolution',
  14. }
  15. type ResourceIntroProps = {
  16. resourceType: ResourceType;
  17. };
  18. const ResourceIntro = ({ resourceType }: ResourceIntroProps) => {
  19. const [info, setInfo] = useState<ResourceData>({} as ResourceData);
  20. const locationParams = useParams();
  21. const [searchParams] = useSearchParams();
  22. const defaultTab = searchParams.get('tab') || ResourceInfoTabKeys.Introduction;
  23. let versionParam = searchParams.get('version');
  24. const [versionList, setVersionList] = useState([]);
  25. const [version, setVersion] = useState<string | undefined>(undefined);
  26. const [activeTab, setActiveTab] = useState<string>(defaultTab);
  27. const resourceId = Number(locationParams.id);
  28. const config = resourceConfig[resourceType];
  29. const typeName = config.name; // 数据集/模型
  30. useEffect(() => {
  31. getModelByDetail();
  32. getVersionList();
  33. }, [resourceId]);
  34. // 获取详情
  35. const getModelByDetail = async () => {
  36. const request = config.getInfo;
  37. const [res] = await to(request(resourceId));
  38. if (res) {
  39. setInfo(res.data);
  40. }
  41. };
  42. // 获取版本列表
  43. const getVersionList = async () => {
  44. const request = config.getVersions;
  45. const [res] = await to(request(resourceId));
  46. if (res && res.data && res.data.length > 0) {
  47. setVersionList(
  48. res.data.map((item: string) => {
  49. return {
  50. label: item,
  51. value: item,
  52. };
  53. }),
  54. );
  55. if (versionParam) {
  56. setVersion(versionParam);
  57. versionParam = null;
  58. } else {
  59. setVersion(res.data[0]);
  60. }
  61. } else {
  62. setVersion(undefined);
  63. }
  64. };
  65. // 版本变化
  66. const handleVersionChange = (value: string) => {
  67. setVersion(value);
  68. };
  69. const items = [
  70. {
  71. key: ResourceInfoTabKeys.Introduction,
  72. label: `${typeName}简介`,
  73. icon: <KFIcon type="icon-moxingjianjie" />,
  74. children: (
  75. <>
  76. <div className={styles['resource-intro__title']}>简介</div>
  77. <div className={styles['resource-intro__intro']}>{info.description}</div>
  78. </>
  79. ),
  80. },
  81. {
  82. key: ResourceInfoTabKeys.Version,
  83. label: `${typeName}文件/版本`,
  84. icon: <KFIcon type="icon-moxingwenjian" />,
  85. children: (
  86. <ResourceVersion
  87. resourceType={resourceType}
  88. resourceId={resourceId}
  89. resourceName={info.name}
  90. isPublic={info.available_range === 1}
  91. versionList={versionList}
  92. version={version}
  93. isActive={activeTab === ResourceInfoTabKeys.Version}
  94. getVersionList={getVersionList}
  95. onVersionChange={handleVersionChange}
  96. ></ResourceVersion>
  97. ),
  98. },
  99. ];
  100. if (resourceType === ResourceType.Model) {
  101. items.push({
  102. key: ResourceInfoTabKeys.Evolution,
  103. label: `模型演化`,
  104. icon: <KFIcon type="icon-moxingyanhua1" />,
  105. children: (
  106. <ModelEvolution
  107. resourceId={resourceId}
  108. versionList={versionList}
  109. version={version}
  110. isActive={activeTab === ResourceInfoTabKeys.Evolution}
  111. onVersionChange={handleVersionChange}
  112. ></ModelEvolution>
  113. ),
  114. });
  115. }
  116. const infoTypePropertyName = config.infoTypePropertyName as keyof ResourceData;
  117. const infoTagPropertyName = config.infoTagPropertyName as keyof ResourceData;
  118. return (
  119. <div className={styles['resource-intro']}>
  120. <div className={styles['resource-intro__top']}>
  121. <div className={styles['resource-intro__top__name']}>{info.name}</div>
  122. <Flex align="center">
  123. <div className={styles['resource-intro__top__tag']}>
  124. {typeName} id:{info.id}
  125. </div>
  126. {info[infoTypePropertyName] && (
  127. <div className={styles['resource-intro__top__tag']}>
  128. {info[infoTypePropertyName] || '--'}
  129. </div>
  130. )}
  131. {info[infoTagPropertyName] && (
  132. <div className={styles['resource-intro__top__tag']}>
  133. {info[infoTagPropertyName] || '--'}
  134. </div>
  135. )}
  136. </Flex>
  137. </div>
  138. <div className={styles['resource-intro__bottom']}>
  139. <Tabs activeKey={activeTab} items={items} onChange={(key) => setActiveTab(key)}></Tabs>
  140. </div>
  141. </div>
  142. );
  143. };
  144. export default ResourceIntro;