baseConfigForm.jsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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('viewType', {
  51. rules: [{ required: true, message: '可视化模式不能为空' }],
  52. initialValue : viewType
  53. })(
  54. <Select onChange={this.changeViewType}>
  55. <Option value='aggregateTable'>总体统计数据表</Option>
  56. <Option value='dataView'>个体统计数据表</Option>
  57. <Option value='line'>折线图</Option>
  58. <Option value='bar'>柱状图</Option>
  59. <Option value='pie'>饼状图</Option>
  60. <Option value='scatter'>散点图</Option>
  61. </Select>
  62. )}
  63. </FormItem>
  64. <FormItem label='描述' {...formItemLayout}>
  65. {getFieldDecorator('note', {
  66. initialValue: note
  67. })(
  68. <Input placeholder="请输入" />
  69. )}
  70. </FormItem>
  71. <FormItem label='数据源' {...formItemLayout}>
  72. {getFieldDecorator('dataSource', {
  73. rules: [{ required: true, message: '数据源不能为空' }],
  74. initialValue: currentDataSource
  75. })(
  76. <Select>
  77. {allDataSource.map((dataSource, i)=>{
  78. return (<Option key={`dataSource-${i}`} value={dataSource.id}>{dataSource.name}</Option>)
  79. })}
  80. </Select>
  81. )}
  82. </FormItem>
  83. <FormItem label='访问权限' {...formItemLayout}>
  84. {getFieldDecorator('accessPermission', {
  85. rules: [{ required: true, message: '访问权限不能为空' }],
  86. initialValue: accessPermission
  87. })(
  88. <Select mode="multiple">
  89. {allPermission.map((accessPermission, i)=>{
  90. return (<Option key={`accessPermission-${i}`} value={accessPermission.value}>{accessPermission.name}</Option>)
  91. })}
  92. </Select>
  93. )}
  94. </FormItem>
  95. <FormItem label='修改权限' {...formItemLayout}>
  96. {getFieldDecorator('editPermission', {
  97. rules: [{ required: true, message: '修改权限不能为空' }],
  98. initialValue: editPermission
  99. })(
  100. <Select mode="multiple">
  101. {allPermission.map((editPermission, i)=>{
  102. return (<Option key={`editPermission-${i}`} value={editPermission.value}>{editPermission.name}</Option>)
  103. })}
  104. </Select>
  105. )}
  106. </FormItem>
  107. <FormItem label='图例' {...formItemLayout}>
  108. <Switch checkedChildren="开" unCheckedChildren="关" defaultChecked={showLegend} />
  109. </FormItem>
  110. <FormItem label='提示框' {...formItemLayout}>
  111. {getFieldDecorator('tooltip')(
  112. <Switch checkedChildren="开" unCheckedChildren="关" defaultChecked={showTooltip} />
  113. )}
  114. </FormItem>
  115. <FormItem label='缩放' {...formItemLayout}>
  116. {getFieldDecorator('datazoom')(
  117. <Switch checkedChildren="开" unCheckedChildren="关" defaultChecked={datazoom} />
  118. )}
  119. </FormItem>
  120. <FormItem label='工具箱' {...formItemLayout}>
  121. {getFieldDecorator('toolbox')(
  122. <Switch checkedChildren="开" unCheckedChildren="关" defaultChecked={toolbox} />
  123. )}
  124. </FormItem>
  125. </Form>
  126. );
  127. }
  128. }
  129. export default Form.create()(baseConfigForm);