| @@ -78,7 +78,7 @@ function ResourceList( | |||
| // 获取数据请求 | |||
| const getDataList = async () => { | |||
| const reqParams = { | |||
| const params = { | |||
| page: pagination.current! - 1, | |||
| size: pagination.pageSize, | |||
| [resourceConfig[resourceType].typeParamKey]: dataType, | |||
| @@ -87,7 +87,7 @@ function ResourceList( | |||
| name: searchText !== '' ? searchText : undefined, | |||
| }; | |||
| const request = resourceConfig[resourceType].getList; | |||
| const [res] = await to(request(reqParams)); | |||
| const [res] = await to(request(params)); | |||
| if (res && res.data && res.data.content) { | |||
| setDataList(res.data.content); | |||
| setTotal(res.data.totalElements); | |||
| @@ -12,7 +12,7 @@ import { CommonTabKeys } from '@/enums'; | |||
| import { createMirrorReq } from '@/services/mirror'; | |||
| import { to } from '@/utils/promise'; | |||
| import { getSessionItemThenRemove, mirrorNameKey } from '@/utils/sessionStorage'; | |||
| import { getFileListFromEvent } from '@/utils/ui'; | |||
| import { getFileListFromEvent, validateUploadFiles } from '@/utils/ui'; | |||
| import { useNavigate } from '@umijs/max'; | |||
| import { Button, Col, Form, Input, Row, Upload, UploadFile, message, type UploadProps } from 'antd'; | |||
| import { omit } from 'lodash'; | |||
| @@ -75,30 +75,16 @@ function MirrorCreate() { | |||
| }; | |||
| } else { | |||
| const fileList = formData['fileList'] ?? []; | |||
| if (fileList.length === 0) { | |||
| message.error('请上传文件'); | |||
| return; | |||
| if (validateUploadFiles(fileList)) { | |||
| const file = fileList[0]; | |||
| params = { | |||
| ...omit(formData, ['fileList', 'upload_type']), | |||
| path: file.response.data.url, | |||
| file_size: file.response.data.fileSize, | |||
| upload_type: 1, | |||
| image_type: 0, | |||
| }; | |||
| } | |||
| const file = fileList[0]; | |||
| if (file.status === 'uploading') { | |||
| message.error('请等待文件上传完成'); | |||
| return; | |||
| } else if (file.status === 'error') { | |||
| message.error('文件上传失败,请重新上传文件'); | |||
| return; | |||
| } | |||
| if (!file.response || !file.response.data) { | |||
| message.error('文件上传失败,请重新上传文件'); | |||
| return; | |||
| } | |||
| params = { | |||
| ...omit(formData, ['fileList', 'upload_type']), | |||
| path: file.response.data.url, | |||
| file_size: file.response.data.fileSize, | |||
| upload_type: 1, | |||
| image_type: 0, | |||
| }; | |||
| } | |||
| const [res] = await to(createMirrorReq(params)); | |||
| @@ -54,6 +54,7 @@ function MirrorList() { | |||
| const [cacheState, setCacheState] = useCacheState(); | |||
| const [activeTab, setActiveTab] = useState<string>(cacheState?.activeTab ?? CommonTabKeys.Public); | |||
| const [searchText, setSearchText] = useState(cacheState?.searchText); | |||
| const [inputText, setInputText] = useState(cacheState?.searchText); | |||
| const [tableData, setTableData] = useState<MirrorData[]>([]); | |||
| const [total, setTotal] = useState(0); | |||
| const [pagination, setPagination] = useState<TablePaginationConfig>( | |||
| @@ -65,11 +66,12 @@ function MirrorList() { | |||
| useEffect(() => { | |||
| getMirrorList(); | |||
| }, [activeTab, pagination]); | |||
| }, [activeTab, pagination, searchText]); | |||
| // 切换 Tab,重置数据 | |||
| const hanleTabChange: TabsProps['onChange'] = (value) => { | |||
| setSearchText(''); | |||
| setInputText(''); | |||
| setPagination({ | |||
| current: 1, | |||
| pageSize: 10, | |||
| @@ -78,16 +80,16 @@ function MirrorList() { | |||
| setTableData([]); | |||
| setActiveTab(value); | |||
| }; | |||
| // 获取镜像列表 | |||
| const getMirrorList = async (params?: Record<string, any>) => { | |||
| const reqParams = { | |||
| const getMirrorList = async () => { | |||
| const params: Record<string, any> = { | |||
| page: pagination.current! - 1, | |||
| size: pagination.pageSize, | |||
| name: searchText, | |||
| image_type: activeTab === CommonTabKeys.Public ? 1 : 0, | |||
| ...params, | |||
| }; | |||
| const [res] = await to(getMirrorListReq(reqParams)); | |||
| const [res] = await to(getMirrorListReq(params)); | |||
| if (res && res.data) { | |||
| const { content = [], totalElements = 0 } = res.data; | |||
| setTableData(content); | |||
| @@ -116,10 +118,7 @@ function MirrorList() { | |||
| // 搜索 | |||
| const onSearch: SearchProps['onSearch'] = (value) => { | |||
| // 带参数是为了点清除时,searchText 更新不及时的问题 | |||
| getMirrorList({ | |||
| name: value, | |||
| }); | |||
| setSearchText(value); | |||
| }; | |||
| // 查看详情 | |||
| @@ -241,9 +240,9 @@ function MirrorList() { | |||
| placeholder="按数据集名称筛选" | |||
| allowClear | |||
| onSearch={onSearch} | |||
| onChange={(e) => setSearchText(e.target.value)} | |||
| onChange={(e) => setInputText(e.target.value)} | |||
| style={{ width: 300 }} | |||
| value={searchText} | |||
| value={inputText} | |||
| /> | |||
| {activeTab === CommonTabKeys.Private && ( | |||
| <Button | |||