Layout.jsx 6.3 KB

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