PollingConfig.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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, { useState } from 'react'
  21. import { Form, Row, Col, Select, InputNumber } from 'antd'
  22. const FormItem = Form.Item
  23. const { Option } = Select
  24. import { FormItemProps, FormComponentProps } from 'antd/lib/form'
  25. export type PollingSetting = {
  26. polling: 'true' | 'false'
  27. frequency?: number
  28. }
  29. const FormItemStyle: Partial<FormItemProps> = {
  30. labelCol: { xl: 8, lg: 10, md: 14, sm: 8 },
  31. wrapperCol: { xl: 14, lg: 12, md: 10, sm: 14 }
  32. }
  33. type PollingConfigProps = Partial<PollingSetting> &
  34. FormComponentProps<PollingSetting>
  35. const PollingConfig: React.FC<PollingConfigProps> = (props) => {
  36. const { form, polling, frequency } = props
  37. const { getFieldDecorator } = form
  38. const currentPolling = form.getFieldValue('polling')
  39. return (
  40. <Form>
  41. <Row>
  42. <Col span={12}>
  43. <FormItem label="数据刷新模式" {...FormItemStyle}>
  44. {getFieldDecorator<PollingSetting>('polling', {
  45. initialValue: polling || 'false'
  46. })(
  47. <Select>
  48. <Option value="false">手动刷新</Option>
  49. <Option value="true">定时刷新</Option>
  50. </Select>
  51. )}
  52. </FormItem>
  53. </Col>
  54. {currentPolling === 'true' && (
  55. <Col span={12}>
  56. <FormItem label="时长(秒)" {...FormItemStyle}>
  57. {getFieldDecorator<PollingSetting>('frequency', {
  58. rules: [
  59. {
  60. required: true,
  61. message: '时长不能为空'
  62. }
  63. ],
  64. initialValue: frequency
  65. })(<InputNumber />)}
  66. </FormItem>
  67. </Col>
  68. )}
  69. </Row>
  70. </Form>
  71. )
  72. }
  73. export default Form.create<PollingConfigProps>()(PollingConfig)