Browse Source

iframe postmessage通信

anxiaoxia 2 years ago
parent
commit
e8078d4a5c
1 changed files with 10 additions and 13 deletions
  1. 10 13
      src/layouts/index.jsx

+ 10 - 13
src/layouts/index.jsx

@@ -107,13 +107,15 @@ export default (props) => {
 
   let setTimer = useRef();
 
-  clearTimeout(setTimer.current);
-  setTimer.current = null;
-  setTimer.current = setTimeout(() => {
-    console.log('----没有点击,退出');
-    window.open('http://10.100.28.70/saasweb/middleware/', '_top');
-  }, 1000 * 60 * 5);
-
+  const logOut = () => {
+    clearTimeout(setTimer.current);
+    setTimer.current = null;
+    setTimer.current = setTimeout(() => {
+      console.log('----没有点击,退出');
+      window.parent.postMessage('loginOut', '*');
+    }, 1000 * 60 * 5);
+  };
+  logOut();
   useEffect(() => {
     clearTimeout(setTimer.current);
     setTimer.current = null;
@@ -123,12 +125,7 @@ export default (props) => {
       className={styles.layout}
       onClick={(event) => {
         console.log('----已点击等待超时,退出');
-        clearTimeout(setTimer.current);
-        setTimer.current = null;
-        setTimer.current = setTimeout(() => {
-          console.log('----点击超时,退出');
-          window.open('http://10.100.28.70/saasweb/middleware/', '_top');
-        }, 1000 * 60 * 5);
+        logOut();
       }}
     >
       <div className={styles.header}>