|
@ -1,17 +1,22 @@ |
|
|
'use strict'; |
|
|
'use strict'; |
|
|
import React, { useEffect, useRef } from 'react'; |
|
|
import React, { useEffect, useRef } from 'react'; |
|
|
import { connect } from "react-redux"; |
|
|
import { connect } from "react-redux"; |
|
|
|
|
|
import authAction from '../actions' |
|
|
|
|
|
|
|
|
const Cross = ({ dispatch, actions }) => { |
|
|
const Cross = ({ dispatch, actions }) => { |
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
useEffect(async () => { |
|
|
|
|
|
function preLogout () { |
|
|
|
|
|
localStorage.removeItem('fs_iot_cross_user') |
|
|
|
|
|
sessionStorage.removeItem('user') |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function messageListen (e) { |
|
|
function messageListen (e) { |
|
|
// 此处需做 域名 验证 |
|
|
// 此处需做 域名 验证 |
|
|
const { data } = e |
|
|
const { data } = e |
|
|
if (data && data.action) { |
|
|
if (data && data.action) { |
|
|
if (data.action == 'logout') { |
|
|
if (data.action == 'logout') { |
|
|
localStorage.removeItem('fs_iot_cross_user') |
|
|
preLogout() |
|
|
sessionStorage.removeItem('user') |
|
|
|
|
|
} else if (data.action = 'login') { |
|
|
} else if (data.action = 'login') { |
|
|
localStorage.setItem('fs_iot_cross_user', JSON.stringify(data.user)) |
|
|
localStorage.setItem('fs_iot_cross_user', JSON.stringify(data.user)) |
|
|
} |
|
|
} |
|
@ -30,8 +35,20 @@ const Cross = ({ dispatch, actions }) => { |
|
|
window.addEventListener('message', messageListen); |
|
|
window.addEventListener('message', messageListen); |
|
|
window.addEventListener("storage", storageListen); |
|
|
window.addEventListener("storage", storageListen); |
|
|
const user = localStorage.getItem('fs_iot_cross_user') |
|
|
const user = localStorage.getItem('fs_iot_cross_user') |
|
|
|
|
|
|
|
|
if (user) { |
|
|
if (user) { |
|
|
|
|
|
const crossRslt = await dispatch(authAction.crossCheck({ token: user.token })) |
|
|
|
|
|
if (crossRslt.success) { |
|
|
|
|
|
if (crossRslt.payload.data.cross) { |
|
|
window.parent.postMessage({ action: 'initUser', user: JSON.parse(user) }, '*'); |
|
|
window.parent.postMessage({ action: 'initUser', user: JSON.parse(user) }, '*'); |
|
|
|
|
|
} else { |
|
|
|
|
|
window.parent.postMessage({ action: 'logout' }, '*'); |
|
|
|
|
|
preLogout() |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
window.parent.postMessage({ action: 'logout' }, '*'); |
|
|
|
|
|
preLogout() |
|
|
|
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
window.parent.postMessage({ action: 'initNotice' }, '*'); |
|
|
window.parent.postMessage({ action: 'initNotice' }, '*'); |
|
|
} |
|
|
} |
|
|