MyPopconfirm.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. return Reflect.get(obj, txtK) || ['', '']
  19. }, [txtK])
  20. return (
  21. <Popconfirm
  22. placement={loc}
  23. title={txt[0]}
  24. okText={txt[1]}
  25. cancelText='取消'
  26. onConfirm={onConfirm}
  27. okButtonProps={{ loading: false }}
  28. >
  29. {Dom ? (
  30. Dom
  31. ) : txtK === '删除' ? (
  32. <Button size='small' type='text' danger>
  33. {txtK}
  34. </Button>
  35. ) : (
  36. <Button>{txtK}</Button>
  37. )}
  38. </Popconfirm>
  39. )
  40. }
  41. const MemoMyPopconfirm = React.memo(MyPopconfirm)
  42. export default MemoMyPopconfirm