ScheduleWeChatWorkConfig.tsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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, {
  21. useImperativeHandle,
  22. forwardRef
  23. } from 'react'
  24. import { Form, Row, Col, Input, Select, Icon, InputNumber, Spin } from 'antd'
  25. const FormItem = Form.Item
  26. const { Option } = Select
  27. // validate http/https
  28. // const URL_REG = /(https?):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/
  29. import { FormComponentProps } from 'antd/lib/form'
  30. import { IScheduleWeChatWorkConfig } from './types'
  31. import {
  32. FormItemStyle,
  33. LongFormItemStyle
  34. } from './constants'
  35. interface IScheduleWeChatWorkConfigProps
  36. extends FormComponentProps<IScheduleWeChatWorkConfig> {
  37. config: IScheduleWeChatWorkConfig
  38. }
  39. export const ScheduleWeChatWorkConfig: React.FC<IScheduleWeChatWorkConfigProps> = (
  40. props,
  41. ref
  42. ) => {
  43. const { form, config } = props
  44. const { getFieldDecorator } = form
  45. useImperativeHandle(ref, () => ({ form }))
  46. return (
  47. <Form>
  48. <FormItem label="机器人webhook地址" {...LongFormItemStyle}>
  49. {getFieldDecorator<IScheduleWeChatWorkConfig>('webHookUrl', {
  50. rules: [{ required: true, message: 'webhook地址不能为空' }],
  51. initialValue: config.webHookUrl
  52. })(<Input />)}
  53. </FormItem>
  54. <Row>
  55. <Col span={12}>
  56. <FormItem label="文件类型" {...FormItemStyle}>
  57. {getFieldDecorator<IScheduleWeChatWorkConfig>('type', {
  58. rules: [{ required: true }],
  59. initialValue: config.type
  60. })(
  61. <Select>
  62. <Option value="image">图片</Option>
  63. </Select>
  64. )}
  65. </FormItem>
  66. </Col>
  67. <Col span={12}>
  68. {form.getFieldValue('type') !== 'excel' && (
  69. <FormItem label="图片宽度" {...FormItemStyle}>
  70. {getFieldDecorator<IScheduleWeChatWorkConfig>('imageWidth', {
  71. rules: [{ required: true }],
  72. initialValue: config.imageWidth || 1920
  73. })(<InputNumber min={100} />)}{' '}
  74. 像素
  75. </FormItem>
  76. )}
  77. </Col>
  78. </Row>
  79. </Form>
  80. )
  81. }
  82. export default Form.create<IScheduleWeChatWorkConfigProps>()(
  83. forwardRef(ScheduleWeChatWorkConfig)
  84. )