86133 | aaa3f5d | 2025-04-20 21:33:29 +0800 | [diff] [blame] | 1 | import { Button, Card, message, Layout } from 'antd'; |
| 2 | import React, { useState } from 'react'; |
| 3 | import { history, FormattedMessage } from '@umijs/max'; |
| 4 | import { importTables, queryTableList } from './service'; |
| 5 | import type { GenCodeType } from './data.d'; |
| 6 | import { ProColumns, ProTable } from '@ant-design/pro-components'; |
| 7 | import { PlusOutlined, RollbackOutlined } from '@ant-design/icons'; |
| 8 | |
| 9 | const { Content } = Layout; |
| 10 | |
| 11 | const handleImport = async (tables: string) => { |
| 12 | const hide = message.loading('正在配置'); |
| 13 | try { |
| 14 | await importTables(tables); |
| 15 | hide(); |
| 16 | message.success('配置成功'); |
| 17 | return true; |
| 18 | } catch (error) { |
| 19 | hide(); |
| 20 | message.error('配置失败请重试!'); |
| 21 | return false; |
| 22 | } |
| 23 | }; |
| 24 | |
| 25 | const ImportTableList: React.FC = () => { |
| 26 | const [selectTables, setSelectTables] = useState<string[]>([]); |
| 27 | |
| 28 | const columns: ProColumns<GenCodeType>[] = [ |
| 29 | { |
| 30 | title: '表名称', |
| 31 | dataIndex: 'tableName', |
| 32 | }, |
| 33 | { |
| 34 | title: '表描述', |
| 35 | dataIndex: 'tableComment', |
| 36 | }, |
| 37 | { |
| 38 | title: '创建时间', |
| 39 | dataIndex: 'createTime', |
| 40 | valueType: 'textarea', |
| 41 | hideInSearch: true, |
| 42 | }, |
| 43 | ]; |
| 44 | |
| 45 | return ( |
| 46 | <Content> |
| 47 | <Card bordered={false}> |
| 48 | <ProTable<GenCodeType> |
| 49 | headerTitle="代码生成信息" |
| 50 | rowKey="tableName" |
| 51 | search={{ |
| 52 | labelWidth: 120, |
| 53 | }} |
| 54 | toolBarRender={() => [ |
| 55 | <Button |
| 56 | type="primary" |
| 57 | key="primary" |
| 58 | onClick={async () => { |
| 59 | if (selectTables.length < 1) { |
| 60 | message.error('请选择要导入的表!'); |
| 61 | return; |
| 62 | } |
| 63 | const success = await handleImport(selectTables.join(',')); |
| 64 | if (success) { |
| 65 | history.back(); |
| 66 | } |
| 67 | }} |
| 68 | > |
| 69 | <PlusOutlined /> <FormattedMessage id="gen.submit" defaultMessage="提交" /> |
| 70 | </Button>, |
| 71 | <Button |
| 72 | type="primary" |
| 73 | key="goback" |
| 74 | onClick={() => { |
| 75 | history.back(); |
| 76 | }} |
| 77 | > |
| 78 | <RollbackOutlined /> <FormattedMessage id="gen.goback" defaultMessage="返回" /> |
| 79 | </Button>, |
| 80 | ]} |
| 81 | request={(params) => |
| 82 | queryTableList({ ...params }).then((res) => { |
| 83 | return { |
| 84 | data: res.rows, |
| 85 | total: res.total, |
| 86 | success: true, |
| 87 | }; |
| 88 | }) |
| 89 | } |
| 90 | columns={columns} |
| 91 | rowSelection={{ |
| 92 | onChange: (_, selectedRows) => { |
| 93 | if (selectedRows && selectedRows.length > 0) { |
| 94 | const tables = selectedRows.map((row) => { |
| 95 | return row.tableName; |
| 96 | }); |
| 97 | setSelectTables(tables); |
| 98 | } |
| 99 | }, |
| 100 | }} |
| 101 | /> |
| 102 | </Card> |
| 103 | </Content> |
| 104 | ); |
| 105 | }; |
| 106 | |
| 107 | export default ImportTableList; |