| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479 |
- // GA
- import ReactGA from 'react-ga4';
- // utils
- import React, {lazy, Suspense, useState} from 'react';
- // styles
- import ThemeStyles from '@styles/theme';
- import './style.scss';
- // libs styles
- import 'react-toastify/dist/ReactToastify.min.css';
- import 'react-grid-layout/css/styles.css';
- import 'swiper/css';
- import 'swiper/css/effect-fade';
- import 'swiper/css/pagination';
- // fonts
- import '@fonts/icomoon/icomoon.woff';
- // import '@fonts/swisscbt/SWISSC-BT.ttf'
- // contexts
- import {SidebarProvider, useSidebar} from '@contexts/sidebarContext';
- import {ThemeProvider} from 'styled-components';
- // hooks
- import {useThemeProvider} from '@contexts/themeContext';
- import {useEffect, useRef} from 'react';
- import {useWindowSize} from 'react-use';
- import useAuthRoute from '@hooks/useAuthRoute';
- // utils
- import {StyleSheetManager} from 'styled-components';
- import {ThemeProvider as MuiThemeProvider, createTheme} from '@mui/material/styles';
- import {getBrazilTimeStamp, getUrlParam, localStorageGet, localStorageSet, preventDefault} from '@utils/helpers';
- import rtlPlugin from 'stylis-plugin-rtl';
- import {CacheProvider} from '@emotion/react';
- import createCache from '@emotion/cache';
- // components
- import {BrowserRouter, HashRouter, Route, Routes, useLocation, useNavigate} from 'react-router-dom';
- import {ToastContainer} from 'react-toastify';
- import Layout from "@layout/Layout";
- import {
- getBFP,
- getFetchStatus,
- getHallServerUrl, getKickState, getOpenPay, getPromoteInstall, getPopWheel,
- getUserID,
- getUserInfo,
- isLogined,
- updateCurrGame, updateOpenPay, getIsGuest, getPopBindPhone, getPopFirst
- } from '@features/mainSlice';
- import {useDispatch, useSelector} from "react-redux";
- import {REQ_STATUS} from "@api/config";
- import {
- reqAgentCheck, reqCheckinCheck,
- reqCustomService, reqFavoGet, reqFirstPayConfig, reqGameActivity, reqGameInfo,
- reqGetRoutes,
- reqMailCheck, reqProtectCheck,
- reqRedpackCheck, reqRedpackConfig,
- reqTurnplateIndex,
- reqWithdrawBaseInfo
- } from "@features/api";
- import LoadingScreen from "@components/LoadingScreen";
- import DropCoins from "@components/DropCoins";
- import {getFirstPayMulti, reqPayConfig} from "@features/paySlice";
- import {connectHall, disconnectHall, hallSendState} from "@features/actions/hallClient";
- import {toast} from "react-toastify";
- import {useBlocker} from "react-router";
- import FontFaceObserver from 'fontfaceobserver';
- import {getTurnplate} from "@features/turnplateSlice";
- import {LOCAL_ACTIVITY_C, LOCAL_VISTOR_ID, LOCAL_WHEEL_INVITE_CODE} from "@constants/localkey";
- import LoadingFull from "@components/Loading/LoadingFull";
- import {ClickAwayListener} from "@mui/base/ClickAwayListener";
- import useGlobalClick from "@hooks/useGlobalClick";
- import SoundHelp from "@utils/SoundManger";
- import {ROUTE_PATH} from "@constants/routes";
- import {onChangeUser, onChangeUserID} from "@features/actions/mainAction";
- import {isInAppBrowser, isShowInstallBox, openUrlUseChrome} from "@utils/UAUtils";
- import WInstallBox from "@widgets/WInstallBox";
- import WMaintainBox from "@widgets/WMaintainBox";
- import WAreaSelect from "@widgets/WAreaSelect";
- const objInfo={
- gameID:0
- }
- const App = () => {
- const dispatch = useDispatch();
- const fetchStatus=useSelector(getFetchStatus);
- const userInfo=useSelector(getUserInfo);
- const userID=useSelector(getUserID);
- const turnplate=useSelector(getTurnplate);
- const appRef = useRef(null);
- const {theme, direction,setIsShowWheel,preLocation,gameID} = useThemeProvider();
- const {pathname, search, hash} = useLocation();
- const gaKey = process.env.REACT_APP_PUBLIC_GA;
- gaKey && ReactGA.initialize(gaKey);
- const navigate = useNavigate();
- // auto RTL support for Material-UI components and styled-components
- const plugins = direction === 'rtl' ? [rtlPlugin] : [];
- const hallServerUrl=useSelector(getHallServerUrl);
- useGlobalClick();
- // const {preLocation,gameID}=usePreviousRoute();
- const serverKick=useSelector(getKickState);
- const promoteInstall=useSelector(getPromoteInstall);
- const popWheel=useSelector(getPopWheel);
- const openPay=useSelector(getOpenPay);
- const guest=useSelector(getIsGuest);
- const popBindPhone=useSelector(getPopBindPhone);
- const [isMaintain, setIsMaintain] = useState(false);
- //是否唤起选择area
- const [isSelectArea, setIsSelectArea] = useState(false);
- const popFirst=useSelector(getPopFirst);
- const firstPayMulti=useSelector(getFirstPayMulti);
- const muiTheme = createTheme({
- direction: direction,
- });
- const cacheRtl = createCache({
- key: 'css-rtl',
- stylisPlugins: plugins,
- });
- const startReqRoutes=()=>{
- //先请求指纹id
- dispatch(getBFP()).then((result)=>{
- dispatch(reqGetRoutes());
- });
- }
- const loadFont=()=>{
- // let swisscbt=new FontFaceObserver("SWISSC-BT");
- // swisscbt.load().then(() => {
- //
- // })
- let timeout=3000;
- // new FontFaceObserver("SWISSC-BT").load(null,timeout).catch(e=>{
- // // console.log(e);
- // });
- // new FontFaceObserver("Roboto").load(null,timeout).catch(e=>{
- // // console.log(e);
- // });
- // new FontFaceObserver("Roboto-1").load(null,timeout).catch(e=>{
- // // console.log(e);
- // });
- }
- //检查邀请码
- const checkInviteCode=()=>{
- let name="act";
- let code=getUrlParam(name);
- if (code!=null){
- localStorageSet(LOCAL_WHEEL_INVITE_CODE,code)
- }
- else {
- localStorageSet(LOCAL_WHEEL_INVITE_CODE,"")
- }
- let cname="c";
- let ccode=getUrlParam(cname);
- if (ccode!=null){
- localStorageSet(LOCAL_ACTIVITY_C,ccode);
- }
- // else{
- // localStorageSet(LOCAL_ACTIVITY_C,"");
- // }
- let bfp=getUrlParam("bfp");
- if (bfp!=null&&bfp!==""){
- localStorageSet(LOCAL_VISTOR_ID,bfp);
- global.BFP=bfp;
- }
- }
- const reProgressierInstallBanner=()=>{
- if (window.NewProgressierInstallBanner!=null)return;
- let ProgressierInstallBanner=window.ProgressierInstallBanner;
- window.NewProgressierInstallBanner=ProgressierInstallBanner;
- window.ProgressierInstallBanner=function (e, t) {
- this.remove = async function() {
- };
- this.render = async function() {
- };
- this.make = function() {
- };
- this.init = async function() {
- }
- }
- }
- const reqInitData=()=>{
- //未初始化
- if (userID===-1)return;
- //onChangeUser
- dispatch(onChangeUser(userInfo));
- if (userID>0){
- dispatch(connectHall(hallServerUrl));
- localStorageSet(LOCAL_WHEEL_INVITE_CODE,"");
- // localStorageSet(LOCAL_ACTIVITY_C,"");
- //Mail红点屏蔽
- dispatch(reqMailCheck());
- dispatch(reqFavoGet());
- checkOpenBindPrompt();
- }
- else
- {
- dispatch(disconnectHall());
- }
- //pay
- // reqPayConfig(dispatch,userInfo);
- // dispatch(reqFirstPayConfig(userID))
- //customer
- // dispatch(reqCustomService());
- //turnplate
- dispatch(reqTurnplateIndex());
- //redpack
- // dispatch(reqRedpackCheck());
- // dispatch(reqRedpackConfig());
- //agent
- // dispatch(reqAgentCheck());
- //activity
- // dispatch(reqGameActivity());
- }
- const appInitData=()=>{
- // scroll to top on route change
- //检查是否维护
- if (checkMaintain())return;
- if (checkAreaSelect())return;
- checkInviteCode();
- checkOpenInChrome();
- loadFont();
- //请求routes
- startReqRoutes();
- appRef.current && appRef.current.scrollTo(0, 0);
- preventDefault();
- reProgressierInstallBanner();
- SoundHelp.loadAllAudioFile();
- // preventTouchMove();
- }
- const checkFirstPay=()=>{
- if (!popFirst)return;
- if (firstPayMulti==null)return;
- let key="first_open_time";
- let now=Date.now();
- let lst=Number(localStorageGet(key,0));
- let delta=now-lst;
- // if (delta<86400000){
- // return false;
- // }
- if (pathname==="/") {
- if (hash == null || hash === "") {
- global.showFirstPay();
- localStorageSet(key,Date.now());
- }
- }
- }
- const checkOpenCheckin=()=>{
- if (userID>0){
- if (pathname==="/"){
- if(hash==null||hash===""){
- let key="checkin_open_time";
- let now=Date.now();
- let lst=Number(localStorageGet(key,0));
- let delta=now-lst;
- if (delta<86400000){
- checkFirstPay();
- return false;
- }
- dispatch(reqCheckinCheck((isCanCheckIn)=>{
- let is_check_first=true;
- if(hash==null||hash===""){
- if(isCanCheckIn===1){
- navigate(ROUTE_PATH.CHECK_IN,{replace:true});
- localStorageSet(key,Date.now());
- is_check_first=false;
- }
- }
- if (is_check_first){
- checkFirstPay();
- }
- }));
- return true;
- }
- }
- }
- checkFirstPay();
- return false;
- }
- const onCloseHallWheel=()=>{
- checkOpenCheckin();
- }
- const checkOpenInstallBox=()=>{
- if (promoteInstall>0){
- if (global.installed===1)return;
- global.installed=1;
- let time=promoteInstall*1000;
- // time=1000;
- setTimeout(async ()=>{
- if (!isShowInstallBox())return;
- let gameID=Number(objInfo.gameID);
- if (gameID>0)return;
- global.showInstallBox();
- },time);
- }
- }
- const checkOpenInChrome=()=>{
- let time=200;
- setTimeout(async ()=>{
- if (!isShowInstallBox())return;
- if (isInAppBrowser()){
- openUrlUseChrome();
- }
- },time);
- }
- //检查打开绑定提示
- const checkOpenBindPrompt=()=>{
- if (guest!==1)return;
- if (popBindPhone!==1)return;
- if (global.ispopBindPhone===1)return;
- if (pathname.startsWith(ROUTE_PATH.GAME))return;
- global.showBindPrompt();
- global.ispopBindPhone=1;
- }
- //检查维护
- const checkMaintain=()=>{
- // let sdate=new Date(2024, 7, 27, 3, 0, 0);
- // let edate=new Date(2024, 7, 27, 7, 0, 0);
- // let stime=sdate.getTime();
- // let etime=edate.getTime();
- //巴西时间
- let stime=getBrazilTimeStamp("2024-08-29 01:00:00");
- // let stime=getBrazilTimeStamp("2024-08-26 16:34:00");
- let etime=getBrazilTimeStamp("2024-08-29 01:10:00");
- let now=Date.now();
- let isopen=false;
- if (now>=stime&&now<=etime){
- isopen=true;
- setIsMaintain(isopen);
- }
- return isopen;
- }
- //检查选择地区
- const checkAreaSelect=()=>{
- let isopen=false;
- let areaID=global.getLocalAreaID();
- if (areaID<=0){
- isopen=true;
- setIsSelectArea(isopen);
- global.showAreaSelect(false);
- }
- return isopen;
- }
- //app Effect
- //初始化
- useEffect(() => {
- appInitData();
- return ()=>{
- }
- }, []);
- //用户信息改变
- useEffect(()=>{
- reqInitData();
- },[userID])
- //转盘
- useEffect(()=>{
- if(turnplate){
- let times=turnplate.times;
- if (times>0){
- if (pathname==="/"){
- if(hash==null||hash===""){
- if(popWheel){
- setIsShowWheel(true);
- return;
- }
- }
- }
- }
- }
- checkOpenCheckin();
- },[turnplate]);
- //监听上一次的路由
- useEffect(()=>{
- if (preLocation){
- let pathname=preLocation.pathname;
- if (pathname){
- if (pathname.startsWith(ROUTE_PATH.GAME)){
- //更新金币
- if (userID>0){
- dispatch(reqGameInfo());
- }
- //从游戏返回弹
- checkFirstPay();
- }
- }
- }
- //检查是否维护
- checkMaintain();
- },[preLocation])
- //监听gameID
- useEffect(()=>{
- dispatch(updateCurrGame(gameID))
- dispatch(hallSendState());
- objInfo.gameID=gameID;
- },[gameID])
- //监听被服务器踢掉
- useEffect(()=>{
- if (serverKick===1){
- if (pathname.startsWith(ROUTE_PATH.GAME)){
- navigate(ROUTE_PATH.HOME,{replace:true});
- }
- }
- },[serverKick])
- //监听安装提示
- useEffect(()=>{
- checkOpenInstallBox();
- },[promoteInstall])
- //监听打开pay
- useEffect(()=>{
- if (openPay===1){
- navigate(ROUTE_PATH.PAY,{replace:true});
- dispatch(updateOpenPay(0));
- }
- },[openPay])
- //app Effect
- const renderLayout=()=>{
- if (isMaintain)return (
- <WMaintainBox open={true}></WMaintainBox>
- );
- if (isSelectArea)return (<></>);
- return (
- <>
- {
- fetchStatus===REQ_STATUS.IDLE?<Layout onCloseHallWheel={onCloseHallWheel} />:(<LoadingFull />)
- }
- </>
- )
- }
- const renderPreload=()=>{
- //维护
- if (isMaintain)return (<></>);
- if (isSelectArea)return (<></>);
- return (
- <>
- {
- <WInstallBox/>
- }
- </>
- )
- }
- const renderAreaSelect=()=>{
- return (
- <WAreaSelect/>
- )
- }
- return (
- <CacheProvider value={cacheRtl}>
- <MuiThemeProvider theme={muiTheme}>
- <ThemeProvider theme={{theme: theme}}>
- <SidebarProvider>
- <ThemeStyles/>
- <ToastContainer theme={theme} autoClose={2500}
- position={direction === 'ltr' ? 'top-right' : 'top-left'}/>
- <StyleSheetManager stylisPlugins={plugins}>
- {
- renderLayout()
- }
- </StyleSheetManager>
- {
- renderPreload()
- }
- {renderAreaSelect()}
- </SidebarProvider>
- </ThemeProvider>
- </MuiThemeProvider>
- </CacheProvider>
- );
- }
- export default App
|