MyPopconfirm.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import React, { useMemo } from 'react'
  2. import { Button, Popconfirm } from 'antd'
  3. type Props = {
  4. txtK: '删除' | '取消' | '重置密码' | '退出登录' | '清空' | '取消认证'
  5. onConfirm: () => void
  6. Dom?: React.ReactNode
  7. loc?: 'bottom'
  8. }
  9. function MyPopconfirm({ txtK, onConfirm, Dom, loc }: Props) {
  10. const txt = useMemo(() => {
  11. const obj = {
  12. 删除: ['删除后无法恢复,是否删除?', '删除'],
  13. 取消: ['放弃编辑后,信息将不会保存!', '放弃'],
  14. 重置密码: ['密码重制后为123456,是否重置?', '重置'],
  15. 退出登录: ['确定退出吗?', '确定'],
  16. 清空: ['确定清空吗?', '确定'],
  17. 取消认证: ['是否移除该用户的团队认证资格及信息?', '移除']
  18. }
  19. return Reflect.get(obj, txtK) || ['', '']
  20. }, [txtK])
  21. return (
  22. <Popconfirm
  23. placement={loc}
  24. title={txt[0]}
  25. okText={txt[1]}
  26. cancelText='取消'
  27. onConfirm={onConfirm}
  28. okButtonProps={{ loading: false }}
  29. >
  30. {Dom ? (
  31. Dom
  32. ) : txtK === '删除' ? (
  33. <Button size='small' type='text' danger>
  34. {txtK}
  35. </Button>
  36. ) : (
  37. <Button>{txtK}</Button>
  38. )}
  39. </Popconfirm>
  40. )
  41. }
  42. const MemoMyPopconfirm = React.memo(MyPopconfirm)
  43. export default MemoMyPopconfirm