MyPopconfirm.tsx 1.2 KB

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