Layout.jsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import ScrollToTop from "@components/ScrollToTop";
  2. import Sidebar from "@layout/Sidebar";
  3. import Navbar from "@layout/Navbar";
  4. import BottomNav from "@layout/BottomNav";
  5. import AppContainer from "@layout/AppContainer";
  6. import React, {cloneElement, createRef, lazy, Suspense, useEffect, useRef, useState} from "react";
  7. import LoadingScreen from "@components/LoadingScreen";
  8. import {Route, Routes, useLocation, useNavigate} from "react-router-dom";
  9. import {useDispatch, useSelector} from "react-redux";
  10. import {isFullRoute, isLogined, routesIn, routesPop, updateGameRoute} from "@features/mainSlice";
  11. import {preventDefault} from "@utils/helpers";
  12. import {useThemeProvider} from "@contexts/themeContext";
  13. import CRoute from "@layout/Routes";
  14. import {CBrowserRouter,CHashRouter} from "@layout/Routes";
  15. import Footer from "@layout/Footer";
  16. import GameSearchPanel from "@layout/GameSearchPanel";
  17. import TransitionGroup from "react-transition-group/TransitionGroup";
  18. import SubScreen from "@components/SubScreen";
  19. import CSSTransition from "react-transition-group/CSSTransition";
  20. import Transition from "react-transition-group/Transition";
  21. import WLangSelect from "@widgets/WLangSelect";
  22. import MsgBox from "@components/MsgBox";
  23. import WDPassPrompt from "@widgets/WWithdraw/PassPrompt/WDPassPrompt";
  24. import useAuthLockRoute from "@hooks/useAuthLockRoute";
  25. import WHallWheel from "@widgets/WCashWheel/WHallWheel/WHallWheel";
  26. import LoadingIn from "@components/Loading/LoadingIn";
  27. import WDPassBox from "@widgets/WWithdraw/PassBox/WDPassBox";
  28. import {ROUTE_PATH, ROUTE_TYPE_FULL, ROUTE_TYPE_IN} from "@constants/routes";
  29. import DropCoins from "@components/DropCoins";
  30. import {toast} from "react-toastify";
  31. import useEdgeGesture from "@hooks/useEdgeGesture";
  32. import MailNew from "@components/MailNew";
  33. import WInstallBox from "@widgets/WInstallBox";
  34. import WBindPhone from "@widgets/WBindPhone";
  35. const PageNotFound = lazy(() => import('@pages/PageNotFound'));
  36. const Layout=({...props})=>{
  37. const appRef = useRef(null);
  38. const msgBoxRef=useRef(null);
  39. const {isMobile,isShowWheel, setIsShowWheel,isShowWDPassBox,setIsShowWDPassBox,isOpenSub} = useThemeProvider();
  40. const {pathname, search, hash} = useLocation();
  41. const isFull = useSelector(isFullRoute(pathname));
  42. const inRoutes=useSelector(routesIn);
  43. const popRoutes=useSelector(routesPop);
  44. const isLogin=useSelector(isLogined);
  45. const navigate=useNavigate();
  46. const {getSidedGesture}=useEdgeGesture();
  47. const isGesture=getSidedGesture();
  48. const mobile=isMobile();
  49. const dispatch = useDispatch();
  50. // const {setLockPath}=useAuthLockRoute();
  51. useEffect(() => {
  52. // scroll to top on route change
  53. appRef.current && appRef.current.scrollTo(0, 0);
  54. preventDefault();
  55. }, []);
  56. useEffect(()=>{
  57. global.msgBox=msgBoxRef.current;
  58. },[msgBoxRef])
  59. useEffect(()=>{
  60. let routeType=ROUTE_TYPE_FULL;
  61. if (!mobile)routeType=ROUTE_TYPE_IN;
  62. dispatch(updateGameRoute(routeType));
  63. },[mobile])
  64. const renderIn=()=>{
  65. let isShowSub=false;
  66. if (isMobile()&&isOpenSub)isShowSub=true;
  67. if (hash==null||hash==="")isShowSub=false;
  68. return (
  69. <>
  70. <div className={`app ${isShowSub ? 'app_openSub' : ''} ${isGesture?'app_gestureSub':''}`} ref={appRef}>
  71. <ScrollToTop/>
  72. <AppContainer>
  73. <div className="app_container-content d-flex flex-column flex-1">
  74. <Suspense fallback={<LoadingIn/>}>
  75. <CBrowserRouter isLogin={isLogin} routes={inRoutes}/>
  76. </Suspense>
  77. </div>
  78. <Footer/>
  79. </AppContainer>
  80. <GameSearchPanel/>
  81. </div>
  82. <div className={`app-top ${isShowSub ? 'app_openSub' : ''} ${isGesture?'app_gestureSub':''}`}>
  83. <Sidebar/>
  84. <Navbar/>
  85. {isMobile() && <BottomNav/>}
  86. </div>
  87. </>
  88. )
  89. }
  90. const renderInFull = () => {
  91. return (
  92. <div className={`app fluid`} ref={appRef}>
  93. <ScrollToTop/>
  94. <div className="app_container_full">
  95. <Suspense fallback={<LoadingScreen/>}>
  96. <CBrowserRouter isLogin={isLogin} routes={inRoutes}/>
  97. </Suspense>
  98. </div>
  99. </div>
  100. )
  101. }
  102. const renderHash = () => {
  103. return (
  104. <CHashRouter isLogin={isLogin} routes={popRoutes} hlocation={{
  105. pathname: pathname,
  106. search: search,
  107. hash: hash
  108. }} basePath={pathname}/>
  109. )
  110. }
  111. const renderPop=()=>{
  112. return (
  113. <>
  114. <WLangSelect/>
  115. <MsgBox ref={msgBoxRef}/>
  116. <WDPassPrompt/>
  117. <WDPassBox open={isShowWDPassBox} onClose={()=>{
  118. setIsShowWDPassBox(false);
  119. }}/>
  120. <WHallWheel open={isShowWheel} onClose={()=>{
  121. setIsShowWheel(false);
  122. if (props&&props.onCloseHallWheel)props.onCloseHallWheel()
  123. }}></WHallWheel>
  124. {/*<WInstallBox/>*/}
  125. <WBindPhone/>
  126. </>
  127. )
  128. }
  129. const renderEffect=()=>{
  130. return (
  131. <>
  132. <DropCoins/>
  133. <MailNew/>
  134. </>
  135. )
  136. }
  137. return (
  138. <>
  139. {
  140. !isFull?renderIn():renderInFull()
  141. }
  142. {
  143. // hash!=''?renderHash():(<></>)
  144. renderHash()
  145. }
  146. {
  147. renderPop()
  148. }
  149. {
  150. renderEffect()
  151. }
  152. </>
  153. );
  154. }
  155. export default Layout;