WorkbenchSettingForm.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2017 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * >>
  19. */
  20. import React, { PureComponent } from 'react'
  21. import { Form, Modal, Row, Col, Radio, Button } from 'antd'
  22. import { IWorkbenchSettings, WorkbenchQueryMode } from './types'
  23. import { FormComponentProps } from 'antd/lib/form'
  24. const FormItem = Form.Item
  25. const RadioGroup = Radio.Group
  26. interface IWorkbenchSettingFormProps {
  27. visible: boolean
  28. settings: IWorkbenchSettings
  29. onSave: (values: any) => void
  30. onClose: () => void
  31. }
  32. export class WorkbenchSettingForm extends PureComponent<IWorkbenchSettingFormProps & FormComponentProps, {}> {
  33. private commonFormItemStyle = {
  34. labelCol: { span: 9 },
  35. wrapperCol: { span: 13 }
  36. }
  37. public componentDidUpdate (prevProps: IWorkbenchSettingFormProps & FormComponentProps) {
  38. const { form, settings, visible } = this.props
  39. if (settings !== prevProps.settings || visible !== prevProps.visible) {
  40. form.setFieldsValue(settings)
  41. }
  42. }
  43. private save = () => {
  44. this.props.form.validateFieldsAndScroll((err, values) => {
  45. if (!err) {
  46. this.props.onSave(values)
  47. }
  48. })
  49. }
  50. private reset = () => {
  51. this.props.form.resetFields()
  52. }
  53. public render () {
  54. const {
  55. form,
  56. visible,
  57. onClose
  58. } = this.props
  59. const { getFieldDecorator } = form
  60. const modalButtons = ([(
  61. <Button
  62. key="submit"
  63. size="large"
  64. type="primary"
  65. onClick={this.save}
  66. >
  67. 保 存
  68. </Button>),
  69. (
  70. <Button
  71. key="back"
  72. size="large"
  73. onClick={onClose}
  74. >
  75. 取 消
  76. </Button>)
  77. ])
  78. return (
  79. <Modal
  80. title="可视化组件 编辑器设置"
  81. wrapClassName="ant-modal-small"
  82. visible={visible}
  83. footer={modalButtons}
  84. onCancel={onClose}
  85. afterClose={this.reset}
  86. >
  87. <Form>
  88. <Row gutter={8}>
  89. <Col span={24}>
  90. <FormItem label="查询触发模式" {...this.commonFormItemStyle}>
  91. {getFieldDecorator('queryMode', {})(
  92. <RadioGroup>
  93. <Radio value={WorkbenchQueryMode.Manually}>手动</Radio>
  94. <Radio value={WorkbenchQueryMode.Immediately}>立即</Radio>
  95. </RadioGroup>
  96. )}
  97. </FormItem>
  98. </Col>
  99. <Col span={24}>
  100. <FormItem label="多选拖拽" {...this.commonFormItemStyle}>
  101. {getFieldDecorator('multiDrag', {})(
  102. <RadioGroup>
  103. <Radio value={true}>是</Radio>
  104. <Radio value={false}>否</Radio>
  105. </RadioGroup>
  106. )}
  107. </FormItem>
  108. </Col>
  109. </Row>
  110. </Form>
  111. </Modal>
  112. )
  113. }
  114. }
  115. export default Form.create<IWorkbenchSettingFormProps & FormComponentProps>()(WorkbenchSettingForm)