index.jsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import {useEffect, useRef, useState} from "react";
  2. import {useThemeProvider} from "@contexts/themeContext";
  3. import MuiDrawer from "@mui/material/Drawer";
  4. import styles from "./styles.module.scss";
  5. import {
  6. isInAppBrowser,
  7. openProgressierInstall,
  8. openUrlUseChrome
  9. } from "@utils/UAUtils";
  10. import Fade from "@mui/material/Fade";
  11. import Grow from "@mui/material/Grow";
  12. import Modal from "@mui/material/Modal";
  13. const i18n=global.i18n;
  14. const WInstallBox = () => {
  15. const {isMobile} = useThemeProvider();
  16. const [isShow, setIsShow] = useState(false);
  17. const installRef = useRef(null);
  18. const [iconUrl, setIconUrl] = useState("");
  19. const show=()=>{
  20. setIsShow(true);
  21. }
  22. const hide=()=>{
  23. setIsShow(false);
  24. }
  25. const onInstall=()=>{
  26. if (isInAppBrowser()){
  27. openUrlUseChrome();
  28. }
  29. else
  30. {
  31. openProgressierInstall();
  32. setIsShow(false);
  33. }
  34. }
  35. const onCancel=()=>{
  36. setIsShow(false);
  37. }
  38. useEffect(()=>{
  39. const installBox={
  40. show,
  41. hide
  42. };
  43. global.installBox=installBox;
  44. if (window.progressier!=null){
  45. if (window.progressier.data!=null){
  46. let params=window.progressier.data.params;
  47. if (params!=null){
  48. setIconUrl(params.icon180);
  49. }
  50. }
  51. }
  52. },[])
  53. const renderInstall=()=>{
  54. return (
  55. <div className={styles.continer}>
  56. <div className={styles.install_con}>
  57. <img src={iconUrl}/>
  58. <span>{i18n.t("installBox.tips")}</span>
  59. </div>
  60. <div className={styles.install_btn_con}>
  61. <button className={styles.install_btn} onClick={onCancel}>
  62. {i18n.t("installBox.btn_cancel")}
  63. </button>
  64. <button className={`${styles.install_btn} ${styles.btn_green}`} onClick={onInstall}>
  65. {i18n.t("installBox.btn_install")}
  66. </button>
  67. </div>
  68. </div>
  69. )
  70. }
  71. const renderMobile = () => {
  72. return (
  73. <MuiDrawer open={isShow}
  74. anchor={"bottom"}
  75. sx={{
  76. pointerEvents: 'auto',
  77. zIndex: 'var(--zindex-install)',
  78. "& .MuiDrawer-paper": {
  79. boxSizing: "border-box",
  80. overflow: 'visible !important',
  81. backgroundColor: '#fff;',
  82. boxShadow: 'var(--widget-shadow);',
  83. borderTopLeftRadius: '0.71rem',
  84. borderTopRightRadius: '0.71rem',
  85. padding: '1.42rem'
  86. },
  87. }}
  88. variant="temporary"
  89. onClose={()=>{
  90. // setIsShow(false)
  91. }}>
  92. {renderInstall()}
  93. </MuiDrawer>
  94. )
  95. }
  96. const renderDesktop = () => {
  97. return (
  98. <Modal open={isShow} onClose={()=>{
  99. }} closeAfterTransition>
  100. <Fade in={isShow} timeout={500}>
  101. <div className="popup-container">
  102. <Grow in={isShow} timeout={500}>
  103. <div className={styles.pop_con} style={{minHeight: 'unset'}}>
  104. {renderInstall()}
  105. </div>
  106. </Grow>
  107. </div>
  108. </Fade>
  109. </Modal>
  110. )
  111. }
  112. return (
  113. <>
  114. {isMobile()?renderMobile():renderDesktop()}
  115. </>
  116. )
  117. }
  118. export default WInstallBox;