Layout.jsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. import WBindPrompt from "@widgets/WBindPrompt";
  36. const PageNotFound = lazy(() => import('@pages/PageNotFound'));
  37. const Layout=({...props})=>{
  38. const appRef = useRef(null);
  39. const msgBoxRef=useRef(null);
  40. const {isMobile,isShowWheel, setIsShowWheel,isShowWDPassBox,setIsShowWDPassBox,isOpenSub} = useThemeProvider();
  41. const {pathname, search, hash} = useLocation();
  42. const isFull = useSelector(isFullRoute(pathname));
  43. const inRoutes=useSelector(routesIn);
  44. const popRoutes=useSelector(routesPop);
  45. const isLogin=useSelector(isLogined);
  46. const navigate=useNavigate();
  47. const {getSidedGesture}=useEdgeGesture();
  48. const isGesture=getSidedGesture();
  49. const mobile=isMobile();
  50. const dispatch = useDispatch();
  51. // const {setLockPath}=useAuthLockRoute();
  52. useEffect(() => {
  53. // scroll to top on route change
  54. appRef.current && appRef.current.scrollTo(0, 0);
  55. preventDefault();
  56. }, []);
  57. useEffect(()=>{
  58. global.msgBox=msgBoxRef.current;
  59. },[msgBoxRef])
  60. useEffect(()=>{
  61. let routeType=ROUTE_TYPE_FULL;
  62. if (!mobile)routeType=ROUTE_TYPE_IN;
  63. dispatch(updateGameRoute(routeType));
  64. },[mobile])
  65. const renderIn=()=>{
  66. let isShowSub=false;
  67. if (isMobile()&&isOpenSub)isShowSub=true;
  68. if (hash==null||hash==="")isShowSub=false;
  69. return (
  70. <>
  71. <div className={`app ${isShowSub ? 'app_openSub' : ''} ${isGesture?'app_gestureSub':''}`} ref={appRef}>
  72. <ScrollToTop/>
  73. <AppContainer>
  74. <div className="app_container-content d-flex flex-column flex-1">
  75. <Suspense fallback={<LoadingIn/>}>
  76. <CBrowserRouter isLogin={isLogin} routes={inRoutes}/>
  77. </Suspense>
  78. </div>
  79. <Footer/>
  80. </AppContainer>
  81. <GameSearchPanel/>
  82. </div>
  83. <div className={`app-top ${isShowSub ? 'app_openSub' : ''} ${isGesture?'app_gestureSub':''}`}>
  84. <Sidebar/>
  85. <Navbar/>
  86. {isMobile() && <BottomNav/>}
  87. </div>
  88. </>
  89. )
  90. }
  91. const renderInFull = () => {
  92. return (
  93. <div className={`app fluid`} ref={appRef}>
  94. <ScrollToTop/>
  95. <div className="app_container_full">
  96. <Suspense fallback={<LoadingScreen/>}>
  97. <CBrowserRouter isLogin={isLogin} routes={inRoutes}/>
  98. </Suspense>
  99. </div>
  100. </div>
  101. )
  102. }
  103. const renderHash = () => {
  104. return (
  105. <CHashRouter isLogin={isLogin} routes={popRoutes} hlocation={{
  106. pathname: pathname,
  107. search: search,
  108. hash: hash
  109. }} basePath={pathname}/>
  110. )
  111. }
  112. const renderPop=()=>{
  113. return (
  114. <>
  115. <WLangSelect/>
  116. <MsgBox ref={msgBoxRef}/>
  117. <WDPassPrompt/>
  118. <WDPassBox open={isShowWDPassBox} onClose={()=>{
  119. setIsShowWDPassBox(false);
  120. }}/>
  121. <WHallWheel open={isShowWheel} onClose={()=>{
  122. setIsShowWheel(false);
  123. if (props&&props.onCloseHallWheel)props.onCloseHallWheel()
  124. }}></WHallWheel>
  125. {/*<WInstallBox/>*/}
  126. <WBindPhone/>
  127. <WBindPrompt/>
  128. </>
  129. )
  130. }
  131. const renderEffect=()=>{
  132. return (
  133. <>
  134. <DropCoins/>
  135. <MailNew/>
  136. </>
  137. )
  138. }
  139. return (
  140. <>
  141. {
  142. !isFull?renderIn():renderInFull()
  143. }
  144. {
  145. // hash!=''?renderHash():(<></>)
  146. renderHash()
  147. }
  148. {
  149. renderPop()
  150. }
  151. {
  152. renderEffect()
  153. }
  154. </>
  155. );
  156. }
  157. export default Layout;