1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import React, { useState, useEffect } from 'react';
import { Form, Modal, Input, Radio, notification } from 'antd';
import { getTableInfo, updateTable } from '@/services/tablemanager/tablemanager';
const AddModal = props => {
const { callBackSubmit = () => {}, type, formObj, visible } = props;
const [loading, setLoading] = useState(false);
const [tableID, setTableID] = useState('');
const [form] = Form.useForm();
const { Item } = Form;
// 提交
const onSubmit = () => {
form.validateFields().then(validate => {
if (validate) {
setLoading(true);
let obj = form.getFieldsValue();
updateTable({
interfaceName: obj.interfaceText,
tableID,
tableName: obj.tableName,
tableStyle: obj.tableStyle,
alias: obj.tableAlias,
officeTmpl: obj.officeTmpl,
}).then(res => {
setLoading(false);
if (res.msg === 'Ok' || res.msg === '') {
form.resetFields();
callBackSubmit();
notification.success({
message: '提示',
duration: 3,
description: '修改成功',
});
} else {
notification.error({
message: '提示',
duration: 3,
description: res.msg,
});
}
});
}
});
};
useEffect(() => {
if (type !== '') {
getTableInfo({ tableName: formObj.tableName }).then(res => {
if (res.data.root && res.data.root.length) {
form.setFieldsValue({
...res.data.root[0],
tableStyle: res.data.root[0].tableStyle === '' ? '大' : res.data.root[0].tableStyle,
});
setTableID(res.data.root[0].tableID);
}
// eslint-disable-next-line no-lone-blocks
// {
// form.setFieldsValue({ tableStyle: '大' });
// }
});
}
}, [visible]);
const layout = {
layout: 'horizontal',
labelCol: {
span: 3,
},
wrapperCol: {
span: 20,
},
};
return (
<Modal
title="修改"
bodyStyle={{ width: '100%', minHeight: '100px' }}
style={{ top: '50px' }}
width="700px"
destroyOnClose
maskClosable={false}
centered
cancelText="取消"
okText="确认"
{...props}
onOk={() => onSubmit()}
confirmLoading={loading}
forceRender
getContainer={false}
>
{visible && (
<Form form={form} {...layout}>
<Item label="表名" name="tableName" rules={[{ required: true, message: '请输入表名' }]}>
<Input placeholder="请输入表名" allowClear />
</Item>
<Item label="别名" name="tableAlias">
<Input placeholder="请输入别名" allowClear />
</Item>
<Item label="样式" name="tableStyle" rules={[{ required: true, message: '请选择样式' }]}>
<Radio.Group>
<Radio value="大">大(3)</Radio>
<Radio value="中">中(4)</Radio>
<Radio value="小">小(5)</Radio>
{/* <Radio value="较小">较小(6)</Radio> */}
</Radio.Group>
</Item>
{/* <Item label="模板" name="officeTmpl">
<Input placeholder="请输入模板" allowClear />
</Item> */}
<Item label="接口" name="interfaceText">
<Input placeholder="请输入接口" allowClear />
</Item>
</Form>
)}
</Modal>
);
};
export default AddModal;