Эх сурвалжийг харах

修改请求 init 之前请求token 新页面bt-path 解析

zhejiushizhuce 2 жил өмнө
parent
commit
5e385fc564

+ 30 - 1
src/pages/Sport.jsx

@@ -1,9 +1,38 @@
 import WSport from "@widgets/WSport";
+import {useEffect, useState} from "react";
+import {reqGameInfo} from "@features/api";
+import LoadingIn from "@components/Loading/LoadingIn";
+import {useDispatch} from "react-redux";
+import {useLocation} from "react-router-dom";
+import {ROUTE_PATH} from "@constants/routes";
 
 const Sport = ({...props}) => {
+    const [isReToken, setIsReToken] = useState(false);
+    const dispatch = useDispatch();
+    const {pathname} = useLocation();
+    const initSport=()=>{
+        setIsReToken(false);
+        dispatch(reqGameInfo()).then(({payload})=>{
+            setIsReToken(true);
+        });
+    }
+    const resetSport=()=>{
+        initSport();
+    }
+    useEffect(()=>{
+        if (pathname===ROUTE_PATH.SPORTS||pathname===ROUTE_PATH.RACING){
+            initSport();
+        }
+        else
+        {
+            if (!isReToken)setIsReToken(true);
+        }
+    },[pathname])
     return (
         <>
-            <WSport {...props}/>
+            {
+                !isReToken?(<LoadingIn></LoadingIn>):(<WSport {...props} resetSport={resetSport}/>)
+            }
         </>
     )
 }

+ 20 - 4
src/widgets/WSport/index.jsx

@@ -14,12 +14,21 @@ import {APP_THEME} from "@constants/app";
 import {useLocation, useNavigate} from "react-router-dom";
 import {ROUTE_PATH} from "@constants/routes";
 import {reqGameInfo} from "@features/api";
+import {getUrlParam} from "@utils/helpers";
 const i18n=global.i18n;
 const objInfo={
     bt:null,
     timer:null
 }
-const WSport=({})=>{
+const checkStartPath=(pathname)=>{
+    let path=pathname.startsWith(ROUTE_PATH.RACING)?"/horse-racing-55":"/";
+    let bt_path=getUrlParam("bt-path");
+    if (bt_path!=null&&bt_path!==""){
+        path=bt_path;
+    }
+    return path;
+}
+const WSport=({resetSport})=>{
     const {isMobile}=useThemeProvider();
     const bbConf=useSelector(getBBConf);
     const {theme}=useThemeProvider();
@@ -29,7 +38,8 @@ const WSport=({})=>{
     const navigate=useNavigate();
     const dispatch=useDispatch();
     const {pathname,hash} = useLocation();
-    const tempSPath=pathname.startsWith(ROUTE_PATH.RACING)?"/horse-racing-55":"/";
+    // const tempSPath=pathname.startsWith(ROUTE_PATH.RACING)?"/horse-racing-55":"/";
+    const tempSPath=checkStartPath(pathname);
     const [sportPath,setSportPath]=useState(tempSPath);
     const btToken=useSelector(getUserBBToken);
     const userLang=useSelector(getUserLang);
@@ -87,7 +97,10 @@ const WSport=({})=>{
             onRecharge:function (){
                 navigate(ROUTE_PATH.PAY);
             },
-            onSessionRefresh: function() {},
+            onSessionRefresh: function() {
+                // resetBT();
+                if (resetSport)resetSport();
+            },
             onBetSlipStateChange: function() {}
         })
         return bt;
@@ -158,9 +171,12 @@ const WSport=({})=>{
     //         })
     //     }
     // },[language])
-    useEffect(()=>{
+    const resetBT=()=>{
         clearBT();
         objInfo.bt=initBetby();
+    }
+    useEffect(()=>{
+        resetBT();
         return ()=>{
             clearBT();
             clearTimer();