index.jsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import React, {useEffect, useState} from "react";
  2. import Popup from "@components/Popup";
  3. import styles from "./styles.module.scss";
  4. import SvgIcon from "@components/SvgIcon";
  5. import {CopyToClipboard} from "react-copy-to-clipboard";
  6. import {toast} from "react-toastify";
  7. import {stringFormat} from "@utils/helpers";
  8. import html2canvas from "html2canvas";
  9. import Fade from "@mui/material/Fade";
  10. import Grow from "@mui/material/Grow";
  11. import Modal from "@mui/material/Modal";
  12. import {ReactComponent as CloseIcon} from "@assets/singlesvg/btnclose.svg";
  13. const i18n=global.i18n;
  14. const WSaveAccount = () => {
  15. const [isShow, setIsShow] = useState(false);
  16. const [account, setAccount] = useState("");
  17. const [password, setPassword] = useState("");
  18. const show=(info)=>{
  19. if (info.account!=null)setAccount(info.account);
  20. if (info.password!=null)setPassword(info.password);
  21. setIsShow(true);
  22. }
  23. const hide=()=>{
  24. setIsShow(false);
  25. }
  26. const handleScreenshot = () => {
  27. const style = document.createElement('style');
  28. document.head.appendChild(style);
  29. style.sheet?.insertRule('body > div:last-child img { display: inline-block; }');
  30. // 获取需要截图的元素
  31. const element = document.getElementById('saveAccount');
  32. // 使用 html2canvas 捕获元素并生成图片
  33. html2canvas(element,{
  34. }).then(canvas => {
  35. // 创建一个链接元素
  36. const link = document.createElement('a');
  37. link.href = canvas.toDataURL('image/png'); // 获取图片数据 URL
  38. link.download = 'accountInfo.png'; // 设置下载的文件名
  39. link.click(); // 触发下载
  40. toast.success(i18n.t("saveAccount.save_success"));
  41. });
  42. };
  43. useEffect(()=>{
  44. const saveAccount={
  45. show,
  46. hide
  47. };
  48. global.saveAccount=saveAccount;
  49. return ()=>{
  50. }
  51. },[])
  52. return (
  53. <Modal open={isShow} onClose={hide} closeAfterTransition>
  54. <Fade in={isShow} timeout={500}>
  55. <div className="popup-container">
  56. <Grow in={isShow} timeout={500}>
  57. <div id={"saveAccount"} className={`popup card card-padded`} style={{minHeight: 'unset'}}>
  58. <button className="popup_close" onClick={hide} aria-label="Close popup">
  59. {/*<i className="icon-xmark"/>*/}
  60. <CloseIcon/>
  61. </button>
  62. <div className={styles.container}>
  63. <span className={styles.title}>
  64. {i18n.t("saveAccount.title")}
  65. </span>
  66. <div className={styles.item_con}>
  67. <span className={styles.sub_title}>{i18n.t("saveAccount.account")}</span>
  68. <div className={"input-control"}>
  69. <div className={styles.item}>
  70. <span>{account}</span>
  71. <CopyToClipboard text={account} onCopy={() => {
  72. toast.success(i18n.t("copy_success"));
  73. }}>
  74. <button>
  75. <SvgIcon className={styles.icon} herf={"icon_Copy"}></SvgIcon>
  76. </button>
  77. </CopyToClipboard>
  78. </div>
  79. </div>
  80. </div>
  81. <div className={styles.item_con}>
  82. <span className={styles.sub_title}>{i18n.t("saveAccount.password")}</span>
  83. <div className={"input-control"}>
  84. <div className={styles.item}>
  85. <span>{password}</span>
  86. <CopyToClipboard text={password} onCopy={() => {
  87. toast.success(i18n.t("copy_success"));
  88. }}>
  89. <button>
  90. <SvgIcon className={styles.icon} herf={"icon_Copy"}></SvgIcon>
  91. </button>
  92. </CopyToClipboard>
  93. </div>
  94. </div>
  95. </div>
  96. <button className={"button-green"} onClick={() => {
  97. handleScreenshot();
  98. }}>{i18n.t("saveAccount.title")}</button>
  99. <span className={styles.tips}>{i18n.t("saveAccount.tips")}</span>
  100. </div>
  101. </div>
  102. </Grow>
  103. </div>
  104. </Fade>
  105. </Modal>
  106. )
  107. }
  108. export default WSaveAccount;