|
|
@@ -11,7 +11,17 @@ class DataConnectBox extends React.Component {
|
|
|
super(props);
|
|
|
this.state = {
|
|
|
password: '',
|
|
|
- passwordEditing: false
|
|
|
+ passwordEditing: false,
|
|
|
+ validInfo: {
|
|
|
+ name: { status: 'success', help: '' },
|
|
|
+ dbType: { status: 'success', help: '' },
|
|
|
+ address: { status: 'success', help: '' },
|
|
|
+ port: { status: 'success', help: '' },
|
|
|
+ dbName: { status: 'success', help: '' },
|
|
|
+ userName: { status: 'success', help: '' },
|
|
|
+ password: { status: 'success', help: '' },
|
|
|
+ description: { status: 'success', help: '' },
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -36,15 +46,23 @@ class DataConnectBox extends React.Component {
|
|
|
|
|
|
checkValid() {
|
|
|
const { dataConnect } = this.props;
|
|
|
+ const { validInfo } = this.state;
|
|
|
const { newOne } = dataConnect;
|
|
|
+ let flag = true;
|
|
|
|
|
|
- return !!newOne && !!newOne.name && !!newOne.dbType && !!newOne.address && !!newOne.port &&
|
|
|
- !!newOne.dbName && !!newOne.userName && (newOne.boxOperation === 'create' ? !!newOne.password : true);
|
|
|
+ for(let k in validInfo) {
|
|
|
+ if(validInfo[k].status === 'error') {
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return flag && !!newOne && !!newOne.name && newOne.name.length <= 50 && !!newOne.dbType && !!newOne.address && !!newOne.port &&
|
|
|
+ !!newOne.dbName && !!newOne.userName && newOne.description.length <= 500 && (newOne.boxOperation === 'create' ? !!newOne.password : true);
|
|
|
}
|
|
|
|
|
|
render() {
|
|
|
const { dispatch, dataConnect } = this.props;
|
|
|
- const { password, passwordEditing } = this.state;
|
|
|
+ const { password, passwordEditing, validInfo } = this.state;
|
|
|
const operation = dataConnect.newOne.boxOperation;
|
|
|
const disabled = operation === 'view';
|
|
|
|
|
|
@@ -92,14 +110,23 @@ class DataConnectBox extends React.Component {
|
|
|
className='required'
|
|
|
label='链接名'
|
|
|
{...formItemLayout}
|
|
|
- validateStatus={(dataConnect.newOne.name === undefined || dataConnect.newOne.name) ? 'success' : 'error'}
|
|
|
- help={dataConnect.newOne.name === undefined || dataConnect.newOne.name ? '' : '链接名不能为空'}
|
|
|
+ validateStatus={validInfo.name.status}
|
|
|
+ help={validInfo.name.help}
|
|
|
>
|
|
|
<Input
|
|
|
disabled={disabled}
|
|
|
placeholder="输入数据链接名称"
|
|
|
- value={dataConnect.newOne.name}
|
|
|
- onChange={(e) => { dispatch({ type: 'dataConnect/setNewModelField', name: 'name', value: e.target.value }) }}
|
|
|
+ defaultValue={dataConnect.newOne.name}
|
|
|
+ onChange={e => {
|
|
|
+ let val = e.target.value;
|
|
|
+ window.clearTimeout(this.nameTimeout);
|
|
|
+ this.nameTimeout = window.setTimeout(() => {
|
|
|
+ this.setState({
|
|
|
+ validInfo: { ...validInfo, name: { status: (!val || (val+'').trim().length > 50 || (val+'').trim().length === 0) ? 'error' : 'success', help: (val+'').trim().length > 50 ? '链接名不能超过50个字符' : ((val+'').trim().length === 0 ? '链接名不能为空' : '') } }
|
|
|
+ });
|
|
|
+ }, 100);
|
|
|
+ }}
|
|
|
+ onBlur={(e) => { dispatch({ type: 'dataConnect/setNewModelField', name: 'name', value: e.target.value }) }}
|
|
|
>
|
|
|
</Input>
|
|
|
</FormItem>
|
|
|
@@ -142,8 +169,8 @@ class DataConnectBox extends React.Component {
|
|
|
<Input
|
|
|
disabled={disabled}
|
|
|
placeholder="格式:192.168.1.1"
|
|
|
- value={dataConnect.newOne.address}
|
|
|
- onChange={(e) => {
|
|
|
+ defaultValue={dataConnect.newOne.address}
|
|
|
+ onBlur={(e) => {
|
|
|
dispatch({ type: 'dataConnect/setNewModelField', name: 'address', value: e.target.value });
|
|
|
}}
|
|
|
/>
|
|
|
@@ -159,9 +186,9 @@ class DataConnectBox extends React.Component {
|
|
|
>
|
|
|
<InputNumber
|
|
|
disabled={disabled}
|
|
|
- defaultValue={1521}
|
|
|
- value={dataConnect.newOne.port}
|
|
|
- onChange={(value) => {
|
|
|
+ defaultValue={dataConnect.newOne.port ? Number(dataConnect.newOne.port) : 1521}
|
|
|
+ // value={dataConnect.newOne.port}
|
|
|
+ onBlur={(value) => {
|
|
|
dispatch({ type: 'dataConnect/setNewModelField', name: 'port', value: value });
|
|
|
}}
|
|
|
/>
|
|
|
@@ -174,9 +201,9 @@ class DataConnectBox extends React.Component {
|
|
|
>
|
|
|
<Input
|
|
|
disabled={disabled}
|
|
|
- defaultValue='orcl'
|
|
|
- value={dataConnect.newOne.dbName}
|
|
|
- onChange={(e) => {
|
|
|
+ // defaultValue='orcl'
|
|
|
+ defaultValue={dataConnect.newOne.dbName || 'orcl'}
|
|
|
+ onBlur={(e) => {
|
|
|
dispatch({ type: 'dataConnect/setNewModelField', name: 'dbName', value: e.target.value });
|
|
|
}}
|
|
|
/>
|
|
|
@@ -192,8 +219,8 @@ class DataConnectBox extends React.Component {
|
|
|
>
|
|
|
<Input
|
|
|
disabled={disabled}
|
|
|
- value={dataConnect.newOne.userName}
|
|
|
- onChange={(e) => {
|
|
|
+ defaultValue={dataConnect.newOne.userName}
|
|
|
+ onBlur={(e) => {
|
|
|
dispatch({ type: 'dataConnect/setNewModelField', name: 'userName', value: e.target.value });
|
|
|
}}
|
|
|
/>
|
|
|
@@ -246,12 +273,27 @@ class DataConnectBox extends React.Component {
|
|
|
</FormItem>
|
|
|
</Col>
|
|
|
</Row>
|
|
|
- <FormItem className='textarea-desc' label='说明' {...formItemLayout}>
|
|
|
+ <FormItem
|
|
|
+ className='textarea-desc'
|
|
|
+ label='说明'
|
|
|
+ {...formItemLayout}
|
|
|
+ validateStatus={validInfo.description.status}
|
|
|
+ help={validInfo.description.help}
|
|
|
+ >
|
|
|
<Input.TextArea
|
|
|
disabled={disabled}
|
|
|
autosize={{ minRows: 2 }}
|
|
|
- value={dataConnect.newOne.description}
|
|
|
- onChange={(e) => {
|
|
|
+ defaultValue={dataConnect.newOne.description}
|
|
|
+ onChange={e => {
|
|
|
+ let val = e.target.value;
|
|
|
+ window.clearTimeout(this.nameTimeout);
|
|
|
+ this.nameTimeout = window.setTimeout(() => {
|
|
|
+ this.setState({
|
|
|
+ validInfo: { ...validInfo, description: { status: (!!val && (val+'').trim().length > 500) ? 'error' : 'success', help: (!!val && (val+'').trim().length > 500) ? '说明不能超过500个字符' : '' } }
|
|
|
+ });
|
|
|
+ }, 100);
|
|
|
+ }}
|
|
|
+ onBlur={(e) => {
|
|
|
dispatch({ type: 'dataConnect/setNewModelField', name: 'description', value: e.target.value });
|
|
|
}}
|
|
|
/>
|