|
|
@@ -1,48 +1,185 @@
|
|
|
import React from 'react'
|
|
|
import { connect } from 'dva'
|
|
|
-import { Responsive, WidthProvider } from 'react-grid-layout'
|
|
|
+import ReactGridLayout from 'react-grid-layout'
|
|
|
import '../../models/dashboard'
|
|
|
import '../../../node_modules/react-grid-layout/css/styles.css'
|
|
|
import '../../../node_modules/react-resizable/css/styles.css'
|
|
|
-
|
|
|
-const ResponsiveReactGridLayout = WidthProvider(Responsive);
|
|
|
-
|
|
|
+import dashboardDesigner from '../../models/dashboardDesigner'
|
|
|
+import { Icon, Menu, Layout, Switch, Row, Col, Button, Dropdown } from 'antd';
|
|
|
+import ElementConfig from './elementConfig'
|
|
|
+import './layout.less'
|
|
|
+import Element from './element'
|
|
|
+import dataConnect from '../../models/dataConnect';
|
|
|
+const { Header, Content } = Layout
|
|
|
|
|
|
class DashboardDesigner extends React.Component {
|
|
|
|
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
+ var layout = this.loadLayout()
|
|
|
this.state = {
|
|
|
+ editMode: true,
|
|
|
+ operation: 'create',
|
|
|
+ visibleBox: false,
|
|
|
+ layout: layout,
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ showElementConfigBox = (o) => {
|
|
|
+ this.setState({
|
|
|
+ operation: o,
|
|
|
+ visibleBox: true
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ hideElementConfigBox = (o) => {
|
|
|
+ this.setState({
|
|
|
+ visibleBox: false
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ enableEditMode = (o) => {
|
|
|
+ this.setState({
|
|
|
+ editMode:true
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ disableEditMode = (o) => {
|
|
|
+ this.setState({
|
|
|
+ editMode:false
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ generateElementConfigMenu = (key) => {
|
|
|
+ const {dashboardDesigner, dispatch} = this.props;
|
|
|
+ return (
|
|
|
+ <Menu>
|
|
|
+ <Menu.Item
|
|
|
+ onClick={()=> {
|
|
|
+ let selectedElement = dashboardDesigner.elementList.find((i) => {return i.key == key});
|
|
|
+ dispatch({ type: 'dashboardDesigner/resetConfigBoxForm'});
|
|
|
+ dispatch({ type: 'dashboardDesigner/loadConfigBoxForm', element: selectedElement});
|
|
|
+ this.showElementConfigBox('modify')
|
|
|
+ }}>
|
|
|
+ <span>属性设置</span>
|
|
|
+ </Menu.Item>
|
|
|
+ </Menu>
|
|
|
+
|
|
|
+
|
|
|
+ )
|
|
|
+ }
|
|
|
+ generateElement() {
|
|
|
+ const elementList = this.props.dashboardDesigner.elementList;
|
|
|
+ const editMode = this.state.editMode
|
|
|
+ let IconStyle={
|
|
|
+ display: editMode? 'inline-block':'none',
|
|
|
+ position: 'absolute',
|
|
|
+ right: '3px',
|
|
|
+ top: '3px'
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ return elementList.map ((item) => {
|
|
|
+ if (item.type == 'chart') {
|
|
|
+ return (
|
|
|
+ <div
|
|
|
+ key={item.key.toString()}
|
|
|
+ className={`grid-item${this.state.editMode ?' grid-item-edit': ''}`}
|
|
|
+ >
|
|
|
+ <Element type="chart" content={item.content} itemKey={item.key}/>
|
|
|
+ <Dropdown overlay={this.generateElementConfigMenu(item.key)} trigger={['click']}>
|
|
|
+ <Icon type="setting" style={IconStyle} />
|
|
|
+ </Dropdown>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ }else if (item.type == "simple") {
|
|
|
+ return (
|
|
|
+ <div
|
|
|
+ key={item.key.toString()}
|
|
|
+ className={`grid-item${this.state.editMode ?' grid-item-edit': ''}`}
|
|
|
+ >
|
|
|
+ <Element type="simple" content={item.content} itemKey={item.key}/>
|
|
|
+ <Dropdown overlay={this.generateElementConfigMenu(item.key)} trigger={['click']}>
|
|
|
+ <Icon type="setting" style={IconStyle} />
|
|
|
+ </Dropdown>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ return (<div key="3" >I'm not typed!</div>)
|
|
|
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ loadLayout() {
|
|
|
+ const layout = this.props.dashboardDesigner.layout;
|
|
|
|
|
|
- }
|
|
|
+ return layout.map((item) => {
|
|
|
+ let { key, x, y, w, h, minW, maxW, minH, maxH } = item;
|
|
|
+ return { i: key.toString(), x: x, y: y, w: w, h: h, minW: minW, maxW: maxW, minH: minH, maxH: maxH}
|
|
|
+ })
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
render() {
|
|
|
- let layout = [
|
|
|
- { i: 'a', x: 0, y: 0, w: 1, h: 2, static: true },
|
|
|
- { i: 'b', x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4 },
|
|
|
- { i: 'c', x: 4, y: 0, w: 1, h: 2 }
|
|
|
- ];
|
|
|
+ const { operation, visibleBox, editMode } = this.state;
|
|
|
+
|
|
|
return (
|
|
|
- <ResponsiveReactGridLayout
|
|
|
- className="grid-layout"
|
|
|
- layouts={layout}
|
|
|
- breakpoints={{lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0}}
|
|
|
- cols={{lg: 12, md: 10, sm: 6, xs: 4, xxs: 2}}
|
|
|
- >
|
|
|
- <div key="a">a</div>
|
|
|
- <div key="b">b</div>
|
|
|
- <div key="c">c</div>
|
|
|
- </ResponsiveReactGridLayout>
|
|
|
-
|
|
|
+ <Layout>
|
|
|
+ <Row
|
|
|
+ type='flex'
|
|
|
+ justify ='space-between'
|
|
|
+ className='dashboard-header'
|
|
|
+ >
|
|
|
+ <Col className='dashboard-header-title' >
|
|
|
+ <div>{this.props.dashboardDesigner.basicConfig.title}</div>
|
|
|
+ </Col>
|
|
|
+ <Col className='dashboard-toolbar'>
|
|
|
+ <div>
|
|
|
+ <Button onClick={() => {
|
|
|
+ this.showElementConfigBox("create")
|
|
|
+ }}>
|
|
|
+ 添加元素
|
|
|
+ </Button>
|
|
|
+ <span>编辑模式</span>
|
|
|
+ <Switch
|
|
|
+ checkedChildren="开"
|
|
|
+ unCheckedChildren="关"
|
|
|
+ checked= {editMode}
|
|
|
+ onChange={(checked) => {
|
|
|
+ this.setState({editMode:checked}, () => {this.forceItUpdate})
|
|
|
+ }}
|
|
|
+
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </Col>
|
|
|
+ </Row>
|
|
|
+ <ReactGridLayout
|
|
|
+ className={`grid-layout${this.state.editMode ?' grid-layout-edit': ''}`}
|
|
|
+ cols={12}
|
|
|
+ layout={this.state.layout}
|
|
|
+ rowHeight={30}
|
|
|
+ width={1200} //TODO: 宽度响应式设计?
|
|
|
+ isDraggable={editMode}
|
|
|
+ isResizable={editMode}
|
|
|
+ compactType="horizontal"
|
|
|
+ >
|
|
|
+ {this.generateElement()}
|
|
|
+
|
|
|
+ </ReactGridLayout>
|
|
|
+ <ElementConfig
|
|
|
+ operation={operation}
|
|
|
+ visibleBox={visibleBox}
|
|
|
+ hideElementConfigBox={this.hideElementConfigBox} />
|
|
|
+ </Layout>
|
|
|
)
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
-function mapStateToProps({present: {dashboard}}) {
|
|
|
- return { dashboard }
|
|
|
+function mapStateToProps({present: {dashboardDesigner}}) {
|
|
|
+ return { dashboardDesigner }
|
|
|
}
|
|
|
|
|
|
export default connect(mapStateToProps)(DashboardDesigner)
|