BaseForm.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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, { memo, useCallback } from 'react'
  21. import moment from 'moment'
  22. import UrlClipboard from './UrlClipboard'
  23. import { Form, Row, Col, DatePicker, Button } from 'antd'
  24. import { WrappedFormUtils } from 'antd/lib/form/Form'
  25. import { TCopyType } from '../types'
  26. import { DEFAULT_DATETIME_FORMAT } from 'app/globalConstants'
  27. import styles from '../SharePanel.less'
  28. const FormItem = Form.Item
  29. interface IBaseFormProps {
  30. form: WrappedFormUtils
  31. shareUrl: string
  32. password?: string
  33. loading: boolean
  34. onCopy: (copytype: TCopyType) => () => void
  35. onGetToken: () => void
  36. }
  37. const BaseForm: React.FC<IBaseFormProps> = ({
  38. form,
  39. shareUrl,
  40. password,
  41. loading,
  42. onCopy,
  43. onGetToken
  44. }) => {
  45. const { getFieldDecorator } = form
  46. const itemStyle = { labelCol: { span: 6 }, wrapperCol: { span: 17 } }
  47. const disabledDate = useCallback(
  48. (current) => current && current < moment().subtract(1, 'day').endOf('day'),
  49. []
  50. )
  51. return (
  52. <>
  53. <Row gutter={8}>
  54. <Col span={24}>
  55. <FormItem label="有效期" {...itemStyle}>
  56. {getFieldDecorator('expired', {
  57. rules: [{ required: true, message: '有效期不能为空' }]
  58. })(
  59. <DatePicker
  60. showTime
  61. format={DEFAULT_DATETIME_FORMAT}
  62. disabledDate={disabledDate}
  63. />
  64. )}
  65. </FormItem>
  66. </Col>
  67. </Row>
  68. <Row gutter={8} type="flex" justify="center">
  69. <Col>
  70. <Button
  71. className={styles.generate}
  72. disabled={loading}
  73. loading={loading}
  74. type="link"
  75. onClick={onGetToken}
  76. >
  77. 点击生成链接
  78. </Button>
  79. </Col>
  80. </Row>
  81. <UrlClipboard shareUrl={shareUrl} password={password} onCopy={onCopy} />
  82. </>
  83. )
  84. }
  85. export default memo(BaseForm)