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