|
|
@@ -0,0 +1,125 @@
|
|
|
+import React from 'react'
|
|
|
+import { Modal, Transfer, Icon, Button, Row, Col } from 'antd'
|
|
|
+import { connect } from 'dva'
|
|
|
+
|
|
|
+
|
|
|
+class DisplayColumnBox extends React.Component {
|
|
|
+ constructor(props){
|
|
|
+ super(props)
|
|
|
+ this.state = {
|
|
|
+ targetKeys: []
|
|
|
+ }
|
|
|
+ }
|
|
|
+ swapItems = (arr, index1, index2) => {
|
|
|
+ let arrClone = JSON.parse(JSON.stringify(arr)) //这里要使用一个深拷贝才能真正地改变state
|
|
|
+ let temp = arrClone[index1]
|
|
|
+ arrClone[index1] = arrClone[index2]
|
|
|
+ arrClone[index2] = temp
|
|
|
+ console.log("changedArrClone", arrClone)
|
|
|
+ this.setState({
|
|
|
+ targetKeys: arrClone
|
|
|
+ }, () => { console.log(`${this.state.targetKeys}`) }
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ upSwap = (index) => {
|
|
|
+ let arr = this.state.targetKeys
|
|
|
+ if (index === 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.swapItems(arr, index, index - 1)
|
|
|
+ }
|
|
|
+
|
|
|
+ downSwap = (index) => {
|
|
|
+ let arr = this.state.targetKeys
|
|
|
+ if (index === arr.length - 1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.swapItems(arr, index, index + 1);
|
|
|
+ };
|
|
|
+
|
|
|
+ renderRow = (item) => {
|
|
|
+ let index = this.state.targetKeys.indexOf(item.key);
|
|
|
+ if (index === -1) {
|
|
|
+ return <span>{item.label}</span>
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ // TODO: 这里样式调整比较麻烦
|
|
|
+ return (
|
|
|
+ <span>
|
|
|
+ {item.label}
|
|
|
+ <span>
|
|
|
+ <Icon type="arrow-up" onClick={() => {this.upSwap(index)}} />
|
|
|
+ <Icon type="arrow-down" onClick={() => {this.downSwap(index)}} />
|
|
|
+ </span>
|
|
|
+ </span>
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ handleChange = (targetKeys) => {
|
|
|
+ this.setState({ targetKeys });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ renderFooter = () => {
|
|
|
+ return (
|
|
|
+ <Button
|
|
|
+ size="small"
|
|
|
+ style={{ float: 'right', margin: 5 }}
|
|
|
+ onClick={this.getMock}
|
|
|
+ >
|
|
|
+ reload
|
|
|
+ </Button>
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ onOk= () => {
|
|
|
+ const { dispatch, chartDesigner, autoRefresh, hideBox } = this.props
|
|
|
+ let viewColumns = chartDesigner.columns.filter(column => this.state.targetKeys.indexOf(column.key) !== -1).map((c) => ({key:c.name, label:c.label}))
|
|
|
+ dispatch({
|
|
|
+ type: 'chartDesigner/changeField',
|
|
|
+ name: 'dataViewConfig',
|
|
|
+ value: { ...chartDesigner.dataViewConfig, viewColumns: viewColumns }, autoRefresh });
|
|
|
+ hideBox()
|
|
|
+ }
|
|
|
+
|
|
|
+ onCancel = () => {
|
|
|
+ const { chartDesigner, hideBox } = this.props
|
|
|
+ this.setState({
|
|
|
+ targetKeys: chartDesigner.dataViewConfig.viewColumns})
|
|
|
+ hideBox()
|
|
|
+ }
|
|
|
+
|
|
|
+ render() {
|
|
|
+ const { visibleDisplayColumnBox } = this.props
|
|
|
+ const { targetKeys } = this.state
|
|
|
+
|
|
|
+ return (
|
|
|
+ <Modal
|
|
|
+ visible={visibleDisplayColumnBox}
|
|
|
+ onCancel={this.onCancel}
|
|
|
+ width={700}
|
|
|
+ style={{textAlign:'center'}}
|
|
|
+ onOk={this.onOk}
|
|
|
+ >
|
|
|
+ <Transfer
|
|
|
+ dataSource={this.props.chartDesigner.columns}
|
|
|
+ showSearch
|
|
|
+ listStyle={{
|
|
|
+ width: 250,
|
|
|
+ height: 300,
|
|
|
+ textAlign:'left'
|
|
|
+ }}
|
|
|
+ operations={['显示', '隐藏']}
|
|
|
+ targetKeys={targetKeys}
|
|
|
+ onChange={this.handleChange}
|
|
|
+ render={this.renderRow}
|
|
|
+ />
|
|
|
+ </Modal>
|
|
|
+ )
|
|
|
+ };
|
|
|
+}
|
|
|
+
|
|
|
+export default connect(({ present: {chartDesigner}}) => ({ chartDesigner}))(DisplayColumnBox);
|