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
import React, { useState, useEffect } from 'react';
import { Form, Modal, Input, Select, AutoComplete, Button, notification } from 'antd';
import { SetServiceConfig } from '@/services/webConfig/api';
const { Option } = Select;
const AddModal = props => {
const { callBackSubmit = () => {}, type, formObj, visible, listData } = props;
const [loading, setLoading] = useState(false);
const [form] = Form.useForm();
const { Item } = Form;
// 提交
const onSubmit = () => {
form.validateFields().then(validate => {
if (validate) {
setLoading(true);
let obj = form.getFieldsValue();
SetServiceConfig({
schemename: obj.schemename,
terminalType: type === 'add' ? 'web' : 'phone',
isBaseMap: 'false',
jsonCfg:
type === 'add'
? JSON.stringify({ type: 'dynamic' })
: JSON.stringify({ isDefault: false }),
})
.then(res => {
setLoading(false);
if (res.code == '0') {
form.resetFields();
callBackSubmit();
notification.success({
message: '提示',
duration: 3,
description: '新增成功',
});
} else {
notification.error({
message: '提示',
duration: 3,
description: '新增失败',
});
}
})
.catch(err => {
notification.error({
message: '提示',
duration: 3,
description: '新增失败',
});
setLoading(false);
});
}
});
};
const onFinish = value => {};
useEffect(() => {
if (type != '') {
form.setFieldsValue({ schemename: listData[0] });
}
}, [visible]);
const layout = {
layout: 'horizontal',
labelCol: {
span: 3,
},
wrapperCol: {
span: 20,
},
};
const handleChange = value => {
form.setFieldsValue({ schemename: value });
};
return (
<Modal
title={`${type === 'add' ? '元数据发布' : '编辑'}`}
bodyStyle={{ width: '100%' }}
style={{ top: '150px' }}
width="700px"
destroyOnClose
maskClosable={false}
cancelText="取消"
okText="确认"
{...props}
onOk={() => onSubmit()}
confirmLoading={loading}
forceRender={true}
getContainer={false}
>
{visible && (
<Form form={form} {...layout} onFinish={onFinish}>
<Item
label="方案名"
name="schemename"
rules={[{ required: true, message: '请选择服务名' }]}
>
<Select onChange={handleChange}>
{listData.map((item, index) => {
return (
<Option value={item} key={index}>
{item}
</Option>
);
})}
</Select>
</Item>
</Form>
)}
</Modal>
);
};
export default AddModal;