|
|
@@ -1,10 +1,13 @@
|
|
|
import React from 'react'
|
|
|
import { findDOMNode } from 'react-dom'
|
|
|
-import { Layout, Button, Switch, Dropdown, Menu, Icon } from 'antd'
|
|
|
+import { Layout, Tooltip, Button, Tag, Dropdown, Menu, Icon } from 'antd'
|
|
|
import { connect } from 'dva'
|
|
|
import ViewLayout from './viewLayout'
|
|
|
import ChooseChartBox from './chooseChartBox'
|
|
|
-const { Header, Content } = Layout
|
|
|
+import FilterBox from '../common/filterBox/filterBox'
|
|
|
+import ConfigForm from './configForm'
|
|
|
+import moment from 'moment'
|
|
|
+const { Header, Content, Sider } = Layout
|
|
|
|
|
|
class DashboardDesignerContent extends React.Component {
|
|
|
constructor(props) {
|
|
|
@@ -15,9 +18,8 @@ class DashboardDesignerContent extends React.Component {
|
|
|
width: 0,
|
|
|
height: 0,
|
|
|
},
|
|
|
- editMode: true,
|
|
|
- operation: 'create',
|
|
|
- visibleBox: false,
|
|
|
+ visibleChooseChartBox: false,
|
|
|
+ visibleFilterBox: false,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
@@ -34,14 +36,25 @@ class DashboardDesignerContent extends React.Component {
|
|
|
|
|
|
showBox = (o) => {
|
|
|
this.setState({
|
|
|
- operation: o,
|
|
|
- visibleBox: true
|
|
|
+ visibleChooseChartBox: true
|
|
|
});
|
|
|
}
|
|
|
|
|
|
hideBox = (o) => {
|
|
|
this.setState({
|
|
|
- visibleBox: false
|
|
|
+ visibleChooseChartBox: false
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ showFilterBox = (e) => {
|
|
|
+ this.setState({
|
|
|
+ visibleFilterBox: true
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ hideFilterBox = (e) => {
|
|
|
+ this.setState({
|
|
|
+ visibleFilterBox: false,
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -56,34 +69,95 @@ class DashboardDesignerContent extends React.Component {
|
|
|
if(!flag && this.state.contentSize.scroll === _scroll) { // 如果滚动条没有变化则直接退出
|
|
|
return;
|
|
|
}
|
|
|
+ console.log(contentEl.offsetWidth);
|
|
|
this.setState({
|
|
|
contentSize: {
|
|
|
scroll: _scroll,
|
|
|
- width: contentEl.offsetWidth - (_scroll ? 25 : 0), // 有滚动条时需要减去滚动条的宽度
|
|
|
+ width: contentEl.offsetWidth - (_scroll ? 28 : 10), // 有滚动条时需要减去滚动条的宽度
|
|
|
height: contentEl.clientHeight
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ createFilterLabel = (filter) => {
|
|
|
+ let { label, operator, operatorLabel, type, value1, value2 } = filter;
|
|
|
+ let filterLabel;
|
|
|
+
|
|
|
+ if(type === 'string' || type === 'index') {
|
|
|
+ if(operator === 'null' || operator === 'notNull') {
|
|
|
+ filterLabel = `${label} ${operatorLabel}`;
|
|
|
+ }else {
|
|
|
+ filterLabel = `${label} ${operatorLabel} ${value1}`;
|
|
|
+ }
|
|
|
+ }else if(type === 'scale') {
|
|
|
+ if(operator === 'null' || operator === 'notNull') {
|
|
|
+ filterLabel = `${label} ${operatorLabel}`;
|
|
|
+ }else if(operator === 'between') {
|
|
|
+ filterLabel = `${label} ${operatorLabel} ${value1} ~ ${value2}`;
|
|
|
+ }else {
|
|
|
+ filterLabel = `${label} ${operatorLabel} ${value1}`;
|
|
|
+ }
|
|
|
+ }else if(type === 'time') {
|
|
|
+ value1 = moment(value1).format('YYYY/MM/DD');
|
|
|
+ value2 = moment(value2).format('YYYY/MM/DD');
|
|
|
+
|
|
|
+ if(operator === 'null' || operator === 'notNull') {
|
|
|
+ filterLabel = `${label} ${operatorLabel}`;
|
|
|
+ }else if(operator === 'between') {
|
|
|
+ filterLabel = `${label} ${operatorLabel} ${value1} ~ ${value2}`;
|
|
|
+ }else {
|
|
|
+ filterLabel = `${label} ${operatorLabel} ${value1}`;
|
|
|
+ }
|
|
|
+ }else if(type === 'categorical') {
|
|
|
+ if(operator === 'null' || operator === 'notNull') {
|
|
|
+ filterLabel = `${label} ${operatorLabel}`;
|
|
|
+ }else {
|
|
|
+ filterLabel = `${label} ${operatorLabel} ${value1}`;
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ filterLabel = '错误条件';
|
|
|
+ }
|
|
|
+ return filterLabel;
|
|
|
+ }
|
|
|
+
|
|
|
render() {
|
|
|
- const { contentSize, editMode, operation, visibleBox } = this.state;
|
|
|
+ const { dashboardDesigner, dispatch } = this.props;
|
|
|
+ const { code, editMode, filterColumns, filters } = dashboardDesigner;
|
|
|
+ const { contentSize, visibleChooseChartBox, visibleFilterBox } = this.state;
|
|
|
+
|
|
|
+ let tags = filters.map((f, i)=>{
|
|
|
+ return {
|
|
|
+ key: f.key,
|
|
|
+ label: this.createFilterLabel(f),
|
|
|
+ using: f.type ? f.using : false
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
return <Layout className='content'>
|
|
|
<Header>
|
|
|
- <div>
|
|
|
- <Switch
|
|
|
- className={`mode-switch ${editMode ? 'edit-mode-switch' : 'view-mode-switch'}`}
|
|
|
- checked={editMode}
|
|
|
- checkedChildren="编辑"
|
|
|
- unCheckedChildren="浏览"
|
|
|
- onChange={(checked) => {
|
|
|
- this.setState({
|
|
|
- editMode: checked
|
|
|
- })
|
|
|
- }}
|
|
|
- />
|
|
|
- </div>
|
|
|
- <div>
|
|
|
- {editMode && <Dropdown overlay={(
|
|
|
+ <div className='filters'>
|
|
|
+ <div style={{ margin: '0 8px 0 10px' }}>筛选:</div>
|
|
|
+ {tags.map(tag => (
|
|
|
+ <Tag
|
|
|
+ className={`filter-tag ${tag.using?'filter-tag-using':''}`}
|
|
|
+ key={tag.key}
|
|
|
+ closable={false}
|
|
|
+ onClick={this.filterUsingChange}
|
|
|
+ data-key={tag.key}
|
|
|
+ >
|
|
|
+ {tag.label}
|
|
|
+ </Tag>
|
|
|
+ ))}
|
|
|
+ <Tag
|
|
|
+ onClick={this.showFilterBox}
|
|
|
+ className={`filter-tag filter-tag-add`}
|
|
|
+ >
|
|
|
+ <Icon type="filter" theme="outlined" />
|
|
|
+ </Tag>
|
|
|
+ </div>
|
|
|
+ {visibleFilterBox && <FilterBox type='dashboard' code={code} columns={filterColumns} filterData={filters} visibleFilterBox={visibleFilterBox} showFilterBox={this.showFilterBox} hideFilterBox={this.hideFilterBox} createFilters={this.createFilters} />}
|
|
|
+ <div className='viewtype'>
|
|
|
+ {/* {editMode && <Dropdown overlay={(
|
|
|
<Menu onClick={(item) => {
|
|
|
const type = item.key;
|
|
|
if(type === 'chart') {
|
|
|
@@ -100,18 +174,35 @@ class DashboardDesignerContent extends React.Component {
|
|
|
<Button>
|
|
|
<Icon type="plus" />添加
|
|
|
</Button>
|
|
|
- </Dropdown>}
|
|
|
- <ChooseChartBox operation={operation} visibleBox={visibleBox} hideBox={this.hideBox} />
|
|
|
+ </Dropdown>} */}
|
|
|
+ <Tooltip title="图表">
|
|
|
+ <Icon className='viewtype-icon' type="area-chart" theme="outlined" onClick={(item) => {
|
|
|
+ this.showBox("create");
|
|
|
+ }}/>
|
|
|
+ </Tooltip >
|
|
|
+ <Tooltip title="富文本">
|
|
|
+ <Icon className='viewtype-icon' type="book" theme="outlined" onClick={() => {
|
|
|
+ dispatch({ type: 'dashboardDesigner/addRichText' });
|
|
|
+ }}/>
|
|
|
+ </Tooltip>
|
|
|
+ <ChooseChartBox visibleBox={visibleChooseChartBox} hideBox={this.hideBox} />
|
|
|
</div>
|
|
|
</Header>
|
|
|
- <Content ref='contentEl' className='dashboard-content'>
|
|
|
- <ViewLayout contentSize={contentSize} reset={this.refreshContentSize} editMode={editMode}/>
|
|
|
+ <Content className='dashboard-content'>
|
|
|
+ <Layout className='content-layout'>
|
|
|
+ <Content className='viewlayout' ref='contentEl'>
|
|
|
+ <ViewLayout contentSize={contentSize} reset={this.refreshContentSize} editMode={editMode}/>
|
|
|
+ </Content>
|
|
|
+ <Sider className='config-sider' width={!!editMode ? 300 : 0}>
|
|
|
+ <ConfigForm />
|
|
|
+ </Sider>
|
|
|
+ </Layout>
|
|
|
</Content>
|
|
|
</Layout>
|
|
|
}
|
|
|
}
|
|
|
function mapStateToProps(state) {
|
|
|
- const DashboardDesigner = state.present.DashboardDesigner;
|
|
|
- return { DashboardDesigner }
|
|
|
+ const dashboardDesigner = state.present.dashboardDesigner;
|
|
|
+ return { dashboardDesigner }
|
|
|
}
|
|
|
export default connect(mapStateToProps)(DashboardDesignerContent);
|