|
|
@@ -1,5 +1,5 @@
|
|
|
import React from 'react'
|
|
|
-import { Modal, Tree, Input, Icon, Row, Col, Button } from 'antd'
|
|
|
+import { Modal, Tree, Form, Input, Icon, Row, Col, Button } from 'antd'
|
|
|
import DeleteBox from '../deleteBox/deleteBox'
|
|
|
import { arrayToTree, hashcode } from '../../../utils/baseUtils'
|
|
|
import './box.less'
|
|
|
@@ -20,7 +20,8 @@ class GroupBox extends React.Component {
|
|
|
mGroups: [], // 修改的分组
|
|
|
dGroups: [], // 删除的分组
|
|
|
willDeleteGroup: null,
|
|
|
- visibleDeleteGroupBox: false
|
|
|
+ visibleDeleteGroupBox: false,
|
|
|
+ validInfo: {},
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -43,7 +44,7 @@ class GroupBox extends React.Component {
|
|
|
}
|
|
|
|
|
|
generateTreeNode(treeData) {
|
|
|
- const { filterLabel, editingKey } = this.state;
|
|
|
+ const { filterLabel, editingKey, validInfo } = this.state;
|
|
|
const reg = new RegExp('([+ \\- & | ! ( ) { } \\[ \\] ^ \" ~ * ? : ( ) \/])', 'g'); // 需要转义的字符
|
|
|
const regLabel = filterLabel.replace(new RegExp('(\\\\)', 'g'), '\\$1').replace(reg, '\\$1'); // 添加转义符号
|
|
|
let arr = this.onFilter(treeData, regLabel);
|
|
|
@@ -61,27 +62,54 @@ class GroupBox extends React.Component {
|
|
|
return <TreeNode
|
|
|
title={<div className='node-title'>
|
|
|
{t.code === editingKey ? <div className='input'>
|
|
|
- <Input
|
|
|
- ref={(input) => {this['inputRef-' + t.code] = input}}
|
|
|
- size="small"
|
|
|
- defaultValue={t.label}
|
|
|
- addonAfter={<Icon style={{ cursor: 'pointer', color: '#52C41A' }} type="check-circle" onClick={() => {
|
|
|
- this.setState({ editingKey: false });
|
|
|
- }}/>}
|
|
|
- onBlur={(e) => {
|
|
|
- this.setState({ editingKey: false });
|
|
|
- if(!e.target.value.trim()) {
|
|
|
- return;
|
|
|
- }
|
|
|
- this.modifyGroup({ ...t, label:e.target.value });
|
|
|
- }} onPressEnter={(e) => {
|
|
|
- this.setState({ editingKey: false });
|
|
|
- if(!e.target.value.trim()) {
|
|
|
- return;
|
|
|
- }
|
|
|
- this.modifyGroup({ ...t, label:e.target.value });
|
|
|
- }}
|
|
|
- />
|
|
|
+ <Form.Item
|
|
|
+ status={(validInfo['inputRef-' + t.code] || { status: 'success' }).status}
|
|
|
+ help={(validInfo['inputRef-' + t.code] || { help: '' }).help}
|
|
|
+ >
|
|
|
+ <Input
|
|
|
+ ref={(input) => {this['inputRef-' + t.code] = input}}
|
|
|
+ size="small"
|
|
|
+ defaultValue={t.label}
|
|
|
+ addonAfter={<Icon style={{ cursor: 'pointer', color: '#52C41A' }} type="check-circle" onClick={() => {
|
|
|
+ this.setState({ editingKey: false });
|
|
|
+ }}/>}
|
|
|
+ onChange={e => {
|
|
|
+ let val = e.target.value + '';
|
|
|
+ let status, help;
|
|
|
+ if(val.trim().length === 0) {
|
|
|
+ status = 'error';
|
|
|
+ help = '*分组名称不能为空';
|
|
|
+ }else if(val.trim().length > 20) {
|
|
|
+ status = 'error';
|
|
|
+ help = '*分组名称不能超过20个字符';
|
|
|
+ }else {
|
|
|
+ status = 'success';
|
|
|
+ help = '';
|
|
|
+ }
|
|
|
+ window.clearTimeout(this['inputRef-' + t.code + '-key']);
|
|
|
+ this['inputRef-' + t.code + '-key'] = window.setTimeout(() => {
|
|
|
+ let obj = {};
|
|
|
+ obj['inputRef-' + t.code] = { status, help }
|
|
|
+ this.setState({
|
|
|
+ validInfo: { ...validInfo, ...obj }
|
|
|
+ });
|
|
|
+ }, 100);
|
|
|
+ }}
|
|
|
+ onBlur={(e) => {
|
|
|
+ this.setState({ editingKey: false });
|
|
|
+ if(!e.target.value.trim()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.modifyGroup({ ...t, label:e.target.value });
|
|
|
+ }} onPressEnter={(e) => {
|
|
|
+ this.setState({ editingKey: false });
|
|
|
+ if(!e.target.value.trim()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.modifyGroup({ ...t, label:e.target.value });
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
</div> :
|
|
|
<div className='label' onDoubleClick={() => {
|
|
|
this.setState({
|
|
|
@@ -90,6 +118,8 @@ class GroupBox extends React.Component {
|
|
|
this['inputRef-' + t.code].focus();
|
|
|
});
|
|
|
}}>{title}</div>}
|
|
|
+ { t.code !== editingKey && t.label.trim().length === 0 && <span style={{ position: 'absolute', color: 'red', marginTop: '14px', fontSize: '12px' }}>*分组名称不能为空</span> }
|
|
|
+ { t.code !== editingKey && t.label.length > 20 && <span style={{ position: 'absolute', color: 'red', marginTop: '14px', fontSize: '12px' }}>*分组名称不能超过20个字符</span> }
|
|
|
<div className='tools'>
|
|
|
{t.code !== editingKey && <Icon type='edit' onClick={() => {
|
|
|
this.setState({
|
|
|
@@ -276,6 +306,18 @@ class GroupBox extends React.Component {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ checkValid = () => {
|
|
|
+ const { validInfo } = this.state;
|
|
|
+ let flag = true;
|
|
|
+ for(let k in validInfo) {
|
|
|
+ if(validInfo[k].status === 'error') {
|
|
|
+ flag = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
render() {
|
|
|
let { visibleBox, hideBox, okHandler } = this.props;
|
|
|
let { groupData, expandedKeys, selectedGroup, autoExpandParent, aGroups, mGroups, dGroups, visibleDeleteGroupBox, willDeleteGroup } = this.state;
|
|
|
@@ -284,6 +326,18 @@ class GroupBox extends React.Component {
|
|
|
className='groupmanagement-box'
|
|
|
title={'分组维护'}
|
|
|
visible={visibleBox}
|
|
|
+ footer={
|
|
|
+ <div>
|
|
|
+ <Button onClick={hideBox}>取 消</Button>
|
|
|
+ <Button disabled={!this.checkValid()} type='primary' onClick={() => {
|
|
|
+ if(aGroups.length === 0 && mGroups.length === 0 && dGroups.length === 0) {
|
|
|
+ hideBox()
|
|
|
+ }else {
|
|
|
+ okHandler(aGroups, mGroups, dGroups);
|
|
|
+ }
|
|
|
+ }}>确 定</Button>
|
|
|
+ </div>
|
|
|
+ }
|
|
|
onOk={() => {
|
|
|
okHandler(aGroups, mGroups, dGroups);
|
|
|
}}
|