AskAdd.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import React, { useEffect } from 'react'
  2. import { Button, Form, Input, Row, Modal } from 'antd'
  3. const { Item } = Form
  4. interface IAskAddProps {
  5. visible: boolean
  6. ID: number
  7. title?: string
  8. placeholder?: string
  9. onCloseModel: (e?: React.MouseEvent<HTMLElement, MouseEvent>) => void
  10. onApply: (ID: number, content: string) => void
  11. }
  12. /**
  13. * 提问/留言
  14. */
  15. const AskAdd: React.FC<IAskAddProps> = props => {
  16. const { visible, ID, title = '留言', placeholder = '可以留下您对报告内容的看法或者疑问', onCloseModel } = props
  17. const [form] = Form.useForm()
  18. useEffect(() => {
  19. return () => {
  20. form.resetFields()
  21. }
  22. // eslint-disable-next-line react-hooks/exhaustive-deps
  23. }, [form])
  24. const handleFinish = (value: { Content: string }) => {
  25. props.onApply(ID, value.Content)
  26. }
  27. return (
  28. <div onClick={e => e.stopPropagation()}>
  29. <Modal
  30. open={visible}
  31. onCancel={onCloseModel}
  32. destroyOnClose={true}
  33. maskClosable={false}
  34. title={title}
  35. footer={null}
  36. >
  37. <Form form={form} onFinish={handleFinish} labelAlign="left">
  38. <Item
  39. label=""
  40. name="Content"
  41. wrapperCol={{ span: 24 }}
  42. rules={[
  43. { required: true, message: '请输入内容!' },
  44. {
  45. pattern: /^[^\s]*$/,
  46. message: '禁止输入空格'
  47. }
  48. ]}
  49. >
  50. <Input.TextArea
  51. placeholder={placeholder}
  52. maxLength={100}
  53. showCount={true}
  54. autoSize={{ minRows: 5, maxRows: 5 }}
  55. />
  56. </Item>
  57. <Row align="middle" justify="center">
  58. <Item>
  59. <Button onClick={onCloseModel} className="m-r-xs">
  60. 取消
  61. </Button>
  62. <Button type="primary" htmlType="submit">
  63. 提交
  64. </Button>
  65. </Item>
  66. </Row>
  67. </Form>
  68. </Modal>
  69. </div>
  70. )
  71. }
  72. export default AskAdd