|
|
@@ -1,51 +1,147 @@
|
|
|
import React from 'react';
|
|
|
-import { Form, Select } from 'antd';
|
|
|
+import { Form, Select, Tag, Cascader, Dropdown, Menu } from 'antd';
|
|
|
const FormItem = Form.Item;
|
|
|
const { Option } = Select;
|
|
|
import { connect } from 'dva';
|
|
|
import chartDesigner from '../../../models/chartDesigner';
|
|
|
+import './barConfigForm.less';
|
|
|
|
|
|
-class barConfigForm extends React.Component {
|
|
|
- render() {
|
|
|
- const props = this.props;
|
|
|
- const columns = props.chartDesigner.columns;
|
|
|
- const { formItemLayout } = props;
|
|
|
-
|
|
|
- return (
|
|
|
- <Form hideRequiredMark={true}>
|
|
|
- <FormItem label='横轴' {...formItemLayout}>
|
|
|
- <Select
|
|
|
- value={props.chartDesigner.barConfig.xAixs}
|
|
|
- labelInValue={true}
|
|
|
- onChange={(value) => {
|
|
|
- props.dispatch({ type: 'chartDesigner/barConfig/setXAixs', xAixs: value});
|
|
|
- }}
|
|
|
- >
|
|
|
- {columns.map((c, i)=>{
|
|
|
- return (<Option key={i} value={c.name}>{c.label}</Option>)
|
|
|
- })}
|
|
|
- </Select>
|
|
|
- </FormItem>
|
|
|
- <FormItem label='纵轴' {...formItemLayout}>
|
|
|
- <Select
|
|
|
- value={props.chartDesigner.barConfig.yAixs}
|
|
|
- labelInValue={true}
|
|
|
- onChange={(value) => {
|
|
|
- props.dispatch({ type: 'chartDesigner/barConfig/setYAixs', yAixs: value});
|
|
|
- }}
|
|
|
- >
|
|
|
- {columns.map((c, i)=>{
|
|
|
- return (<Option key={i} value={c.name}>{c.label}</Option>)
|
|
|
- })}
|
|
|
- </Select>
|
|
|
- </FormItem>
|
|
|
- </Form>
|
|
|
- );
|
|
|
- }
|
|
|
+const barConfigForm = ({ chartDesigner, dispatch, formItemLayout }) => {
|
|
|
+
|
|
|
+
|
|
|
+ const columns = chartDesigner.columns;
|
|
|
+
|
|
|
+ const menu = <Menu>
|
|
|
+ <Menu.Item>
|
|
|
+ <a target="_blank" rel="noopener noreferrer" href="http://www.alipay.com/">1st menu item</a>
|
|
|
+ </Menu.Item>
|
|
|
+ <Menu.Item>
|
|
|
+ <a target="_blank" rel="noopener noreferrer" href="http://www.taobao.com/">2nd menu item</a>
|
|
|
+ </Menu.Item>
|
|
|
+ <Menu.Item>
|
|
|
+ <a target="_blank" rel="noopener noreferrer" href="http://www.tmall.com/">3rd menu item</a>
|
|
|
+ </Menu.Item>
|
|
|
+ </Menu>
|
|
|
+
|
|
|
+ return (
|
|
|
+ <Form hideRequiredMark={true}>
|
|
|
+ <FormItem label='横轴' {...formItemLayout}>
|
|
|
+ <Select
|
|
|
+ value={chartDesigner.barConfig.xAxis}
|
|
|
+ labelInValue={true}
|
|
|
+ onChange={(value) => {
|
|
|
+ dispatch({ type: 'chartDesigner/barConfig/setXAxis', xAxis: value});
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {columns.map((c, i)=>{
|
|
|
+ return (<Option key={i} value={c.name}>{c.label}</Option>)
|
|
|
+ })}
|
|
|
+ </Select>
|
|
|
+ </FormItem>
|
|
|
+ <FormItem label='纵轴' {...formItemLayout}>
|
|
|
+ <Cascader
|
|
|
+ className='barconfig-yxais'
|
|
|
+ value={chartDesigner.barConfig.yAxis}
|
|
|
+ allowClear={true}
|
|
|
+ options={columns.map((c, i)=>{
|
|
|
+ // return (<Option key={i} value={c.name}>{c.label}</Option>)
|
|
|
+ return {
|
|
|
+ value: c.name,
|
|
|
+ label: c.label,
|
|
|
+ children: [{
|
|
|
+ value: 'sum',
|
|
|
+ label: '和计'
|
|
|
+ }, {
|
|
|
+ value: 'avg',
|
|
|
+ label: '平均值'
|
|
|
+ }, {
|
|
|
+ value: 'median',
|
|
|
+ label: '中位数'
|
|
|
+ }, {
|
|
|
+ value: 'count',
|
|
|
+ label: '计数'
|
|
|
+ }, {
|
|
|
+ value: 'distinctCount',
|
|
|
+ label: '不重复计数'
|
|
|
+ }, {
|
|
|
+ value: 'max',
|
|
|
+ label: '最大'
|
|
|
+ }, {
|
|
|
+ value: 'min',
|
|
|
+ label: '最小'
|
|
|
+ }]
|
|
|
+ }
|
|
|
+ })}
|
|
|
+ onChange={(value) => {
|
|
|
+ dispatch({ type: 'chartDesigner/barConfig/setYAxis', yAxis: value});
|
|
|
+ }}
|
|
|
+ displayRender={(label, selectedOptions) => {
|
|
|
+ let menu = selectedOptions.length > 0 ? <Menu>
|
|
|
+ {selectedOptions[0].children.map((c, i) => {
|
|
|
+ return <Menu.Item key={i}>{c.label}</Menu.Item>
|
|
|
+ })}
|
|
|
+ </Menu>: [];
|
|
|
+ let tag = selectedOptions.length > 0 ? <Dropdown
|
|
|
+ trigger='click'
|
|
|
+ overlay={menu}
|
|
|
+ >
|
|
|
+ <Tag size='small'>{label[1]}</Tag>
|
|
|
+ </Dropdown>
|
|
|
+ : null;
|
|
|
+
|
|
|
+ return <div>
|
|
|
+ {tag}
|
|
|
+ <span>{label[0]}</span>
|
|
|
+ </div>
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ </Cascader>
|
|
|
+ </FormItem>
|
|
|
+ </Form>
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
+// class barConfigForm extends React.Component {
|
|
|
+// render() {
|
|
|
+// const props = this.props;
|
|
|
+// const columns = props.chartDesigner.columns;
|
|
|
+// const { formItemLayout } = props;
|
|
|
+
|
|
|
+// return (
|
|
|
+// <Form hideRequiredMark={true}>
|
|
|
+// <FormItem label='横轴' {...formItemLayout}>
|
|
|
+// <Select
|
|
|
+// value={props.chartDesigner.barConfig.xAxis}
|
|
|
+// labelInValue={true}
|
|
|
+// onChange={(value) => {
|
|
|
+// props.dispatch({ type: 'chartDesigner/barConfig/setXAxis', xAxis: value});
|
|
|
+// }}
|
|
|
+// >
|
|
|
+// {columns.map((c, i)=>{
|
|
|
+// return (<Option key={i} value={c.name}>{c.label}</Option>)
|
|
|
+// })}
|
|
|
+// </Select>
|
|
|
+// </FormItem>
|
|
|
+// <FormItem label='纵轴' {...formItemLayout}>
|
|
|
+// <Select
|
|
|
+// value={props.chartDesigner.barConfig.yAxis}
|
|
|
+// labelInValue={true}
|
|
|
+// onChange={(value) => {
|
|
|
+// props.dispatch({ type: 'chartDesigner/barConfig/setYAxis', yAxis: value});
|
|
|
+// }}
|
|
|
+// >
|
|
|
+// {columns.map((c, i)=>{
|
|
|
+// return (<Option key={i} value={c.name}>{c.label}</Option>)
|
|
|
+// })}
|
|
|
+// </Select>
|
|
|
+// </FormItem>
|
|
|
+// </Form>
|
|
|
+// );
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
function mapStateToProps({ present: { chartDesigner } }) {
|
|
|
return { chartDesigner: chartDesigner }
|
|
|
}
|
|
|
|
|
|
-export default Form.create()(connect(mapStateToProps)(barConfigForm));
|
|
|
+export default connect(mapStateToProps)(barConfigForm);
|