aggregateTableConfigForm.jsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import React from 'react';
  2. import { Form, Icon, Input, Button, Select, Switch, Checkbox } from 'antd';
  3. const FormItem = Form.Item;
  4. const { Option } = Select;
  5. const CheckboxGroup = Checkbox.Group;
  6. class AggregateTableConfigForm extends React.Component {
  7. constructor(props) {
  8. super(props);
  9. this.state = {
  10. config: props.config
  11. }
  12. }
  13. componentDidMount() {
  14. // To disabled submit button at the beginning.
  15. this.props.form.validateFields();
  16. }
  17. onChange(checkedList) {
  18. console.log(checkedList);
  19. }
  20. render() {
  21. const { config } = this.state;
  22. const columns = [
  23. { value: 'c1', label: '列1' },
  24. { value: 'c2', label: '列2' },
  25. { value: 'c3', label: '列3' },
  26. { value: 'c4', label: '列4' },
  27. { value: 'c5', label: '列5' },
  28. ];
  29. let targetColumn = ['c3'];
  30. const statisticsOptions = [
  31. { value: 'count', label: '条数', checked: true },
  32. { value: 'max', label: '最大值', checked: true },
  33. { value: 'percentage', label: '百分比', checked: true },
  34. { value: '75th', label: '75th值', checked: true },
  35. { value: 'sum', label: '总和', checked: true },
  36. { value: 'median', label: '中位数', checked: false },
  37. { value: 'avg', label: '平均数', checked: true },
  38. { value: '25th', label: '25th值', checked: true },
  39. { value: 'std', label: '标准差', checked: true },
  40. { value: 'min', label: '最小值', checked: true }
  41. ];
  42. let filterFunc = function(option) {
  43. return option.checked == true;
  44. }
  45. const { getFieldDecorator, getFieldsError, getFieldError, isFieldTouched } = this.props.form;
  46. const formItemLayout = {
  47. labelCol: { span: 10 },
  48. wrapperCol: { span: 14 },
  49. };
  50. return (
  51. <Form layout='horizontal'>
  52. <FormItem label='分析目标' {...formItemLayout}>
  53. {getFieldDecorator('targetColumn', {
  54. rules: [{ required: true, message: '分析目标不能为空' }],
  55. initialValue : targetColumn
  56. })(
  57. <Select mode='multiple'>
  58. {columns.map((c, i)=>{
  59. return (<Option key={`c-${i}`} value={c.value}>{c.label}</Option>)
  60. })}
  61. </Select>
  62. )}
  63. </FormItem>
  64. <FormItem label='显示总体数据' {...formItemLayout}>
  65. {getFieldDecorator('statistics', {
  66. initialValue: statisticsOptions.filter(filterFunc).map((s)=>{return s.label})
  67. })(
  68. <CheckboxGroup options={statisticsOptions.map((s)=>{return s.label})} onChange={this.onChange} />
  69. )}
  70. </FormItem>
  71. </Form>
  72. );
  73. }
  74. }
  75. export default Form.create()(AggregateTableConfigForm);