瀏覽代碼

update:更新体育

xiaolin.fu 6 月之前
父節點
當前提交
15dc3dd4fc
共有 1 個文件被更改,包括 21 次插入76 次删除
  1. 21 76
      src/app/[locale]/(TabBar)/sports/SportsClient.tsx

+ 21 - 76
src/app/[locale]/(TabBar)/sports/SportsClient.tsx

@@ -16,24 +16,18 @@ const SportsClient: FC<Props> = (props) => {
   const [currentToken, setCurrentToken] = useState(token);
 
   const btRef = useRef(null);
-  const router = useRouter();
-  const isFreshRef = useRef(false);
+  const router:any = useRouter();
 
-  // Effect to dynamically load the script on client mount
   useEffect(() => {
-    console.log("onLoad=====>0000");
-    if (typeof window !== "undefined") { // Make sure it's only executed on the client
-      console.log("onLoad=====>1111");
+    if (typeof window !== "undefined") { 
       const script = document.createElement("script");
       script.src = "https://ui.invisiblesport.com/bt-renderer.min.js";
       script.async = true;
       script.onload = () => {
-        console.log("onLoad=====> Script Loaded and Initialized");
         onLoad();
       };
       document.body.appendChild(script);
 
-      // Cleanup when the component is unmounted
       return () => {
         console.log("onLoad=====> Clean up");
         if (btRef.current) {
@@ -44,70 +38,32 @@ const SportsClient: FC<Props> = (props) => {
         document.body.removeChild(script); // Remove script when component unmounts
       };
     }
-  }, []); // Trigger the effect when `currentToken` changes
-
+  }, []);
+  
   useEffect(() => {
-    console.log("onLoad=====>22222");
     // 如果token更新了才调用update
     if( currentToken !== token){
-      console.log("onLoad=====>333333");
       updateToken(token);
     }
   }, [token]);
 
-
-  // const updateToken = (newToken: string) => {
-  //   console.log("onLoad=====>44444-0000000");
-  //   // @ts-ignore
-  //     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,
-  //         });
-  //       }
-  //     }
-  // }
-
-
   const updateToken = (newToken: string) => {
-    console.log("onLoad=====>44444-0000000");
     // @ts-ignore
       if(currentToken!== newToken){
-        console.log("onLoad=====>44444");
         setCurrentToken(newToken);
-        // 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,
-            });
-          }
+        // 多次点击当前页面只需要跳转到首页即可
+        // 使用 updateOptions 更新当前的 BTRenderer 参数,而不是重新初始化
+        if (btRef.current) {
+          // 更新 token 和其他配置
+          // @ts-ignore
+          btRef.current.updateOptions({
+            token: newToken, // 更新 token
+            url: '/', // 更新 URL 或其他参数
+            betSlipOffsetBottom: 80,
+            betSlipZIndex: 1000,
+            stickyTop: 0,
+            betSlipOffsetTop: 50,
+          });
         }
         
       }
@@ -129,35 +85,25 @@ const SportsClient: FC<Props> = (props) => {
             }
         });
     return data;
-};
-  // Handle initialization when script is loaded
+  };
+
   const onLoad = () => {
     // @ts-ignore
     const bt = new BTRenderer();
     btRef.current = bt;
-    console.log("onLoad=====>666666",token);
+    // @ts-ignore
     bt.initialize({
         brand_id: brand_id,
         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()
+          window.location.reload();
         },
         themeName: "default",
         lang: "pt-br",
         target: document.getElementById("betby"),
         betSlipOffsetBottom: 80,
         // betSlipOffsetRight: 750,
-
         betSlipZIndex: 1000,
         stickyTop: 0,
         betSlipOffsetTop: 50,
@@ -172,7 +118,6 @@ const SportsClient: FC<Props> = (props) => {
     });
   };
 
-
   return <div id="betby" className="h-[100%]"></div>;
 };