blob: 2db5de46b0651a9beb85562403e8eb36386264bf [file] [log] [blame]
86133aaa3f5d2025-04-20 21:33:29 +08001import React, { Fragment, useEffect, useRef, useState } from 'react';
2import type { GenCodeType } from '../data';
3import { Button, Checkbox, Col, Row, Tag } from 'antd';
4import type { FormInstance } from 'antd';
5import { history } from '@umijs/max';
6import styles from '../style.less';
7import { EditableProTable, ProColumns } from '@ant-design/pro-components';
8
9export type ColumnInfoProps = {
10 parentType?: string;
11 data?: any[];
12 dictData?: any[];
13 onStepSubmit?: any;
14};
15
16const booleanEnum = [
17 {
18 label: 'true',
19 value: '1',
20 },
21 {
22 label: 'false',
23 value: '0',
24 },
25];
26
27const ColumnInfo: React.FC<ColumnInfoProps> = (props) => {
28 const formRef = useRef<FormInstance>();
29
30 const [dataSource, setDataSource] = useState<any[]>();
31
32 const [editableKeys, setEditableRowKeys] = useState<React.Key[]>([]);
33
34 const { data, dictData, onStepSubmit } = props;
35
36 const columns: ProColumns<GenCodeType>[] = [
37 {
38 title: '编号',
39 dataIndex: 'columnId',
40 editable: false,
41 width: 80,
42 },
43 {
44 title: '字段名',
45 dataIndex: 'columnName',
46 editable: false,
47 },
48 {
49 title: '字段描述',
50 dataIndex: 'columnComment',
51 hideInForm: true,
52 hideInSearch: true,
53 width: 200,
54 },
55 {
56 title: '字段类型',
57 dataIndex: 'columnType',
58 editable: false,
59 },
60 {
61 title: 'Java类型',
62 dataIndex: 'javaType',
63 valueType: 'select',
64 valueEnum: {
65 Long: {
66 text: 'Long',
67 },
68 String: {
69 text: 'String',
70 },
71 Integer: {
72 text: 'Integer',
73 },
74 Double: {
75 text: 'Double',
76 },
77 BigDecimal: {
78 text: 'BigDecimal',
79 },
80 Date: {
81 text: 'Date',
82 },
83 },
84 },
85 {
86 title: 'Java属性',
87 dataIndex: 'javaField',
88 },
89 {
90 title: '插入',
91 dataIndex: 'isInsert',
92 valueType: 'select',
93 fieldProps: {
94 options: booleanEnum,
95 },
96 render: (_, record) => {
97 return <Checkbox checked={record.isInsert === '1'} />;
98 },
99 },
100 {
101 title: '编辑',
102 dataIndex: 'isEdit',
103 valueType: 'select',
104 fieldProps: {
105 options: booleanEnum,
106 },
107 render: (_, record) => {
108 return <Checkbox checked={record.isEdit === '1'} />;
109 },
110 },
111 {
112 title: '列表',
113 dataIndex: 'isList',
114 valueType: 'select',
115 fieldProps: {
116 options: booleanEnum,
117 },
118 render: (_, record) => {
119 return <Checkbox checked={record.isList === '1'} />;
120 },
121 },
122 {
123 title: '查询',
124 dataIndex: 'isQuery',
125 valueType: 'select',
126 fieldProps: {
127 options: booleanEnum,
128 },
129 render: (_, record) => {
130 return <Checkbox checked={record.isQuery === '1'} />;
131 },
132 },
133 {
134 title: '查询方式',
135 dataIndex: 'queryType',
136 valueType: 'select',
137 valueEnum: {
138 EQ: {
139 text: '=',
140 },
141 NE: {
142 text: '!=',
143 },
144 GT: {
145 text: '>',
146 },
147 GTE: {
148 text: '>=',
149 },
150 LT: {
151 text: '<',
152 },
153 LTE: {
154 text: '<=',
155 },
156 LIKE: {
157 text: 'LIKE',
158 },
159 BETWEEN: {
160 text: 'BETWEEN',
161 },
162 },
163 },
164 {
165 title: '必填',
166 dataIndex: 'isRequired',
167 valueType: 'select',
168 fieldProps: {
169 options: booleanEnum,
170 },
171 render: (_, record) => {
172 return <Checkbox checked={record.isRequired === '1'} />;
173 },
174 },
175 {
176 title: '显示类型',
177 dataIndex: 'htmlType',
178 hideInSearch: true,
179 valueType: 'select',
180 valueEnum: {
181 input: {
182 text: '文本框',
183 },
184 textarea: {
185 text: '文本域',
186 },
187 select: {
188 text: '下拉框',
189 },
190 radio: {
191 text: '单选框',
192 },
193 checkbox: {
194 text: '复选框',
195 },
196 datetime: {
197 text: '日期控件',
198 },
199 imageUpload: {
200 text: '图片上传',
201 },
202 fileUpload: {
203 text: '文件上传',
204 },
205 editor: {
206 text: '富文本控件',
207 },
208 },
209 },
210 {
211 title: '字典类型',
212 dataIndex: 'dictType',
213 hideInSearch: true,
214 valueType: 'select',
215 fieldProps: {
216 options: dictData,
217 },
218 render: (text) => {
219 return <Tag color="#108ee9">{text}</Tag>;
220 },
221 },
222 ];
223
224 useEffect(() => {
225 setDataSource(data);
226 if (data) {
227 setEditableRowKeys(data.map((item) => item.columnId));
228 }
229 }, [data]);
230
231 const onSubmit = (direction: string) => {
232 if (onStepSubmit) {
233 onStepSubmit('column', dataSource, direction);
234 }
235 };
236
237 const onDataChange = (value: readonly GenCodeType[]) => {
238 setDataSource({ ...value } as []);
239 };
240
241 return (
242 <Fragment>
243 <Row>
244 <Col span={24}>
245 <EditableProTable<GenCodeType>
246 formRef={formRef}
247 rowKey="columnId"
248 search={false}
249 columns={columns}
250 value={dataSource}
251 editable={{
252 type: 'multiple',
253 editableKeys,
254 onChange: setEditableRowKeys,
255 actionRender: (row, config, defaultDoms) => {
256 return [defaultDoms.delete];
257 },
258 onValuesChange: (record, recordList) => {
259 setDataSource(recordList);
260 },
261 }}
262 onChange={onDataChange}
263 recordCreatorProps={false}
264 />
265 </Col>
266 </Row>
267 <Row justify="center">
268 <Col span={4}>
269 <Button
270 type="primary"
271 onClick={() => {
272 history.back();
273 }}
274 >
275 返回
276 </Button>
277 </Col>
278 <Col span={4}>
279 <Button
280 type="primary"
281 className={styles.step_buttons}
282 onClick={() => {
283 onSubmit('prev');
284 }}
285 >
286 上一步
287 </Button>
288 </Col>
289 <Col span={4}>
290 <Button
291 type="primary"
292 onClick={() => {
293 onSubmit('next');
294 }}
295 >
296 下一步
297 </Button>
298 </Col>
299 </Row>
300 </Fragment>
301 );
302};
303
304export default ColumnInfo;