Layout.jsx 6.4 KB

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