baseConfigForm.jsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import React from 'react';
  2. import { Form, Icon, Input, Button, Select, Switch } from 'antd';
  3. const FormItem = Form.Item;
  4. const { Option } = Select;
  5. import emitter from '../../../eventManger/ev'
  6. function hasErrors(fieldsError) {
  7. return Object.keys(fieldsError).some(field => fieldsError[field]);
  8. }
  9. class baseConfigForm extends React.Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. config: props.config
  14. }
  15. }
  16. componentDidMount() {
  17. // To disabled submit button at the beginning.
  18. this.props.form.validateFields();
  19. }
  20. changeViewType(value, ele) {
  21. let viewType = {
  22. name: value,
  23. label: ele.props.children
  24. }
  25. emitter.emit('changeViewType', viewType);
  26. }
  27. render() {
  28. const { config } = this.state;
  29. const { viewType, note, currentDataSource, accessPermission, editPermission, showLegend, showTooltip, datazoom, toolbox } = config;
  30. const allDataSource = [
  31. { id: 'd1', name: '数据源1' },
  32. { id: 'd2', name: '数据源2' },
  33. { id: 'd3', name: '数据源3' },
  34. { id: 'd4', name: '数据源4' },
  35. { id: 'd5', name: '数据源5' },
  36. { id: 'd6', name: '数据源6' },
  37. ];
  38. const allPermission = [
  39. { value: 'owner', name: '创建人' },
  40. { value: 'anyone', name: '所有人' }
  41. ];
  42. const { getFieldDecorator, getFieldsError, getFieldError, isFieldTouched } = this.props.form;
  43. const formItemLayout = {
  44. labelCol: { span: 9 },
  45. wrapperCol: { span: 15 },
  46. };
  47. return (
  48. <Form hideRequiredMark={true}>
  49. <FormItem label='数据源' {...formItemLayout}>
  50. {getFieldDecorator('dataSource', {
  51. rules: [{ required: true, message: '数据源不能为空' }],
  52. initialValue: currentDataSource
  53. })(
  54. <Select>
  55. {allDataSource.map((dataSource, i)=>{
  56. return (<Option key={`dataSource-${i}`} value={dataSource.id}>{dataSource.name}</Option>)
  57. })}
  58. </Select>
  59. )}
  60. </FormItem>
  61. <FormItem label='可视化模式' {...formItemLayout}>
  62. {getFieldDecorator('viewType', {
  63. rules: [{ required: true, message: '可视化模式不能为空' }],
  64. initialValue : viewType
  65. })(
  66. <Select onChange={this.changeViewType}>
  67. <Option value='aggregateTable'>总体统计数据表</Option>
  68. <Option value='dataView'>个体统计数据表</Option>
  69. <Option value='line'>折线图</Option>
  70. <Option value='bar'>柱状图</Option>
  71. <Option value='pie'>饼状图</Option>
  72. <Option value='scatter'>散点图</Option>
  73. </Select>
  74. )}
  75. </FormItem>
  76. </Form>
  77. );
  78. }
  79. }
  80. export default Form.create()(baseConfigForm);