From c1cc01cc97d36db7c8f320808b0f4842a4a33841 Mon Sep 17 00:00:00 2001 From: cp3hnu Date: Tue, 1 Apr 2025 14:04:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=96=B0=E5=BB=BA=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=9B=86=E3=80=81=E6=A8=A1=E5=9E=8B=E5=88=A0=E9=99=A4=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=97=B6=EF=BC=8C=E8=B0=83=E7=94=A8=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/AddDatasetModal/index.tsx | 23 +++++--------- .../components/AddModelModal/index.tsx | 5 ++-- .../components/AddVersionModal/index.tsx | 3 +- react-ui/src/services/dataset/index.js | 11 ++++++- react-ui/src/types.ts | 14 +++++++++ react-ui/src/utils/ui.tsx | 30 ++++++++++++++++++- 6 files changed, 66 insertions(+), 20 deletions(-) diff --git a/react-ui/src/pages/Dataset/components/AddDatasetModal/index.tsx b/react-ui/src/pages/Dataset/components/AddDatasetModal/index.tsx index 883e20c7..624ef833 100644 --- a/react-ui/src/pages/Dataset/components/AddDatasetModal/index.tsx +++ b/react-ui/src/pages/Dataset/components/AddDatasetModal/index.tsx @@ -4,7 +4,12 @@ import KFModal from '@/components/KFModal'; import { CategoryData, DataSource, ResourceType, resourceConfig } from '@/pages/Dataset/config'; import { addDataset } from '@/services/dataset/index.js'; import { to } from '@/utils/promise'; -import { getFileListFromEvent, limitUploadFileType, validateUploadFiles } from '@/utils/ui'; +import { + getFileListFromEvent, + limitUploadFileType, + removeUploadedFile, + validateUploadFiles, +} from '@/utils/ui'; import { Button, Form, @@ -29,11 +34,6 @@ interface AddDatasetModalProps extends Omit { function AddDatasetModal({ typeList, tagList, onOk, ...rest }: AddDatasetModalProps) { const [uuid] = useState(Date.now()); - // const [clusterOptions, setClusterOptions] = useState([]); - - // useEffect(() => { - // getClusterOptions(); - // }, []); // 上传组件参数 const uploadProps: UploadProps = { @@ -44,16 +44,9 @@ function AddDatasetModal({ typeList, tagList, onOk, ...rest }: AddDatasetModalPr defaultFileList: [], accept: '.zip,.tgz', beforeUpload: limitUploadFileType('zip,tgz'), + onRemove: removeUploadedFile, }; - // 获取集群版本数据 - // const getClusterOptions = async () => { - // const [res] = await to(getDictSelectOption('available_cluster')); - // if (res) { - // setClusterOptions(res); - // } - // }; - // 上传请求 const createDataset = async (params: any) => { const [res] = await to(addDataset(params)); @@ -113,7 +106,7 @@ function AddDatasetModal({ typeList, tagList, onOk, ...rest }: AddDatasetModalPr }, ]} > - + - + = { + code: number; + msg: string; + data: T; +}; + +// 上传文件的响应 +export type UploadFileRes = { + fileName: string; + fileSize: number; + url: string; +}; diff --git a/react-ui/src/utils/ui.tsx b/react-ui/src/utils/ui.tsx index f40fd576..5cd39e43 100644 --- a/react-ui/src/utils/ui.tsx +++ b/react-ui/src/utils/ui.tsx @@ -5,8 +5,10 @@ */ import { PageEnum } from '@/enums/pagesEnums'; import { removeAllPageCacheState } from '@/hooks/useCacheState'; +import { deleteUploadFileReq } from '@/services/dataset/index.js'; import themes from '@/styles/theme.less'; -import { type ClientInfo } from '@/types'; +import { type AppResponse, type ClientInfo, type UploadFileRes } from '@/types'; +import { to } from '@/utils/promise'; import { history } from '@umijs/max'; import { Modal, @@ -162,6 +164,32 @@ export const limitUploadFileType = (type: string) => { }; }; +/** + * 删除已上传的文件 + * @param file - 已上传的文件 + */ +export const removeUploadedFile = async (file: UploadFile>) => { + const { status, response } = file; + const { code, data } = response ?? {}; + if (status === 'done' && code === 200 && Array.isArray(data) && data.length > 0) { + const uploadRes = data[0]; + const { fileName, url } = uploadRes; + const [res] = await to( + deleteUploadFileReq({ + fileName, + url, + }), + ); + if (res) { + return true; + } else { + return false; + } + } + + return true; +}; + /** * 删除 FormList 表单项,如果表单项没有值,则直接删除,否则弹出确认框 * @param form - From实例