A2EMail.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import React, { useCallback, useEffect, useRef } from 'react'
  2. import styles from './index.module.scss'
  3. import { Button, Form, FormInstance, Modal } from 'antd'
  4. import MyPopconfirm from '@/components/MyPopconfirm'
  5. import TextArea from 'antd/es/input/TextArea'
  6. import { A2_APIgetConfig, A2_APIsetConfig } from '@/store/action/A2orderSet'
  7. import { MessageFu } from '@/utils/message'
  8. type Props = {
  9. closeFu: () => void
  10. }
  11. function A2EMail({ closeFu }: Props) {
  12. // 表单的ref
  13. const FormBoxRef = useRef<FormInstance>(null)
  14. // 获取设置
  15. const getEMfu = useCallback(async () => {
  16. const res = await A2_APIgetConfig(12)
  17. if (res.code === 0) {
  18. FormBoxRef.current?.setFieldsValue({ rtf: res.data.rtf })
  19. }
  20. }, [])
  21. useEffect(() => {
  22. getEMfu()
  23. }, [getEMfu])
  24. // 没有通过校验
  25. const onFinishFailed = useCallback(() => {}, [])
  26. // 通过校验点击确定
  27. const onFinish = useCallback(
  28. async (values: { rtf: string }) => {
  29. const res = await A2_APIsetConfig({ id: 12, rtf: values.rtf || '' })
  30. if (res.code === 0) {
  31. MessageFu.success('设置邮箱地址成功!')
  32. closeFu()
  33. }
  34. },
  35. [closeFu]
  36. )
  37. return (
  38. <Modal
  39. wrapClassName={styles.A2EMail}
  40. open={true}
  41. title=''
  42. footer={
  43. [] // 设置footer为空,去掉 取消 确定默认按钮
  44. }
  45. >
  46. <Form
  47. ref={FormBoxRef}
  48. name='basic'
  49. onFinish={onFinish}
  50. onFinishFailed={onFinishFailed}
  51. autoComplete='off'
  52. scrollToFirstError
  53. >
  54. <Form.Item
  55. label='邮箱地址'
  56. name='rtf'
  57. rules={[
  58. {
  59. pattern: /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/,
  60. message: '请输入正确格式的邮箱!'
  61. }
  62. ]}
  63. getValueFromEvent={e => e.target.value.replace(/\s+/g, '')}
  64. >
  65. <TextArea maxLength={50} showCount placeholder='请输入内容' />
  66. </Form.Item>
  67. {/* 确定和取消按钮 */}
  68. <Form.Item className='A2Ebtn'>
  69. <MyPopconfirm txtK='取消' onConfirm={closeFu} /> &emsp;
  70. <Button type='primary' htmlType='submit'>
  71. 提交
  72. </Button>
  73. </Form.Item>
  74. </Form>
  75. </Modal>
  76. )
  77. }
  78. const MemoA2EMail = React.memo(A2EMail)
  79. export default MemoA2EMail