addOrUpd.js
8.16 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import React from 'react';
import { NavLink } from 'react-router-dom';
import { UserManageBar, } from '@components/Common';
import {Input,Form,Row,Col,Message,Button, Spin} from 'antd';
import './style.less';
import { API_SYSPARAM_MANAGE } from '@src/Api';
import axios from '@src/axios/index';
import Utils from '@src/utils/utils';
class SysParamUpdOrAdd extends React.Component{
state = {
expandedKeys: [],
autoExpandParent: true,
checkedKeys: [],
selectedKeys: [],
menuName: '新增参数',
treeData: [],
roleInfo: [],
expandMenu: {},
originInfo: {},
spinStatus: false, // 是否显示加载中
}
componentDidMount () {
let originInfo = this.props.location.state;
if (originInfo) {
this.setState({menuName: '修改参数'});
} else {
this.setState({menuName: '新增参数'});
}
}
render () {
const {menuName} = this.state;
let originInfo = this.props.location.state;
return (
<div className="roleAdd">
<div className="nav">
<NavLink to='/home/system/sysParam'>参数设置 > </NavLink> <span>{menuName}</span>
</div>
<UserManageBar title="基本信息" />
<ParaForm originInfo={originInfo} history={this.props.history} />
</div>
)
}
}
/* 新增参数表单 */
const ParaForm = Form.create()(
class extends React.Component {
state = {
// 修改参数的id
paramId: '',
nameDisabled:false,
spinStatus: false,
};
componentDidMount () {
let originInfo = this.props.originInfo;
if (originInfo) {
let paramId = originInfo.id;
let {paramName,paramKeyName,paramKeyValue,description} = originInfo;
this.props.form.setFieldsValue({paramName,paramKeyName,paramKeyValue,description});
this.setState({paramId,nameDisabled:true});
}
}
// 验证参数并提交
save = () => {
// 校验参数
this.props.form.validateFields((err, values) => {
if (!err) {
this.submit(values);
}
});
}
// 提交保存信息
submit = (subData) => {
this.setState({spinStatus: true})
axios.optAjax({
url: API_SYSPARAM_MANAGE.insertSysParam,
data: {
...subData,
id: this.state.paramId
}
}).then((res) => {
if (res && res.code && res.code !== 0){
this.setState({
spinStatus: false,
})
return
}
if (this.state.paramId) {
Message.success('修改参数成功');
} else {
Message.success('新增参数成功');
this.props.form.resetFields();
}
this.setState({spinStatus: false})
this.props.history.push({
pathname: '/home/system/sysParam'
});
});
}
// 返回
goBack = () => {
this.props.history.push({
pathname: '/home/system/sysParam'
});
}
render () {
const FormItem = Form.Item;
const {getFieldDecorator} = this.props.form;
const Textarea = Input.TextArea;
const comStyle = {
background: '#fff',
padding: 15
}
return (
<div className="com-paraForm" style={comStyle}>
<Spin tip="加载中..." spinning = {this.state.spinStatus}>
<Form layout="inline">
<Row>
<Col span={6}>
<FormItem label="参数名称">
{
getFieldDecorator('paramName',{
rules: [
{required: true,message: '请填写参数名称'},
{max:20,message: '参数名称不能超过20个字符'},
{pattern: /^(?!_)(?!.*?_$)[a-zA-Z0-9_\u4e00-\u9fa5]+$/, message: '参数名称不能有特殊字符'}
]
})(<Input type="text" placeholder="参数名称" />)
}
</FormItem>
</Col>
<Col span={6}>
<FormItem label="参数键名">
{
getFieldDecorator('paramKeyName',{
validateFirst: true,
rules: [
{required: true,message: '请填写参数键名'},
{max:64,message:'参数键名不能超过64个字符'},
{pattern: /^[\.a-zA-Z0-9\u4e00-\u9fa5]+$/, message: '参数键名不能有特殊字符'}
]
})(<Input disabled={this.state.nameDisabled} type="text" placeholder="参数键名" />)
}
</FormItem>
</Col>
<Col span={6}>
<FormItem label="参数键值">
{
getFieldDecorator('paramKeyValue',{
validateFirst: true,
rules: [
{required: true,message: '请填写参数键值'},
{max:20,message:'参数键值不能超过20个字符'},
{pattern: /^[\.a-zA-Z0-9\u4e00-\u9fa5]+$/, message: '参数键值不能有特殊字符'}
]
})(<Input type="text" placeholder="参数键值" />)
}
</FormItem>
</Col>
</Row>
<Row style={{marginTop: 20}}>
<Col span={20} style={{paddingLeft:12}}>
<FormItem label="参数描述" className="form-des">
{
getFieldDecorator('description',{
rules: [
{max:200,message:'参数键值不能超过200个字符'}
]
})(<Textarea rows={10} cols={10} placeholder="为了方便他人理解,请描述参数含义及参数键值的单位" />)
}
</FormItem>
</Col>
</Row>
<Row style={{marginTop: 20}}>
<Col span={20}>
<div style={{textAlign: 'center'}}>
<Button disabled = {this.state.spinStatus} onClick={this.save} style={{background: '#5468D9',marginRight:20,color:'#fff'}}>保存</Button>
<Button onClick={this.goBack}>返回</Button>
</div>
</Col>
</Row>
</Form>
</Spin>
</div>
);
}
}
);
export default SysParamUpdOrAdd;