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.

index.tsx 2.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import KFIcon from '@/components/KFIcon';
  2. import {
  3. ResourceData,
  4. ResourceFileData,
  5. ResourceType,
  6. resourceConfig,
  7. } from '@/pages/Dataset/config';
  8. import { downLoadZip } from '@/utils/downloadfile';
  9. import tableCellRender, { TableCellValueType } from '@/utils/table';
  10. import { Button, Flex, Table, TableProps } from 'antd';
  11. import styles from './index.less';
  12. type ResourceVersionProps = {
  13. resourceType: ResourceType;
  14. info: ResourceData;
  15. };
  16. function ResourceVersion({ resourceType, info }: ResourceVersionProps) {
  17. const config = resourceConfig[resourceType];
  18. const filePropKey = config.filePropKey as keyof ResourceData;
  19. const fileList = (info[filePropKey] ?? []) as ResourceFileData[];
  20. fileList.forEach((item) => (item.update_time = info.update_time));
  21. // 全部导出
  22. const handleExport = async () => {
  23. const url = config.downloadAllAction;
  24. downLoadZip(url, {
  25. name: info.name,
  26. id: info.id,
  27. version: info.version,
  28. identifier: info.identifier,
  29. });
  30. };
  31. // 单个导出
  32. const downloadAlone = async (record: ResourceFileData) => {
  33. const url = config.downloadSingleAction;
  34. downLoadZip(url, { url: record.url });
  35. };
  36. const columns: TableProps<ResourceFileData>['columns'] = [
  37. {
  38. title: '序号',
  39. dataIndex: 'index',
  40. key: 'index',
  41. width: 80,
  42. render: tableCellRender(false, TableCellValueType.Index),
  43. },
  44. {
  45. title: '文件名称',
  46. dataIndex: 'file_name',
  47. key: 'file_name',
  48. render: tableCellRender(false, TableCellValueType.Link, {
  49. onClick: downloadAlone,
  50. }),
  51. },
  52. {
  53. title: '文件大小',
  54. dataIndex: 'file_size',
  55. key: 'file_size',
  56. render: tableCellRender(),
  57. },
  58. {
  59. title: '更新时间',
  60. dataIndex: 'update_time',
  61. key: 'update_time',
  62. render: tableCellRender(false, TableCellValueType.Date),
  63. },
  64. {
  65. title: '操作',
  66. dataIndex: 'option',
  67. width: 160,
  68. key: 'option',
  69. render: (_: any, record: ResourceFileData) => [
  70. <Button
  71. type="link"
  72. size="small"
  73. key="download"
  74. icon={<KFIcon type="icon-xiazai" />}
  75. onClick={() => downloadAlone(record)}
  76. >
  77. 下载
  78. </Button>,
  79. ],
  80. },
  81. ];
  82. return (
  83. <div className={styles['resource-version']}>
  84. <Flex justify="space-between" align="center" style={{ marginBottom: '20px' }}>
  85. <Flex align="center">
  86. <Button
  87. type="default"
  88. disabled={fileList.length === 0}
  89. onClick={handleExport}
  90. icon={<KFIcon type="icon-xiazai" />}
  91. >
  92. 下载
  93. </Button>
  94. </Flex>
  95. </Flex>
  96. <Table columns={columns} dataSource={fileList} pagination={false} rowKey="url" />
  97. </div>
  98. );
  99. }
  100. export default ResourceVersion;