mirror of https://github.com/openspug/spug
62 lines
1.9 KiB
JavaScript
62 lines
1.9 KiB
JavaScript
import React from 'react';
|
||
import { observer } from 'mobx-react';
|
||
import { Modal, Form, Input, message } from 'antd';
|
||
import http from 'libs/http';
|
||
import store from './store';
|
||
|
||
@observer
|
||
class ComForm extends React.Component {
|
||
constructor(props) {
|
||
super(props);
|
||
this.state = {
|
||
loading: false,
|
||
}
|
||
}
|
||
|
||
handleSubmit = () => {
|
||
this.setState({loading: true});
|
||
const formData = this.props.form.getFieldsValue();
|
||
formData['id'] = store.record.id;
|
||
http.post('/api/config/environment/', formData)
|
||
.then(res => {
|
||
message.success('操作成功');
|
||
store.formVisible = false;
|
||
store.fetchRecords()
|
||
}, () => this.setState({loading: false}))
|
||
};
|
||
|
||
render() {
|
||
const info = store.record;
|
||
const {getFieldDecorator} = this.props.form;
|
||
return (
|
||
<Modal
|
||
visible
|
||
width={800}
|
||
maskClosable={false}
|
||
title={store.record.id ? '编辑环境' : '新建环境'}
|
||
onCancel={() => store.formVisible = false}
|
||
confirmLoading={this.state.loading}
|
||
onOk={this.handleSubmit}>
|
||
<Form labelCol={{span: 6}} wrapperCol={{span: 14}}>
|
||
<Form.Item required label="环境名称">
|
||
{getFieldDecorator('name', {initialValue: info['name']})(
|
||
<Input placeholder="请输入环境名称,例如:开发环境"/>
|
||
)}
|
||
</Form.Item>
|
||
<Form.Item required label="唯一标识符">
|
||
{getFieldDecorator('key', {initialValue: info['key']})(
|
||
<Input placeholder="请输入唯一标识符,例如:dev"/>
|
||
)}
|
||
</Form.Item>
|
||
<Form.Item label="备注信息">
|
||
{getFieldDecorator('desc', {initialValue: info['desc']})(
|
||
<Input.TextArea placeholder="请输入备注信息"/>
|
||
)}
|
||
</Form.Item>
|
||
</Form>
|
||
</Modal>
|
||
)
|
||
}
|
||
}
|
||
|
||
export default Form.create()(ComForm) |