blob: 6e2c8dffd242136650669cb8f8ef530ebec9157d [file] [log] [blame]
Jiarenxiang38dcb052025-03-13 16:40:09 +08001import { Button, Card, message, Layout } from 'antd';
2import React, { useState } from 'react';
3import { history, FormattedMessage } from '@umijs/max';
4import { importTables, queryTableList } from './service';
5import type { GenCodeType } from './data.d';
6import { ProColumns, ProTable } from '@ant-design/pro-components';
7import { PlusOutlined, RollbackOutlined } from '@ant-design/icons';
8
9const { Content } = Layout;
10
11const 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
25const 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
107export default ImportTableList;