MyPopconfirm.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import React, { useMemo } from 'react'
  2. import { Button, Popconfirm } from 'antd'
  3. import { defaultPassWord } from '@/utils/http'
  4. type Props = {
  5. txtK: '删除' | '删除2' | '取消' | '返回' | '重置密码' | '退出登录' | '重新提交' | '撤回'
  6. onConfirm: () => void
  7. Dom?: React.ReactNode
  8. loc?: 'bottom'
  9. disabled?: boolean
  10. }
  11. function MyPopconfirm({ txtK, onConfirm, Dom, loc, disabled }: Props) {
  12. const txt = useMemo(() => {
  13. const obj = {
  14. 删除: ['删除后无法恢复,是否删除?', '删除'],
  15. 删除2: ['确定删除吗?', '确定'],
  16. 取消: ['放弃编辑后,信息将不会保存!', '放弃'],
  17. 返回: ['放弃编辑后,信息将不会保存!', '放弃'],
  18. 重置密码: [`密码重制后为${defaultPassWord},是否重置?`, '重置'],
  19. 退出登录: ['确定退出吗?', '确定'],
  20. 重新提交: ['确定重新提交吗?', '确定'],
  21. 撤回: ['确定撤回吗?', '确定']
  22. }
  23. return Reflect.get(obj, txtK) || ['', '']
  24. }, [txtK])
  25. return (
  26. <Popconfirm
  27. placement={loc}
  28. title={txt[0]}
  29. okText={txt[1]}
  30. cancelText='取消'
  31. onConfirm={onConfirm}
  32. okButtonProps={{ loading: false }}
  33. >
  34. {Dom ? (
  35. Dom
  36. ) : txtK === '删除' ? (
  37. <Button disabled={disabled} size='small' type='text' danger={!disabled}>
  38. {txtK}
  39. </Button>
  40. ) : (
  41. <Button>{txtK}</Button>
  42. )}
  43. </Popconfirm>
  44. )
  45. }
  46. const MemoMyPopconfirm = React.memo(MyPopconfirm)
  47. export default MemoMyPopconfirm