|
@@ -1,8 +1,9 @@
|
|
|
import React from 'react'
|
|
import React from 'react'
|
|
|
-import { Input, Icon, Button, Popconfirm, Tooltip, Modal } from 'antd'
|
|
|
|
|
|
|
+import { Input, Icon, Button, Popconfirm, Tooltip, Modal, Form } from 'antd'
|
|
|
import { connect } from 'dva'
|
|
import { connect } from 'dva'
|
|
|
import DeleteBox from '../common/deleteBox/deleteBox'
|
|
import DeleteBox from '../common/deleteBox/deleteBox'
|
|
|
import './header.less'
|
|
import './header.less'
|
|
|
|
|
+const FormItem = Form.Item
|
|
|
|
|
|
|
|
class Header extends React.Component {
|
|
class Header extends React.Component {
|
|
|
constructor(props) {
|
|
constructor(props) {
|
|
@@ -11,7 +12,10 @@ class Header extends React.Component {
|
|
|
visibleConfirm: false,
|
|
visibleConfirm: false,
|
|
|
visibleCopyBox: false,
|
|
visibleCopyBox: false,
|
|
|
visibleDeleteBox: false,
|
|
visibleDeleteBox: false,
|
|
|
- newHeaderLabel: ''
|
|
|
|
|
|
|
+ newHeaderLabel: '',
|
|
|
|
|
+ validInfo: {
|
|
|
|
|
+ header: { status: 'success', help: '' }
|
|
|
|
|
+ },
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -35,23 +39,33 @@ class Header extends React.Component {
|
|
|
return currentUser.code === creatorCode;
|
|
return currentUser.code === creatorCode;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ isValid = () => {
|
|
|
|
|
+ const { chartDesigner, main } = this.props;
|
|
|
|
|
+ const { header } = chartDesigner;
|
|
|
|
|
+
|
|
|
|
|
+ return !!header.label && header.label.trim().length > 0 && header.label.length <= 50;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
render() {
|
|
render() {
|
|
|
const { chartDesigner, dispatch } = this.props;
|
|
const { chartDesigner, dispatch } = this.props;
|
|
|
- const { visibleCopyBox, newHeaderLabel, visibleDeleteBox } = this.state;
|
|
|
|
|
|
|
+ const { visibleCopyBox, newHeaderLabel, visibleDeleteBox, validInfo } = this.state;
|
|
|
return (
|
|
return (
|
|
|
<div className='header'>
|
|
<div className='header'>
|
|
|
<div className='header-item toolbar-back'>
|
|
<div className='header-item toolbar-back'>
|
|
|
{this.isOwner() && <Popconfirm
|
|
{this.isOwner() && <Popconfirm
|
|
|
|
|
+ overlayClassName={`close-popconfirm${this.isValid() ? '' : ' confirm-disabled'}`}
|
|
|
placement="bottomLeft"
|
|
placement="bottomLeft"
|
|
|
title="离开前保存修改吗?"
|
|
title="离开前保存修改吗?"
|
|
|
visible={this.state.visibleConfirm}
|
|
visible={this.state.visibleConfirm}
|
|
|
onVisibleChange={this.handleVisibleChange}
|
|
onVisibleChange={this.handleVisibleChange}
|
|
|
onConfirm={() => {
|
|
onConfirm={() => {
|
|
|
|
|
+ if(this.isValid()) {
|
|
|
|
|
+ dispatch({ type: 'chart/remoteModify' });
|
|
|
|
|
+ dispatch({ type: 'main/goBack', path: '/chart' });
|
|
|
|
|
+ }
|
|
|
this.setState({
|
|
this.setState({
|
|
|
visibleConfirm: false
|
|
visibleConfirm: false
|
|
|
});
|
|
});
|
|
|
- dispatch({ type: 'chart/remoteModify' });
|
|
|
|
|
- dispatch({ type: 'main/goBack', path: '/chart' });
|
|
|
|
|
}}
|
|
}}
|
|
|
onCancel={() => {
|
|
onCancel={() => {
|
|
|
this.setState({
|
|
this.setState({
|
|
@@ -77,46 +91,61 @@ class Header extends React.Component {
|
|
|
</Button>}
|
|
</Button>}
|
|
|
</div>
|
|
</div>
|
|
|
<div className='header-item toolbar-title'>
|
|
<div className='header-item toolbar-title'>
|
|
|
- <Input
|
|
|
|
|
- key={chartDesigner.header.label}
|
|
|
|
|
- className='input-title'
|
|
|
|
|
- readOnly={!this.isOwner()}
|
|
|
|
|
- defaultValue={chartDesigner.header.label}
|
|
|
|
|
- addonAfter={this.isOwner() ? <Icon type="edit"
|
|
|
|
|
- onClick={(e) => {
|
|
|
|
|
- const input = e.currentTarget.parentElement.parentElement.getElementsByTagName('input')[0];
|
|
|
|
|
- input && input.focus()
|
|
|
|
|
|
|
+ <FormItem
|
|
|
|
|
+ validateStatus={validInfo.header.status}
|
|
|
|
|
+ help={validInfo.header.help}
|
|
|
|
|
+ >
|
|
|
|
|
+ <Input
|
|
|
|
|
+ key={chartDesigner.header.label}
|
|
|
|
|
+ className='input-title'
|
|
|
|
|
+ readOnly={!this.isOwner()}
|
|
|
|
|
+ defaultValue={chartDesigner.header.label}
|
|
|
|
|
+ addonAfter={this.isOwner() ? <Icon type="edit"
|
|
|
|
|
+ onClick={(e) => {
|
|
|
|
|
+ const input = e.currentTarget.parentElement.parentElement.getElementsByTagName('input')[0];
|
|
|
|
|
+ input && input.focus()
|
|
|
|
|
+ }}
|
|
|
|
|
+ /> : ''}
|
|
|
|
|
+ onBlur={(e) => {
|
|
|
|
|
+ dispatch({ type: 'chartDesigner/setField', name: 'header', value: { label: e.target.value + '' } });
|
|
|
}}
|
|
}}
|
|
|
- /> : ''}
|
|
|
|
|
- onBlur={(e) => {
|
|
|
|
|
- let value = e.target.value;
|
|
|
|
|
- if(!!value.trim()) {
|
|
|
|
|
- dispatch({ type: 'chartDesigner/setField', name: 'header', value: { label: e.target.value } });
|
|
|
|
|
- }else {
|
|
|
|
|
- e.target.value = chartDesigner.header.label;
|
|
|
|
|
- }
|
|
|
|
|
- }}
|
|
|
|
|
- onPressEnter={(e) => {
|
|
|
|
|
- let value = e.target.value;
|
|
|
|
|
- if(!!value.trim()) {
|
|
|
|
|
- dispatch({ type: 'chartDesigner/setField', name: 'header', value: { label: e.target.value } });
|
|
|
|
|
- }else {
|
|
|
|
|
- e.target.value = chartDesigner.header.label;
|
|
|
|
|
- }
|
|
|
|
|
- }}
|
|
|
|
|
- />
|
|
|
|
|
|
|
+ onPressEnter={(e) => {
|
|
|
|
|
+ dispatch({ type: 'chartDesigner/setField', name: 'header', value: { label: e.target.value + '' } });
|
|
|
|
|
+ }}
|
|
|
|
|
+ onChange={e => {
|
|
|
|
|
+ let val = e.target.value + '';
|
|
|
|
|
+ let status, help;
|
|
|
|
|
+ if(val.trim().length === 0) {
|
|
|
|
|
+ status = 'error';
|
|
|
|
|
+ help = '数据源名称不能为空';
|
|
|
|
|
+ }else if(val.trim().length > 50) {
|
|
|
|
|
+ status = 'error';
|
|
|
|
|
+ help = '数据源名称不能超过50个字符';
|
|
|
|
|
+ }else {
|
|
|
|
|
+ status = 'success';
|
|
|
|
|
+ help = '';
|
|
|
|
|
+ }
|
|
|
|
|
+ window.clearTimeout(this.headerTimeout);
|
|
|
|
|
+ this.headerTimeout = window.setTimeout(() => {
|
|
|
|
|
+ this.setState({
|
|
|
|
|
+ validInfo: { ...validInfo, header: { status, help } }
|
|
|
|
|
+ });
|
|
|
|
|
+ }, 100);
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ </FormItem>
|
|
|
</div>
|
|
</div>
|
|
|
<div className='header-item toolbar-buttons'>
|
|
<div className='header-item toolbar-buttons'>
|
|
|
- {this.isOwner() && <Button onClick={() => {
|
|
|
|
|
|
|
+ {this.isOwner() && <Button disabled={!this.isValid()} onClick={() => {
|
|
|
if(chartDesigner.code && chartDesigner.code !== -1) {
|
|
if(chartDesigner.code && chartDesigner.code !== -1) {
|
|
|
dispatch({ type: 'chart/remoteModify' });
|
|
dispatch({ type: 'chart/remoteModify' });
|
|
|
}else {
|
|
}else {
|
|
|
dispatch({ type: 'chart/remoteAdd' });
|
|
dispatch({ type: 'chart/remoteAdd' });
|
|
|
}
|
|
}
|
|
|
dispatch({ type: 'chartDesigner/setDirty', dirty: false });
|
|
dispatch({ type: 'chartDesigner/setDirty', dirty: false });
|
|
|
- }}><Icon type='save' />保存</Button>}
|
|
|
|
|
|
|
+ }}>保存</Button>}
|
|
|
{this.isOwner() && <Tooltip title='复制新增'>
|
|
{this.isOwner() && <Tooltip title='复制新增'>
|
|
|
- <Button className='tools-btn' icon='copy' onClick={() => {
|
|
|
|
|
|
|
+ <Button className='tools-btn' onClick={() => {
|
|
|
this.setState({
|
|
this.setState({
|
|
|
visibleCopyBox: true,
|
|
visibleCopyBox: true,
|
|
|
newHeaderLabel: chartDesigner.header.label + '_副本'
|
|
newHeaderLabel: chartDesigner.header.label + '_副本'
|
|
@@ -143,7 +172,7 @@ class Header extends React.Component {
|
|
|
this.setState({
|
|
this.setState({
|
|
|
visibleDeleteBox: true
|
|
visibleDeleteBox: true
|
|
|
});
|
|
});
|
|
|
- }}><Icon type='delete' />删除</Button>}
|
|
|
|
|
|
|
+ }}>删除</Button>}
|
|
|
{visibleDeleteBox && <DeleteBox
|
|
{visibleDeleteBox && <DeleteBox
|
|
|
visibleBox={visibleDeleteBox}
|
|
visibleBox={visibleDeleteBox}
|
|
|
text={<div><span>确定要删除图表【{chartDesigner.header.label}】吗?</span></div>}
|
|
text={<div><span>确定要删除图表【{chartDesigner.header.label}】吗?</span></div>}
|