Sfoglia il codice sorgente

监听pg closeloading计数 2次强制回大厅

zhejiushizhuce 2 anni fa
parent
commit
f3fae90354
2 ha cambiato i file con 22 aggiunte e 2 eliminazioni
  1. 16 1
      src/hooks/useGameIFrame.js
  2. 6 1
      src/widgets/WGame/index.jsx

+ 16 - 1
src/hooks/useGameIFrame.js

@@ -2,15 +2,26 @@ import {useEffect, useRef, useState} from "react";
 import {ROUTE_PATH} from "@constants/routes";
 import {openFullScreen} from "@utils/helpers";
 import {useNavigate} from "react-router-dom";
-
+const objInfo={
+    closeCount:0
+}
 const useGameIFrame = () => {
     const iFrameRef = useRef(null);
     const [isGameLoad,setIsGameLoad]=useState(false);
     const navigate = useNavigate();
     const onBack=()=>{
         // dispatch(reqGameInfo());
+        if (iFrameRef.extBackFunc!=null){
+            iFrameRef.extBackFunc();
+            return;
+        }
         navigate(ROUTE_PATH.BACK);
     }
+    const checkCloseCount=()=>{
+        if (objInfo.closeCount>=2){
+            onBack();
+        }
+    }
     const receiveMessage=(event)=>{
         let data=event.data;
         // console.log(data);
@@ -30,6 +41,8 @@ const useGameIFrame = () => {
             }
             else if (data.cmd==="closeLoading"){
                 setIsGameLoad(true);
+                objInfo.closeCount++;
+                checkCloseCount();
             }
         }
     }
@@ -55,6 +68,7 @@ const useGameIFrame = () => {
             },5000);
         }
         window.addEventListener("message", receiveMessage, false);
+        objInfo.closeCount=0;
     }
     const removeGameEvent=()=>{
         const gameFrame = iFrameRef.current;
@@ -63,6 +77,7 @@ const useGameIFrame = () => {
             clearGameTimeout();
         }
         window.removeEventListener("message", receiveMessage);
+        objInfo.closeCount=0;
     }
     useEffect(() => {
         initGameEvent();

+ 6 - 1
src/widgets/WGame/index.jsx

@@ -35,7 +35,7 @@ const WGame=()=>{
     const navigate=useNavigate();
     const backBoxRef = useRef(null);
     const [dragDeltaY,setDragDeltaY]=useState(0);
-    const {isGameLoad,setIsGameLoad,iFrameRef}=useGameIFrame();
+    const {isGameLoad,setIsGameLoad,iFrameRef,setExtBackFunc}=useGameIFrame();
     const gameCardInfo=useSelector(getGameCardInfo(gameid));
     const onBack=()=>{
         // dispatch(reqGameInfo());
@@ -68,6 +68,11 @@ const WGame=()=>{
         if (Number(gameid)>0&&gameCardInfo==null){
             dispatch(reqGameCardInfo(gameid));
         }
+        if (iFrameRef!=null){
+            iFrameRef.extBackFunc=()=>{
+                onBack();
+            }
+        }
         return () => {
 
         };