dataViewConfigForm.jsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import React from 'react'
  2. import { Form, Select, Cascader } from 'antd'
  3. import { connect } from 'dva'
  4. const FormItem = Form.Item
  5. const { Option } = Select
  6. class DataViewConfigForm extends React.Component {
  7. render() {
  8. const { dispatch, chartDesigner, formItemLayout } = this.props;
  9. const columns = chartDesigner.columns;
  10. return (
  11. <Form layout='horizontal'>
  12. <FormItem label="展示列" {...formItemLayout}>
  13. <Select
  14. mode='multiple'
  15. allowClear
  16. value={chartDesigner.dataViewConfig.viewColumns}
  17. onChange={(value) => {
  18. dispatch({ type: 'chartDesigner/changeField', name: 'dataViewConfig', value: { ...chartDesigner.dataViewConfig, viewColumns: value }});
  19. }}
  20. >
  21. {columns.map((c, i)=>{
  22. return <Option key={i} value={c.name}>{c.label}</Option>
  23. })}
  24. </Select>
  25. </FormItem>
  26. <FormItem label='排序列' {...formItemLayout}>
  27. <Cascader
  28. // value={[chartDesigner.dataViewConfig.sortColumn.name, chartDesigner.dataViewConfig.sortColumn.sortType]}
  29. allowClear={true}
  30. options={columns.filter(c =>['ordinal', 'categorical', 'time'].indexOf(c.type) !== -1).map((c, i)=>{
  31. return {
  32. type: c.type,
  33. value: c.name,
  34. label: c.label,
  35. }
  36. })}
  37. onChange={(value, items) => {
  38. // let column = {};
  39. // let granularity = {};
  40. // if(items.length > 0) {
  41. // column = { type: items[0].type, value: items[0].value, label: items[0].label };
  42. // }
  43. // if(items.length > 1) {
  44. // granularity = { value: items[1].value, label: items[1].label };
  45. // }
  46. // dispatch({ type: 'chartDesigner/changeField', name: 'sortColumn', value: { ...chartDesigner.dataViewConfig, sortColumn: { column, granularity } } });
  47. }}
  48. displayRender={(label, selectedOptions) => {
  49. let text = '';
  50. let className = 'cascader-label';
  51. if(label.length > 0) {
  52. className += ' full-label';
  53. text += label[0];
  54. if(label.length > 1) {
  55. text += '(' + label[1] + ')';
  56. }
  57. }else {
  58. className += ' empty-label';
  59. text = '请选择...';
  60. }
  61. return <div className={className}>{text}</div>;
  62. }}
  63. >
  64. </Cascader>
  65. </FormItem>
  66. </Form>
  67. );
  68. }
  69. }
  70. function mapStateToProps({ present: { chartDesigner } }) {
  71. return { chartDesigner: chartDesigner }
  72. }
  73. export default Form.create()(connect(mapStateToProps)(DataViewConfigForm));