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.

datasetIntro.jsx 12 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. import { getAccessToken } from '@/access';
  2. import {
  3. addDatasetVersionDetail,
  4. deleteDatasetVersion,
  5. getDatasetById,
  6. getDatasetVersionIdList,
  7. getDatasetVersionsById,
  8. } from '@/services/dataset/index.js';
  9. import { downLoadZip } from '@/utils/downloadfile';
  10. import {
  11. DeleteOutlined,
  12. DownloadOutlined,
  13. PlusCircleOutlined,
  14. UploadOutlined,
  15. } from '@ant-design/icons';
  16. import { Button, Form, Input, Modal, Select, Table, Tabs, Upload, message } from 'antd';
  17. import moment from 'moment';
  18. import { useEffect, useRef, useState } from 'react';
  19. import { useParams } from 'react-router-dom';
  20. import Styles from './index.less';
  21. const { Search } = Input;
  22. const { TabPane } = Tabs;
  23. const Dataset = () => {
  24. const props = {
  25. action: '/api/mmp/dataset/upload',
  26. // headers: {
  27. // 'X-Requested-With': null
  28. // },
  29. headers: {
  30. Authorization: getAccessToken(),
  31. 'X-Requested-With': null,
  32. },
  33. onChange({ file, fileList }) {
  34. if (file.status !== 'uploading') {
  35. console.log(file, fileList);
  36. setFormList(
  37. fileList.map((item) => {
  38. return {
  39. ...form.getFieldsValue(),
  40. dataset_id: locationParams.id,
  41. file_name: item.response.data[0].fileName,
  42. file_size: item.response.data[0].fileSize,
  43. url: item.response.data[0].url,
  44. };
  45. }),
  46. );
  47. }
  48. },
  49. defaultFileList: [],
  50. };
  51. const [form] = Form.useForm();
  52. const [formList, setFormList] = useState([]);
  53. const [dialogTitle, setDialogTitle] = useState('新建版本');
  54. const [isModalOpen, setIsModalOpen] = useState(false);
  55. const [datasetDetailObj, setDatasetDetailObj] = useState({});
  56. const [version, setVersion] = useState(null);
  57. const [versionList, setVersionList] = useState([]);
  58. const locationParams = useParams(); //新版本获取路由参数接口
  59. const [wordList, setWordList] = useState([]);
  60. const [activeTabKey, setActiveTabKey] = useState('1');
  61. const [uuid, setUuid] = useState(Date.now());
  62. const getDatasetByDetail = () => {
  63. getDatasetById(locationParams.id).then((ret) => {
  64. console.log(ret);
  65. setDatasetDetailObj(ret.data);
  66. });
  67. };
  68. // 获取数据集版本
  69. const getDatasetVersionList = () => {
  70. getDatasetVersionsById(locationParams.id).then((ret) => {
  71. console.log(ret);
  72. if (ret && ret.data && ret.data.length > 0) {
  73. setVersionList(
  74. ret.data.map((item) => {
  75. return {
  76. label: item,
  77. value: item,
  78. };
  79. }),
  80. );
  81. setVersion(ret.data[0]);
  82. getDatasetVersions({ version: ret.data[0], dataset_id: locationParams.id });
  83. }
  84. });
  85. };
  86. useEffect(() => {
  87. getDatasetByDetail();
  88. getDatasetVersionList();
  89. return () => {};
  90. }, []);
  91. const showModal = () => {
  92. form.resetFields();
  93. form.setFieldsValue({ name: datasetDetailObj.name });
  94. setDialogTitle('创建新版本');
  95. setUuid(Date.now());
  96. setIsModalOpen(true);
  97. };
  98. const handleCancel = () => {
  99. setIsModalOpen(false);
  100. };
  101. const handleExport = async () => {
  102. const hide = message.loading('正在下载');
  103. hide();
  104. downLoadZip(`/api/mmp/dataset/downloadAllFiles`, { dataset_id: locationParams.id, version });
  105. };
  106. const deleteDataset = () => {
  107. Modal.confirm({
  108. title: '删除',
  109. content: '确定删除数据集版本?',
  110. okText: '确认',
  111. cancelText: '取消',
  112. onOk: () => {
  113. deleteDatasetVersion({ dataset_id: locationParams.id, version }).then((ret) => {
  114. getDatasetVersionList();
  115. message.success('删除成功');
  116. });
  117. },
  118. });
  119. };
  120. const onFinish = (values) => {
  121. addDatasetVersionDetail(formList).then((ret) => {
  122. getDatasetVersionList();
  123. setIsModalOpen(false);
  124. message.success('创建成功');
  125. });
  126. };
  127. // 获取版本下的文件列表
  128. const getDatasetVersions = (params) => {
  129. getDatasetVersionIdList(params).then((res) => {
  130. setWordList(res?.data?.content ?? []);
  131. });
  132. };
  133. const handleChange = (value) => {
  134. console.log(value);
  135. if (value) {
  136. getDatasetVersions({ version: value, dataset_id: locationParams.id });
  137. setVersion(value);
  138. } else {
  139. setVersion(null);
  140. }
  141. };
  142. const onFinishFailed = (errorInfo) => {
  143. console.log('Failed:', errorInfo);
  144. };
  145. const downloadAlone = (e, record) => {
  146. console.log(record);
  147. const hide = message.loading('正在下载');
  148. hide();
  149. downLoadZip(`/api/mmp/dataset/download/${record.id}`);
  150. };
  151. const columns = [
  152. {
  153. title: '序号',
  154. dataIndex: 'index',
  155. key: 'index',
  156. width: 80,
  157. render(text, record, index) {
  158. return <span>{(pageOption.current.page - 1) * 10 + index + 1}</span>;
  159. },
  160. // render: (text, record, index) => `${((curPage-1)*10)+(index+1)}`,
  161. },
  162. {
  163. title: '文件名称',
  164. dataIndex: 'file_name',
  165. key: 'file_name',
  166. render: (text, record) => <a onClick={(e) => downloadAlone(e, record)}>{text}</a>,
  167. },
  168. {
  169. title: '版本号',
  170. dataIndex: 'version',
  171. key: 'version',
  172. },
  173. {
  174. title: '文件大小',
  175. dataIndex: 'file_size',
  176. key: 'file_size',
  177. },
  178. {
  179. title: '更新时间',
  180. dataIndex: 'update_time',
  181. key: 'update_time',
  182. render: (text) => <span>{moment(text).format('YYYY-MM-DD HH:mm:ss')}</span>,
  183. },
  184. {
  185. title: '操作',
  186. dataIndex: 'option',
  187. width: '100px',
  188. key: 'option',
  189. render: (_, record) => [
  190. <Button
  191. type="link"
  192. size="small"
  193. key="download"
  194. icon={<DownloadOutlined />}
  195. onClick={(e) => downloadAlone(e, record)}
  196. >
  197. 下载
  198. </Button>,
  199. ],
  200. },
  201. ];
  202. const pageOption = useRef({ page: 1, size: 10 });
  203. // 当前页面切换
  204. const paginationChange = async (current, size) => {
  205. console.log('page', current, size);
  206. pageOption.current = {
  207. page: current,
  208. size: size,
  209. };
  210. // getList()
  211. };
  212. return (
  213. <div className={Styles.datasetBox}>
  214. <div className={Styles.datasetIntroTopBox}>
  215. <span style={{ color: '#1d1d20', fontSize: '20px' }}>{datasetDetailObj.name}</span>
  216. <div className={Styles.smallTagBox}>
  217. <div className={Styles.tagItem}>{datasetDetailObj.data_tag || '...'}</div>
  218. <div className={Styles.tagItem}>{datasetDetailObj.data_type}</div>
  219. {/* <div className={Styles.tagItem}>English</div> */}
  220. </div>
  221. </div>
  222. <div className={Styles.datasetIntroCneterBox}>
  223. <Tabs activeKey={activeTabKey} onChange={(key) => setActiveTabKey(key)}>
  224. <TabPane tab="数据集简介" key="1">
  225. <div className={Styles.datasetIntroTitle}>简介</div>
  226. <div className={Styles.datasetIntroText}>{datasetDetailObj.description}</div>
  227. </TabPane>
  228. <TabPane tab="数据集文件/版本" key="2">
  229. <div className={Styles.dataListBox}>
  230. <div>数据集文件列表</div>
  231. <div className={Styles.dataButtonList}>
  232. <div
  233. style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}
  234. >
  235. <span style={{ marginRight: '10px' }}>版本号:</span>
  236. <Select
  237. placeholder="请选择版本号"
  238. style={{
  239. width: 160,
  240. }}
  241. allowClear
  242. value={version}
  243. onChange={handleChange}
  244. options={versionList}
  245. />
  246. <Button
  247. type="primary"
  248. className={Styles.plusButton}
  249. onClick={showModal}
  250. icon={<PlusCircleOutlined style={{ color: '#1664ff' }} />}
  251. >
  252. 创建新版本
  253. </Button>
  254. </div>
  255. <div
  256. style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}
  257. >
  258. <Button
  259. type="primary"
  260. className={Styles.plusButton}
  261. style={{ margin: '0 20px 0 0' }}
  262. onClick={deleteDataset}
  263. icon={<DeleteOutlined style={{ color: '#1664ff' }} />}
  264. >
  265. 删除
  266. </Button>
  267. <Button
  268. type="primary"
  269. disabled={!version}
  270. className={Styles.plusButton}
  271. style={{ margin: '0 20px 0 0' }}
  272. onClick={handleExport}
  273. icon={<DownloadOutlined style={{ color: '#1664ff' }} />}
  274. >
  275. 下载
  276. </Button>
  277. </div>
  278. </div>
  279. <div style={{ marginBottom: '10px', fontSize: '14px' }}>
  280. {wordList.length > 0 && wordList[0].description
  281. ? '版本描述:' + wordList[0].description
  282. : null}
  283. </div>
  284. <Table columns={columns} dataSource={wordList} pagination={false} rowKey="id" />
  285. </div>
  286. </TabPane>
  287. </Tabs>
  288. </div>
  289. <Modal
  290. title={
  291. <div style={{ display: 'flex', alignItems: 'center', fontWeight: 500 }}>
  292. <img
  293. style={{ width: '20px', marginRight: '10px' }}
  294. src={`/assets/images/pipeline-edit-icon.png`}
  295. alt=""
  296. />
  297. {dialogTitle}
  298. </div>
  299. }
  300. open={isModalOpen}
  301. className={Styles.modal}
  302. okButtonProps={{
  303. htmlType: 'submit',
  304. form: 'form',
  305. }}
  306. onCancel={handleCancel}
  307. >
  308. <Form
  309. name="form"
  310. form={form}
  311. layout="vertical"
  312. initialValues={{
  313. remember: true,
  314. }}
  315. onFinish={onFinish}
  316. onFinishFailed={onFinishFailed}
  317. autoComplete="off"
  318. >
  319. <Form.Item
  320. label="数据集名称"
  321. name="name"
  322. rules={[
  323. {
  324. required: true,
  325. message: '请输入数据集名称',
  326. },
  327. ]}
  328. >
  329. <Input disabled placeholder="请输入数据集名称" />
  330. </Form.Item>
  331. <Form.Item
  332. label="数据集版本"
  333. name="version"
  334. rules={[
  335. {
  336. required: true,
  337. message: '请输入数据集版本',
  338. },
  339. ]}
  340. >
  341. <Input placeholder="请输入数据集版本" maxLength={64} showCount allowClear />
  342. </Form.Item>
  343. <Form.Item
  344. label="版本描述"
  345. name="description"
  346. rules={[
  347. {
  348. required: true,
  349. message: '请输入版本描述',
  350. },
  351. ]}
  352. >
  353. <Input.TextArea
  354. placeholder="请输入版本描述"
  355. autoSize={{ minRows: 2, maxRows: 6 }}
  356. maxLength={256}
  357. showCount
  358. allowClear
  359. />
  360. </Form.Item>
  361. <Form.Item
  362. label="数据集文件"
  363. name="dataset_version_vos"
  364. rules={[
  365. {
  366. required: true,
  367. message: '请上传数据集文件',
  368. },
  369. ]}
  370. >
  371. <Upload {...props} data={{ uuid: uuid }}>
  372. <Button
  373. style={{
  374. fontSize: '14px',
  375. border: '1px solid',
  376. borderColor: '#1664ff',
  377. background: '#fff',
  378. }}
  379. icon={<UploadOutlined style={{ color: '#1664ff' }} />}
  380. >
  381. 上传文件
  382. </Button>
  383. </Upload>
  384. </Form.Item>
  385. </Form>
  386. </Modal>
  387. </div>
  388. );
  389. };
  390. export default Dataset;