| @@ -4,7 +4,7 @@ import KFModal from '@/components/KFModal'; | |||||
| import { CategoryData, DataSource, ResourceType, resourceConfig } from '@/pages/Dataset/config'; | import { CategoryData, DataSource, ResourceType, resourceConfig } from '@/pages/Dataset/config'; | ||||
| import { addDataset } from '@/services/dataset/index.js'; | import { addDataset } from '@/services/dataset/index.js'; | ||||
| import { to } from '@/utils/promise'; | import { to } from '@/utils/promise'; | ||||
| import { getFileListFromEvent, validateUploadFiles } from '@/utils/ui'; | |||||
| import { getFileListFromEvent, limitUploadFileType, validateUploadFiles } from '@/utils/ui'; | |||||
| import { | import { | ||||
| Button, | Button, | ||||
| Form, | Form, | ||||
| @@ -42,6 +42,8 @@ function AddDatasetModal({ typeList, tagList, onOk, ...rest }: AddDatasetModalPr | |||||
| Authorization: getAccessToken() || '', | Authorization: getAccessToken() || '', | ||||
| }, | }, | ||||
| defaultFileList: [], | defaultFileList: [], | ||||
| accept: '.zip,.tgz', | |||||
| beforeUpload: limitUploadFileType('zip,tgz'), | |||||
| }; | }; | ||||
| // 获取集群版本数据 | // 获取集群版本数据 | ||||
| @@ -200,7 +202,7 @@ function AddDatasetModal({ typeList, tagList, onOk, ...rest }: AddDatasetModalPr | |||||
| }, | }, | ||||
| ]} | ]} | ||||
| > | > | ||||
| <Upload {...uploadProps} data={{ uuid: uuid }} accept=".zip,.tgz"> | |||||
| <Upload {...uploadProps} data={{ uuid: uuid }}> | |||||
| <Button | <Button | ||||
| className={styles['upload-button']} | className={styles['upload-button']} | ||||
| type="default" | type="default" | ||||
| @@ -21,8 +21,9 @@ import styles from '../AddDatasetModal/index.less'; | |||||
| interface AddVersionModalProps extends Omit<ModalProps, 'onOk'> { | interface AddVersionModalProps extends Omit<ModalProps, 'onOk'> { | ||||
| resourceType: ResourceType; | resourceType: ResourceType; | ||||
| resourceId: number; | resourceId: number; | ||||
| identifier: string; | |||||
| resoureName: string; | resoureName: string; | ||||
| owner: string; | |||||
| identifier: string; | |||||
| is_public: boolean; | is_public: boolean; | ||||
| onOk: () => void; | onOk: () => void; | ||||
| } | } | ||||
| @@ -31,6 +32,7 @@ function AddVersionModal({ | |||||
| resourceType, | resourceType, | ||||
| resourceId, | resourceId, | ||||
| resoureName, | resoureName, | ||||
| owner, | |||||
| identifier, | identifier, | ||||
| is_public, | is_public, | ||||
| onOk, | onOk, | ||||
| @@ -46,6 +48,8 @@ function AddVersionModal({ | |||||
| Authorization: getAccessToken() || '', | Authorization: getAccessToken() || '', | ||||
| }, | }, | ||||
| defaultFileList: [], | defaultFileList: [], | ||||
| beforeUpload: config.beforeUpload, | |||||
| accept: config.uploadAccept, | |||||
| }; | }; | ||||
| // 上传请求 | // 上传请求 | ||||
| @@ -74,6 +78,7 @@ function AddVersionModal({ | |||||
| id: resourceId, | id: resourceId, | ||||
| identifier, | identifier, | ||||
| is_public, | is_public, | ||||
| owner, | |||||
| [config.filePropKey]: version_vos, | [config.filePropKey]: version_vos, | ||||
| ...omit(formData, 'fileList'), | ...omit(formData, 'fileList'), | ||||
| [config.sourceParamKey]: DataSource.Create, | [config.sourceParamKey]: DataSource.Create, | ||||
| @@ -83,7 +88,7 @@ function AddVersionModal({ | |||||
| }; | }; | ||||
| const name = config.name; | const name = config.name; | ||||
| const accept = config.uploadAccept; | |||||
| return ( | return ( | ||||
| <KFModal | <KFModal | ||||
| {...rest} | {...rest} | ||||
| @@ -170,7 +175,7 @@ function AddVersionModal({ | |||||
| }, | }, | ||||
| ]} | ]} | ||||
| > | > | ||||
| <Upload {...uploadProps} data={{ uuid: uuid }} accept={accept}> | |||||
| <Upload {...uploadProps} data={{ uuid: uuid }}> | |||||
| <Button | <Button | ||||
| className={styles['upload-button']} | className={styles['upload-button']} | ||||
| type="default" | type="default" | ||||
| @@ -3,8 +3,7 @@ | |||||
| flex-direction: column; | flex-direction: column; | ||||
| align-items: center; | align-items: center; | ||||
| width: 92px; | width: 92px; | ||||
| height: 62px; | |||||
| padding: 11px 8px 7px; | |||||
| padding: 10px 8px 8px; | |||||
| color: @text-color; | color: @text-color; | ||||
| font-size: 12px; | font-size: 12px; | ||||
| border: 1px solid rgba(22, 100, 255, 0.05); | border: 1px solid rgba(22, 100, 255, 0.05); | ||||
| @@ -17,14 +16,6 @@ | |||||
| &__active-icon { | &__active-icon { | ||||
| display: none; | display: none; | ||||
| } | } | ||||
| &__name { | |||||
| width: 100%; | |||||
| margin-top: 4px; | |||||
| overflow: hidden; | |||||
| white-space: nowrap; | |||||
| text-align: center; | |||||
| text-overflow: ellipsis; | |||||
| } | |||||
| &:hover, | &:hover, | ||||
| &--active { | &--active { | ||||
| @@ -1,3 +1,4 @@ | |||||
| import { Typography } from 'antd'; | |||||
| import classNames from 'classnames'; | import classNames from 'classnames'; | ||||
| import { CategoryData, ResourceType, resourceConfig } from '../../config'; | import { CategoryData, ResourceType, resourceConfig } from '../../config'; | ||||
| import styles from './index.less'; | import styles from './index.less'; | ||||
| @@ -32,7 +33,13 @@ function CategoryItem({ resourceType, item, isSelected, onClick }: CategoryItemP | |||||
| alt="" | alt="" | ||||
| draggable={false} | draggable={false} | ||||
| /> | /> | ||||
| <span className={styles['category-item__name']}>{item.name}</span> | |||||
| <Typography.Text | |||||
| ellipsis={{ tooltip: item.name }} | |||||
| style={{ color: 'inherit', marginTop: '4px' }} | |||||
| > | |||||
| {item.name} | |||||
| </Typography.Text> | |||||
| {/* <span className={styles['category-item__name']}>{item.name}</span> */} | |||||
| </div> | </div> | ||||
| ); | ); | ||||
| } | } | ||||
| @@ -119,6 +119,7 @@ const ResourceInfo = ({ resourceType }: ResourceInfoProps) => { | |||||
| resourceType: resourceType, | resourceType: resourceType, | ||||
| resourceId: resourceId, | resourceId: resourceId, | ||||
| resoureName: info.name, | resoureName: info.name, | ||||
| owner: info.owner, | |||||
| identifier: info.identifier, | identifier: info.identifier, | ||||
| is_public: info.is_public, | is_public: info.is_public, | ||||
| onOk: () => { | onOk: () => { | ||||
| @@ -14,7 +14,8 @@ import { | |||||
| getModelList, | getModelList, | ||||
| getModelVersionList, | getModelVersionList, | ||||
| } from '@/services/dataset/index.js'; | } from '@/services/dataset/index.js'; | ||||
| import type { TabsProps } from 'antd'; | |||||
| import { limitUploadFileType } from '@/utils/ui'; | |||||
| import type { TabsProps, UploadFile } from 'antd'; | |||||
| export enum ResourceType { | export enum ResourceType { | ||||
| Model = 'Model', // 模型 | Model = 'Model', // 模型 | ||||
| @@ -49,6 +50,7 @@ type ResourceTypeInfo = { | |||||
| addBtnTitle: string; // 新增按钮的title | addBtnTitle: string; // 新增按钮的title | ||||
| uploadAction: string; // 上传接口 url | uploadAction: string; // 上传接口 url | ||||
| uploadAccept?: string; // 上传文件类型 | uploadAccept?: string; // 上传文件类型 | ||||
| beforeUpload?: (file: UploadFile) => boolean | string; | |||||
| downloadAllAction: string; // 批量下载接口 url | downloadAllAction: string; // 批量下载接口 url | ||||
| downloadSingleAction: string; // 单个下载接口 url | downloadSingleAction: string; // 单个下载接口 url | ||||
| }; | }; | ||||
| @@ -87,6 +89,7 @@ export const resourceConfig: Record<ResourceType, ResourceTypeInfo> = { | |||||
| addBtnTitle: '新建数据集', | addBtnTitle: '新建数据集', | ||||
| uploadAction: '/api/mmp/newdataset/upload', | uploadAction: '/api/mmp/newdataset/upload', | ||||
| uploadAccept: '.zip,.tgz', | uploadAccept: '.zip,.tgz', | ||||
| beforeUpload: limitUploadFileType('zip,tgz'), | |||||
| downloadAllAction: '/api/mmp/newdataset/downloadAllFiles', | downloadAllAction: '/api/mmp/newdataset/downloadAllFiles', | ||||
| downloadSingleAction: '/api/mmp/newdataset/downloadSingleFile', | downloadSingleAction: '/api/mmp/newdataset/downloadSingleFile', | ||||
| }, | }, | ||||
| @@ -8,7 +8,7 @@ import { removeAllPageCacheState } from '@/hooks/pageCacheState'; | |||||
| import themes from '@/styles/theme.less'; | import themes from '@/styles/theme.less'; | ||||
| import { type ClientInfo } from '@/types'; | import { type ClientInfo } from '@/types'; | ||||
| import { history } from '@umijs/max'; | import { history } from '@umijs/max'; | ||||
| import { Modal, message, type ModalFuncProps, type UploadFile } from 'antd'; | |||||
| import { Modal, Upload, message, type ModalFuncProps, type UploadFile } from 'antd'; | |||||
| import { closeAllModals } from './modal'; | import { closeAllModals } from './modal'; | ||||
| import SessionStorage from './sessionStorage'; | import SessionStorage from './sessionStorage'; | ||||
| @@ -52,23 +52,6 @@ export function modalConfirm({ | |||||
| }); | }); | ||||
| } | } | ||||
| // 从事件中获取上传文件列表,用于 Upload + Form 中 | |||||
| export const getFileListFromEvent = (e: any) => { | |||||
| const fileList: UploadFile[] = (Array.isArray(e) ? e : e?.fileList) || []; | |||||
| return fileList.map((item) => { | |||||
| if (item.status === 'done') { | |||||
| const { response } = item; | |||||
| if (response?.code !== 200) { | |||||
| return { | |||||
| ...item, | |||||
| status: 'error', | |||||
| }; | |||||
| } | |||||
| } | |||||
| return item; | |||||
| }); | |||||
| }; | |||||
| /** | /** | ||||
| * 跳转到登录页 | * 跳转到登录页 | ||||
| * @param toHome 是否跳转到首页 | * @param toHome 是否跳转到首页 | ||||
| @@ -97,6 +80,23 @@ export const gotoOAuth2 = () => { | |||||
| } | } | ||||
| }; | }; | ||||
| // 从事件中获取上传文件列表,用于 Upload + Form 中 | |||||
| export const getFileListFromEvent = (e: any) => { | |||||
| const fileList: UploadFile[] = (Array.isArray(e) ? e : e?.fileList) || []; | |||||
| return fileList.map((item) => { | |||||
| if (item.status === 'done') { | |||||
| const { response } = item; | |||||
| if (response?.code !== 200) { | |||||
| return { | |||||
| ...item, | |||||
| status: 'error', | |||||
| }; | |||||
| } | |||||
| } | |||||
| return item; | |||||
| }); | |||||
| }; | |||||
| /** | /** | ||||
| * 验证文件上传 | * 验证文件上传 | ||||
| * | * | ||||
| @@ -128,6 +128,20 @@ export const validateUploadFiles = (files: UploadFile[], required: boolean = tru | |||||
| return !hasError; | return !hasError; | ||||
| }; | }; | ||||
| // 限制上传文件类型 | |||||
| export const limitUploadFileType = (type: string) => { | |||||
| return (file: UploadFile): boolean | string => { | |||||
| const acceptTypes = type.split(',').map((item) => item.trim()); | |||||
| const fileType = file.name.split('.').pop()?.trim(); | |||||
| if (!(fileType && acceptTypes.includes(fileType))) { | |||||
| message.error(`文件类型不正确,只支持 "${acceptTypes.join('、')}" 类型的文件`); | |||||
| file.status = 'error'; | |||||
| return Upload.LIST_IGNORE; | |||||
| } | |||||
| return true; | |||||
| }; | |||||
| }; | |||||
| /** | /** | ||||
| * 滚动到底部 | * 滚动到底部 | ||||
| * | * | ||||