|
|
|
@@ -1,56 +1,25 @@ |
|
|
|
import { getAccessToken } from '@/access'; |
|
|
|
import KFIcon from '@/components/KFIcon'; |
|
|
|
import KFModal from '@/components/KFModal'; |
|
|
|
import { ResourceType } from '@/pages/Dataset/type'; |
|
|
|
import { |
|
|
|
addDatasetVersionDetail, |
|
|
|
deleteDatasetVersion, |
|
|
|
getDatasetById, |
|
|
|
getDatasetVersionIdList, |
|
|
|
getDatasetVersionsById, |
|
|
|
} from '@/services/dataset/index.js'; |
|
|
|
import { formatDate } from '@/utils/date'; |
|
|
|
import { downLoadZip } from '@/utils/downloadfile'; |
|
|
|
import { openAntdModal } from '@/utils/modal'; |
|
|
|
import { modalConfirm } from '@/utils/ui'; |
|
|
|
import { UploadOutlined } from '@ant-design/icons'; |
|
|
|
import { useParams, useSearchParams } from '@umijs/max'; |
|
|
|
import { Button, Form, Input, Select, Table, Tabs, Upload, message } from 'antd'; |
|
|
|
import moment from 'moment'; |
|
|
|
import { Button, Input, Select, Table, Tabs, message } from 'antd'; |
|
|
|
import { useEffect, useRef, useState } from 'react'; |
|
|
|
import Styles from './index.less'; |
|
|
|
import AddVersionModal from './components/AddVersionModal'; |
|
|
|
import Styles from './intro.less'; |
|
|
|
const { Search } = Input; |
|
|
|
const { TabPane } = Tabs; |
|
|
|
|
|
|
|
const Dataset = () => { |
|
|
|
const props = { |
|
|
|
action: '/api/mmp/dataset/upload', |
|
|
|
// headers: { |
|
|
|
// 'X-Requested-With': null |
|
|
|
// }, |
|
|
|
headers: { |
|
|
|
Authorization: getAccessToken(), |
|
|
|
'X-Requested-With': null, |
|
|
|
}, |
|
|
|
onChange({ file, fileList }) { |
|
|
|
if (file.status !== 'uploading') { |
|
|
|
console.log(file, fileList); |
|
|
|
setFormList( |
|
|
|
fileList.map((item) => { |
|
|
|
return { |
|
|
|
...form.getFieldsValue(), |
|
|
|
dataset_id: locationParams.id, |
|
|
|
file_name: item.response.code === 200 ? item.response.data[0].fileName : null, |
|
|
|
file_size: item.response.code === 200 ? item.response.data[0].fileSize : null, |
|
|
|
url: item.response.code === 200 ? item.response.data[0].url : null, |
|
|
|
}; |
|
|
|
}), |
|
|
|
); |
|
|
|
} |
|
|
|
}, |
|
|
|
defaultFileList: [], |
|
|
|
}; |
|
|
|
const [form] = Form.useForm(); |
|
|
|
const [formList, setFormList] = useState([]); |
|
|
|
const [dialogTitle, setDialogTitle] = useState('新建版本'); |
|
|
|
const [isModalOpen, setIsModalOpen] = useState(false); |
|
|
|
const [datasetDetailObj, setDatasetDetailObj] = useState({}); |
|
|
|
const [version, setVersion] = useState(null); |
|
|
|
const [versionList, setVersionList] = useState([]); |
|
|
|
@@ -58,8 +27,8 @@ const Dataset = () => { |
|
|
|
const [searchParams] = useSearchParams(); |
|
|
|
const [wordList, setWordList] = useState([]); |
|
|
|
const [activeTabKey, setActiveTabKey] = useState('1'); |
|
|
|
const [uuid, setUuid] = useState(Date.now()); |
|
|
|
const isPublic = searchParams.get('isPublic') === 'true'; |
|
|
|
|
|
|
|
const getDatasetByDetail = () => { |
|
|
|
getDatasetById(locationParams.id).then((ret) => { |
|
|
|
console.log(ret); |
|
|
|
@@ -93,21 +62,17 @@ const Dataset = () => { |
|
|
|
return () => {}; |
|
|
|
}, []); |
|
|
|
const showModal = () => { |
|
|
|
form.resetFields(); |
|
|
|
form.setFieldsValue({ name: datasetDetailObj.name }); |
|
|
|
|
|
|
|
setDialogTitle('创建新版本'); |
|
|
|
setUuid(Date.now()); |
|
|
|
setIsModalOpen(true); |
|
|
|
}; |
|
|
|
const handleCancel = () => { |
|
|
|
setIsModalOpen(false); |
|
|
|
}; |
|
|
|
const handleExport = async () => { |
|
|
|
const hide = message.loading('正在下载'); |
|
|
|
hide(); |
|
|
|
downLoadZip(`/api/mmp/dataset/downloadAllFiles`, { dataset_id: locationParams.id, version }); |
|
|
|
const { close } = openAntdModal(AddVersionModal, { |
|
|
|
resourceType: ResourceType.Dataset, |
|
|
|
resourceId: locationParams.id, |
|
|
|
initialName: datasetDetailObj.name, |
|
|
|
onOk: () => { |
|
|
|
getDatasetVersionList(); |
|
|
|
close(); |
|
|
|
}, |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
const deleteDataset = () => { |
|
|
|
modalConfirm({ |
|
|
|
title: '删除后,该数据集版本将不可恢复', |
|
|
|
@@ -120,19 +85,26 @@ const Dataset = () => { |
|
|
|
}, |
|
|
|
}); |
|
|
|
}; |
|
|
|
const onFinish = (values) => { |
|
|
|
addDatasetVersionDetail(formList).then((ret) => { |
|
|
|
getDatasetVersionList(); |
|
|
|
setIsModalOpen(false); |
|
|
|
message.success('创建成功'); |
|
|
|
}); |
|
|
|
}; |
|
|
|
// 获取版本下的文件列表 |
|
|
|
const getDatasetVersions = (params) => { |
|
|
|
getDatasetVersionIdList(params).then((res) => { |
|
|
|
setWordList(res?.data?.content ?? []); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
const handleExport = async () => { |
|
|
|
const hide = message.loading('正在下载'); |
|
|
|
hide(); |
|
|
|
downLoadZip(`/api/mmp/dataset/downloadAllFiles`, { dataset_id: locationParams.id, version }); |
|
|
|
}; |
|
|
|
|
|
|
|
const downloadAlone = (e, record) => { |
|
|
|
console.log(record); |
|
|
|
const hide = message.loading('正在下载'); |
|
|
|
hide(); |
|
|
|
downLoadZip(`/api/mmp/dataset/download/${record.id}`); |
|
|
|
}; |
|
|
|
|
|
|
|
const handleChange = (value) => { |
|
|
|
console.log(value); |
|
|
|
if (value) { |
|
|
|
@@ -142,15 +114,7 @@ const Dataset = () => { |
|
|
|
setVersion(null); |
|
|
|
} |
|
|
|
}; |
|
|
|
const onFinishFailed = (errorInfo) => { |
|
|
|
console.log('Failed:', errorInfo); |
|
|
|
}; |
|
|
|
const downloadAlone = (e, record) => { |
|
|
|
console.log(record); |
|
|
|
const hide = message.loading('正在下载'); |
|
|
|
hide(); |
|
|
|
downLoadZip(`/api/mmp/dataset/download/${record.id}`); |
|
|
|
}; |
|
|
|
|
|
|
|
const columns = [ |
|
|
|
{ |
|
|
|
title: '序号', |
|
|
|
@@ -182,7 +146,7 @@ const Dataset = () => { |
|
|
|
title: '更新时间', |
|
|
|
dataIndex: 'update_time', |
|
|
|
key: 'update_time', |
|
|
|
render: (text) => <span>{moment(text).format('YYYY-MM-DD HH:mm:ss')}</span>, |
|
|
|
render: (text) => <span>{formatDate(text)}</span>, |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: '操作', |
|
|
|
@@ -292,98 +256,6 @@ const Dataset = () => { |
|
|
|
</TabPane> |
|
|
|
</Tabs> |
|
|
|
</div> |
|
|
|
<KFModal |
|
|
|
title={dialogTitle} |
|
|
|
width={825} |
|
|
|
image={require('@/assets/img/create-experiment.png')} |
|
|
|
open={isModalOpen} |
|
|
|
className={Styles.modal} |
|
|
|
okButtonProps={{ |
|
|
|
htmlType: 'submit', |
|
|
|
form: 'form', |
|
|
|
}} |
|
|
|
onCancel={handleCancel} |
|
|
|
> |
|
|
|
<Form |
|
|
|
name="form" |
|
|
|
form={form} |
|
|
|
layout="vertical" |
|
|
|
initialValues={{ |
|
|
|
remember: true, |
|
|
|
}} |
|
|
|
onFinish={onFinish} |
|
|
|
onFinishFailed={onFinishFailed} |
|
|
|
autoComplete="off" |
|
|
|
> |
|
|
|
<Form.Item |
|
|
|
label="数据集名称" |
|
|
|
name="name" |
|
|
|
rules={[ |
|
|
|
{ |
|
|
|
required: true, |
|
|
|
message: '请输入数据集名称', |
|
|
|
}, |
|
|
|
]} |
|
|
|
> |
|
|
|
<Input disabled placeholder="请输入数据集名称" /> |
|
|
|
</Form.Item> |
|
|
|
<Form.Item |
|
|
|
label="数据集版本" |
|
|
|
name="version" |
|
|
|
rules={[ |
|
|
|
{ |
|
|
|
required: true, |
|
|
|
message: '请输入数据集版本', |
|
|
|
}, |
|
|
|
]} |
|
|
|
> |
|
|
|
<Input placeholder="请输入数据集版本" maxLength={64} showCount allowClear /> |
|
|
|
</Form.Item> |
|
|
|
<Form.Item |
|
|
|
label="版本描述" |
|
|
|
name="description" |
|
|
|
rules={[ |
|
|
|
{ |
|
|
|
required: true, |
|
|
|
message: '请输入版本描述', |
|
|
|
}, |
|
|
|
]} |
|
|
|
> |
|
|
|
<Input.TextArea |
|
|
|
placeholder="请输入版本描述" |
|
|
|
autoSize={{ minRows: 2, maxRows: 6 }} |
|
|
|
maxLength={256} |
|
|
|
showCount |
|
|
|
allowClear |
|
|
|
/> |
|
|
|
</Form.Item> |
|
|
|
<Form.Item |
|
|
|
label="数据集文件" |
|
|
|
name="dataset_version_vos" |
|
|
|
rules={[ |
|
|
|
{ |
|
|
|
required: true, |
|
|
|
message: '请上传数据集文件', |
|
|
|
}, |
|
|
|
]} |
|
|
|
> |
|
|
|
<Upload {...props} data={{ uuid: uuid }} accept=".zip,.tgz"> |
|
|
|
<Button |
|
|
|
style={{ |
|
|
|
fontSize: '14px', |
|
|
|
border: '1px solid', |
|
|
|
borderColor: '#1664ff', |
|
|
|
background: '#fff', |
|
|
|
}} |
|
|
|
icon={<UploadOutlined style={{ color: '#1664ff' }} />} |
|
|
|
> |
|
|
|
上传文件 |
|
|
|
</Button> |
|
|
|
<div className={Styles.tipContent}>只允许上传.zip,.tgz格式文件</div> |
|
|
|
</Upload> |
|
|
|
</Form.Item> |
|
|
|
</Form> |
|
|
|
</KFModal> |
|
|
|
</div> |
|
|
|
); |
|
|
|
}; |