Prechádzať zdrojové kódy

update:更新体育

xiaolin.fu 6 mesiacov pred
rodič
commit
603eb73e49

+ 33 - 18
src/app/[locale]/(TabBar)/sports/SportsClient.tsx

@@ -16,10 +16,11 @@ const SportsClient: FC<Props> = (props) => {
     const { brand_id, token } = props;
     const [currentToken, setCurrentToken] = useState(token);
 
-
     const btRef = useRef(null);
     const router = useRouter();
 
+    const isFreshRef = useRef(false);
+    const hasCleanedUp = useRef(false);
 
     useEffect(() => {
       console.log("onLoad=====>0000");
@@ -31,13 +32,13 @@ const SportsClient: FC<Props> = (props) => {
       
       // 离开体育页的时候需要kill掉
       return () => {
-        console.log("onLoad=====>killkillkillkillkill");
-        if(btRef.current){
+        console.log("onLoad=====>killkillkillkillkill",btRef.current);
+        if(btRef.current && !hasCleanedUp.current){
           // @ts-ignore
           btRef.current?.kill();
           btRef.current = null;
+          hasCleanedUp.current = true;
         }
-          
       };
     }, []);
 
@@ -50,6 +51,8 @@ const SportsClient: FC<Props> = (props) => {
       }
     }, [token]);
 
+
+
     const getGameDetailApi = async () => {
         const data = await server
             .request<GameInfo>({
@@ -74,20 +77,29 @@ const SportsClient: FC<Props> = (props) => {
         if(currentToken!== newToken){
           console.log("onLoad=====>44444");
           setCurrentToken(newToken);
-           // 使用 updateOptions 更新当前的 BTRenderer 参数,而不是重新初始化
-          if (btRef.current) {
-            console.log("onLoad=====>55555");
-            // 更新 token 和其他配置
-            // @ts-ignore
-            btRef.current.updateOptions({
-              token: newToken, // 更新 token
-              url: '/', // 更新 URL 或其他参数
-              betSlipOffsetBottom: 80,
-              betSlipZIndex: 1000,
-              stickyTop: 0,
-              betSlipOffsetTop: 50,
-            });
+          // session失效需要重新load
+          // @ts-ignore
+          if (window.BTRenderer && !!isFreshRef.current) {
+            console.log("onLoad=====>1111isFreshRef");
+            onLoad();
+          }else{
+            // 多次点击当前页面只需要跳转到首页即可
+            // 使用 updateOptions 更新当前的 BTRenderer 参数,而不是重新初始化
+            if (btRef.current) {
+              console.log("onLoad=====>55555");
+              // 更新 token 和其他配置
+              // @ts-ignore
+              btRef.current.updateOptions({
+                token: newToken, // 更新 token
+                url: '/', // 更新 URL 或其他参数
+                betSlipOffsetBottom: 80,
+                betSlipZIndex: 1000,
+                stickyTop: 0,
+                betSlipOffsetTop: 50,
+              });
+            }
           }
+          
         }
     }
 
@@ -101,12 +113,15 @@ const SportsClient: FC<Props> = (props) => {
           token: token,//使用最新的token
           onTokenExpired: getGameDetailApi, //过期自动更新token
           onSessionRefresh: () => {
+            console.log('onLoad=====>onSessionRefresh')
             // 销毁之前的实例并等待刷新完成
             if(btRef.current){
+              console.log('onLoad=====>onSessionRefresh1111')
               // @ts-ignore
               btRef.current?.kill();
             }
-            
+            isFreshRef.current = true;
+            console.log('onLoad=====>onSessionRefresh11112222')
             router.refresh()
           },
           themeName: "default",