Commit 15916b72 authored by 周宏民's avatar 周宏民

fix: 集成登录跳转前做菜单权限判断,获取子站优化

parent d6a25018
Pipeline #93634 waiting for manual action with stages
...@@ -14,6 +14,7 @@ import axios from 'axios'; ...@@ -14,6 +14,7 @@ import axios from 'axios';
import { defaultApp } from '@/micro'; import { defaultApp } from '@/micro';
import { useHistory } from '@wisdom-utils/runtime'; import { useHistory } from '@wisdom-utils/runtime';
import LoadPage from '@/components/LoadPage'; import LoadPage from '@/components/LoadPage';
import { getUserInfo, getWebSiteConfig } from '@/api/service/base';
import styles from './index.less'; import styles from './index.less';
const IntegratedSwitch = props => { const IntegratedSwitch = props => {
...@@ -74,13 +75,21 @@ const IntegratedSwitch = props => { ...@@ -74,13 +75,21 @@ const IntegratedSwitch = props => {
useEffect(() => { useEffect(() => {
// if (!window?.globalConfig?.userInfo?.OID || (!(window?.globalConfig?.isIntegration > 1) && window?.globalConfig?.Industry !== '集成登录')) return setDataList([]); // if (!window?.globalConfig?.userInfo?.OID || (!(window?.globalConfig?.isIntegration > 1) && window?.globalConfig?.Industry !== '集成登录')) return setDataList([]);
if (!window?.globalConfig?.userInfo?.OID || !(window?.globalConfig?.isIntegration >= 1)) return setDataList([]); if (!window?.globalConfig?.userInfo?.OID || !(window?.globalConfig?.isIntegration >= 1)) return setDataList([]);
let list = localStorage.getItem('integrationData'); //
list = list ? JSON.parse(list) : [];
if (Array.isArray(list) && list?.length) {
setDataList(list || []);
} else {
appService appService
.GetIntegrationConfig({ .GetIntegrationConfig({
type: '集成登录', type: '集成登录',
userId: window?.globalConfig?.userInfo?.OID ?? null, userId: window?.globalConfig?.userInfo?.OID ?? null,
isEnable: true, isEnable: true,
client: client:
localStorage.getItem('integrationClient') || sessionStorage.getItem('client') || props?.global?.client || '', localStorage.getItem('integrationClient') ||
sessionStorage.getItem('client') ||
props?.global?.client ||
'',
}) })
.then(res => { .then(res => {
setDataList(res?.data || []); setDataList(res?.data || []);
...@@ -88,15 +97,16 @@ const IntegratedSwitch = props => { ...@@ -88,15 +97,16 @@ const IntegratedSwitch = props => {
.catch(err => { .catch(err => {
setDataList([]); setDataList([]);
}); });
}
}, []); }, []);
// 子站跳转 // 子站跳转
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow
const handlePage = useCallback((item, loginAction) => { const handlePage = useCallback((item, loginAction) => {
if (item.subType === '外链') {
setJumpLoading(true); setJumpLoading(true);
jumpProgressStart(); jumpProgressStart();
startTiming(5); startTiming(5);
if (item.subType === '外链') {
// 营收 // 营收
if (item.paramValue === 'ticket') { if (item.paramValue === 'ticket') {
// 获取临时token // 获取临时token
...@@ -129,10 +139,27 @@ const IntegratedSwitch = props => { ...@@ -129,10 +139,27 @@ const IntegratedSwitch = props => {
} }
} }
} else if (item.subType === '内链') { } else if (item.subType === '内链') {
const cli = item.appKey;
const token = props.global?.token || Cookies.get('token');
getWebSiteConfig({
identity: token,
client: cli,
}).then(res => {
if (!res?.data?.[0]?.widgets?.length) {
message.error({
duration: 3,
content: '您没有该板块权限,请联系管理员',
});
return;
}
setJumpLoading(true);
jumpProgressStart();
startTiming(5);
if (window.qiankunIsCache) { if (window.qiankunIsCache) {
store.set('event:dropCache'); store.set('event:dropCache');
} }
const cli = item.appKey;
Cookies.set('client', cli, { Cookies.set('client', cli, {
expires: 86400000 / (24 * 60 * 60 * 1000), expires: 86400000 / (24 * 60 * 60 * 1000),
path: '/', path: '/',
...@@ -157,7 +184,11 @@ const IntegratedSwitch = props => { ...@@ -157,7 +184,11 @@ const IntegratedSwitch = props => {
// props.instance && props.instance.updateConfig(config); // props.instance && props.instance.updateConfig(config);
loginAction && loginAction.getUserInfoAndConfig('', true, item.type); loginAction && loginAction.getUserInfoAndConfig('', true, item.type);
});
} else { } else {
setJumpLoading(true);
jumpProgressStart();
startTiming(5);
let { url } = item; let { url } = item;
if (url?.indexOf('{userId}') >= 0) { if (url?.indexOf('{userId}') >= 0) {
url = url.replace('{userId}', window.globalConfig?.userInfo?.OID); url = url.replace('{userId}', window.globalConfig?.userInfo?.OID);
...@@ -173,6 +204,9 @@ const IntegratedSwitch = props => { ...@@ -173,6 +204,9 @@ const IntegratedSwitch = props => {
} else { } else {
window.open(res.data?.data, '_blank'); window.open(res.data?.data, '_blank');
} }
} else {
setJumpLoading(false);
jumpProgressEnd();
} }
}); });
} }
...@@ -220,7 +254,9 @@ const IntegratedSwitch = props => { ...@@ -220,7 +254,9 @@ const IntegratedSwitch = props => {
</Tooltip> </Tooltip>
</div> </div>
</li> </li>
{dataList.map(item => ( {dataList.map(item => {
if (item.subType === '内链' && item.appKey === props?.global?.client) return null;
return (
<li className={styles.switchPageLi} key={item.name} onClick={event => handlePage(item, loginAction)}> <li className={styles.switchPageLi} key={item.name} onClick={event => handlePage(item, loginAction)}>
<div className={styles.switchPageList}> <div className={styles.switchPageList}>
<Tooltip placement="top" title={item.name}> <Tooltip placement="top" title={item.name}>
...@@ -231,7 +267,8 @@ const IntegratedSwitch = props => { ...@@ -231,7 +267,8 @@ const IntegratedSwitch = props => {
</Tooltip> </Tooltip>
</div> </div>
</li> </li>
))} );
})}
</ul> </ul>
</div> </div>
) : null; ) : null;
......
...@@ -229,6 +229,7 @@ export function logout(data) { ...@@ -229,6 +229,7 @@ export function logout(data) {
sessionStorage.setItem('client', integrationClient); sessionStorage.setItem('client', integrationClient);
} }
localStorage.removeItem('integrationClient'); localStorage.removeItem('integrationClient');
localStorage.removeItem('integrationData');
localStorage.removeItem('access_token'); localStorage.removeItem('access_token');
localStorage.removeItem('password_token'); localStorage.removeItem('password_token');
localStorage.removeItem('password_pwdRegex'); localStorage.removeItem('password_pwdRegex');
......
...@@ -97,7 +97,9 @@ const OnlyFocusStations = props => { ...@@ -97,7 +97,9 @@ const OnlyFocusStations = props => {
<div className={layoutStyles.focusStations} style={{ border: 'none' }}> <div className={layoutStyles.focusStations} style={{ border: 'none' }}>
<ul> <ul>
{Array.isArray(data) {Array.isArray(data)
? data.map(item => StationsItem(item, props.action, props.setVisible, props.actionRef, props.setMenuLoading, props.data)) ? data.map(item =>
StationsItem(item, props.action, props.setVisible, props.actionRef, props.setMenuLoading, props.data),
)
: null} : null}
</ul> </ul>
</div> </div>
...@@ -180,7 +182,7 @@ const renderSite = ({ data, config, loading, setLoading, action, actionRef, setM ...@@ -180,7 +182,7 @@ const renderSite = ({ data, config, loading, setLoading, action, actionRef, setM
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const [stationName, setStationName] = useState(''); const [stationName, setStationName] = useState('');
useEffect(() => { useEffect(() => {
window.share.event.on('changeSiteVisible', (res) => { window.share.event.on('changeSiteVisible', res => {
setStationName(res.currentStationName); setStationName(res.currentStationName);
setVisible(res.visible); setVisible(res.visible);
}); });
...@@ -296,7 +298,7 @@ const Layout = props => { ...@@ -296,7 +298,7 @@ const Layout = props => {
// onTopMenuHeaderClick(res) // onTopMenuHeaderClick(res)
// }); // });
window.onTopMenuHeaderClick_=onTopMenuHeaderClick window.onTopMenuHeaderClick_ = onTopMenuHeaderClick;
event.on('loading', ret => { event.on('loading', ret => {
setSubLoading(ret); setSubLoading(ret);
...@@ -327,19 +329,19 @@ const Layout = props => { ...@@ -327,19 +329,19 @@ const Layout = props => {
? `&generateType=${generateType}` ? `&generateType=${generateType}`
: ''; : '';
const integrationClient = localStorage.getItem('integrationClient'); const integrationClient = localStorage.getItem('integrationClient');
if(integrationClient) client = integrationClient if (integrationClient) client = integrationClient;
if (!isLogin) { if (!isLogin) {
history.push(`/user/login?client=${client}${generateType}`, { reload: true }); history.push(`/user/login?client=${client}${generateType}`, { reload: true });
clear(); clear();
props.logout(); props.logout();
} }
if(props.global.security === "1") { if (props.global.security === '1') {
store.off('event:unauthorized'); store.off('event:unauthorized');
} else { } else {
store.on('event:unauthorized', () => { store.on('event:unauthorized', () => {
store.off('event:unauthorized'); store.off('event:unauthorized');
const key = `open${Date.now()}`; const key = `open${Date.now()}`;
if(notify) return false; if (notify) return false;
notify = true; notify = true;
notification.open({ notification.open({
description: '登录认证过期,即将跳转到登录页', description: '登录认证过期,即将跳转到登录页',
...@@ -354,8 +356,10 @@ const Layout = props => { ...@@ -354,8 +356,10 @@ const Layout = props => {
notify = null; notify = null;
clear(); clear();
props.logout(); props.logout();
}) });
}}>确认 }}
>
确认
</Button> </Button>
), ),
key, key,
...@@ -388,13 +392,17 @@ const Layout = props => { ...@@ -388,13 +392,17 @@ const Layout = props => {
const GetIntegrationConfig = () => { const GetIntegrationConfig = () => {
if (first) { if (first) {
const integrationClient = localStorage.getItem('integrationClient'); const integrationClient = localStorage.getItem('integrationClient');
let list = localStorage.getItem('integrationData'); //
list = list ? JSON.parse(list) : [];
if (Array.isArray(list) && list?.length) {
setIntegrationData(list);
} else {
appService appService
.GetIntegrationConfig({ .GetIntegrationConfig({
type: '集成登录', type: '集成登录',
userId: window.globalConfig.userInfo?.OID ?? null, userId: window.globalConfig.userInfo?.OID ?? null,
isEnable: true, isEnable: true,
client: integrationClient || props.global.client // 只有指定client才能获取集成登录信息 client: integrationClient || props.global.client, // 只有指定client才能获取集成登录信息
}) })
.then(res => { .then(res => {
setFirst(false); setFirst(false);
...@@ -404,10 +412,10 @@ const Layout = props => { ...@@ -404,10 +412,10 @@ const Layout = props => {
} else { } else {
setIntegrationData([]); setIntegrationData([]);
} }
}) });
} }
} }
};
useEffect(() => { useEffect(() => {
if (window?.globalConfig?.isIntegration >= 1) { if (window?.globalConfig?.isIntegration >= 1) {
...@@ -433,7 +441,7 @@ const Layout = props => { ...@@ -433,7 +441,7 @@ const Layout = props => {
window.share.event.removeAllListeners('updateSite'); window.share.event.removeAllListeners('updateSite');
loginAction.events.removeListener('toggleIndustry', handleToggleIndustry); loginAction.events.removeListener('toggleIndustry', handleToggleIndustry);
}; };
}, [GetIntegrationConfig, loginAction.events, props]); }, [loginAction.events, props]);
useEffect(() => { useEffect(() => {
const needMark = () => const needMark = () =>
...@@ -448,7 +456,7 @@ const Layout = props => { ...@@ -448,7 +456,7 @@ const Layout = props => {
return () => { return () => {
const marks = document.querySelectorAll('.pandawatermark_mask_div'); const marks = document.querySelectorAll('.pandawatermark_mask_div');
if (marks && marks.length) { if (marks && marks.length) {
Array.prototype.forEach.call(marks, function (dom, index) { Array.prototype.forEach.call(marks, function(dom, index) {
document.body.removeChild(dom); document.body.removeChild(dom);
}); });
} }
...@@ -460,29 +468,31 @@ const Layout = props => { ...@@ -460,29 +468,31 @@ const Layout = props => {
const integrationClient = localStorage.getItem('integrationClient'); const integrationClient = localStorage.getItem('integrationClient');
// integrationClient存在,则返回集成登录站点 // integrationClient存在,则返回集成登录站点
if (window.globalConfig.isIntegration > 1 || integrationData.length > 1 || integrationClient) { if (window.globalConfig.isIntegration > 1 || integrationData.length > 1 || integrationClient) {
if(integrationClient){ if (integrationClient) {
Cookies.set(integrationClient, '', { Cookies.set(integrationClient, '', {
path: '/', path: '/',
}); });
window.globalConfig.client = integrationClient; window.globalConfig.client = integrationClient;
props.updateConfig( Object.assign({}, window.globalConfig, { props.updateConfig(
Object.assign({}, window.globalConfig, {
client: integrationClient, client: integrationClient,
}),
})) );
sessionStorage.setItem('client', integrationClient); sessionStorage.setItem('client', integrationClient);
localStorage.removeItem('integrationClient'); localStorage.removeItem('integrationClient');
// localStorage.removeItem('integrationData');
} }
// window.qiankunIsCache = false; // window.qiankunIsCache = false;
history.push('/Industry'); history.push('/Industry');
} }
// 非云平台不做响应 // 非云平台不做响应
if (!props.global.get('userInfo.site')) { if (!props.global.get('userInfo.site')) {
if(props.global.get("isOpenTransitionPage")) { if (props.global.get('isOpenTransitionPage')) {
if (window.qiankunIsCache) { if (window.qiankunIsCache) {
store.set('event:refreshCurrentMenu', { store.set('event:refreshCurrentMenu', {
dropCache: true, dropCache: true,
action: 'closeAllTabs' action: 'closeAllTabs',
}) });
} }
history.push('/homePage'); history.push('/homePage');
} }
...@@ -500,11 +510,11 @@ const Layout = props => { ...@@ -500,11 +510,11 @@ const Layout = props => {
// setMenuLoading(false); // setMenuLoading(false);
// }, [props.menu]); // }, [props.menu]);
const onTopMenuHeaderClick = (index => { const onTopMenuHeaderClick = index => {
props.updateCurrentIndex(index); props.updateCurrentIndex(index);
window.share && window.share.event.emit('trigger:updateMenuIndex', index); window.share && window.share.event.emit('trigger:updateMenuIndex', index);
store.set('updateMenuIndex', index); store.set('updateMenuIndex', index);
}); };
const logo = const logo =
props.global && _.isFunction(props.global.get) && props.global.get('bannerLogo') props.global && _.isFunction(props.global.get) && props.global.get('bannerLogo')
...@@ -556,7 +566,7 @@ const Layout = props => { ...@@ -556,7 +566,7 @@ const Layout = props => {
if (url.indexOf('|') > -1) { if (url.indexOf('|') > -1) {
const params = url.split('|')[1]; const params = url.split('|')[1];
params.split('&').map(function (item) { params.split('&').map(function(item) {
return (ret[item.split('=')[0]] = item.split('=')[1]); return (ret[item.split('=')[0]] = item.split('=')[1]);
}); });
return ret; return ret;
...@@ -575,11 +585,11 @@ const Layout = props => { ...@@ -575,11 +585,11 @@ const Layout = props => {
// 渲染集成站点切换弹框 // 渲染集成站点切换弹框
const renderIntegration = (inData, loginAction, props) => { const renderIntegration = (inData, loginAction, props) => {
if (inData.length <= 1) { if (inData.length <= 1) {
return <></> return <></>;
} }
const choiceOne = inData?.find(function (a) { const choiceOne = inData?.find(function(a) {
return a.url?.indexOf(window?.globalConfig?.client) >= 0 return a.url?.indexOf(window?.globalConfig?.client) >= 0;
}) });
// 切换集成站点 // 切换集成站点
const checkIntegration = (val, loginAction, props) => { const checkIntegration = (val, loginAction, props) => {
...@@ -590,7 +600,7 @@ const Layout = props => { ...@@ -590,7 +600,7 @@ const Layout = props => {
if (res.code === 0) { if (res.code === 0) {
setVisible(false); setVisible(false);
const url = `${val.url + (val.url.indexOf('?') > 0 ? '&' : '?') + val.paramName}=${res.data}`; const url = `${val.url + (val.url.indexOf('?') > 0 ? '&' : '?') + val.paramName}=${res.data}`;
window.open(url, "_blank"); window.open(url, '_blank');
} else { } else {
setVisible(false); setVisible(false);
notification.error({ notification.error({
...@@ -602,15 +612,17 @@ const Layout = props => { ...@@ -602,15 +612,17 @@ const Layout = props => {
}); });
} else { } else {
setVisible(false); setVisible(false);
const url = `${val.url + (val.url.indexOf('?') > 0 ? '&' : '?') + val.paramName}=${window.globalConfig?.token}`; const url = `${val.url + (val.url.indexOf('?') > 0 ? '&' : '?') + val.paramName}=${
window.open(url, "_blank"); window.globalConfig?.token
}`;
window.open(url, '_blank');
} }
} else { } else {
if (window.qiankunIsCache) { if (window.qiankunIsCache) {
store.set('event:refreshCurrentMenu', { store.set('event:refreshCurrentMenu', {
dropCache: true, dropCache: true,
action: 'closeAllTabs' action: 'closeAllTabs',
}) });
} }
const cli = val.url?.indexOf('client=') >= 0 ? val.url.split('client=')[1] : ''; const cli = val.url?.indexOf('client=') >= 0 ? val.url.split('client=')[1] : '';
Cookies.set('client', cli, { Cookies.set('client', cli, {
...@@ -618,7 +630,8 @@ const Layout = props => { ...@@ -618,7 +630,8 @@ const Layout = props => {
path: '/', path: '/',
}); });
sessionStorage.setItem('client', cli); sessionStorage.setItem('client', cli);
const currentProduct = `__global__recent_productIndex__micro_${window.location.hostname}_${window.globalConfig?.client ?? 'city'}`; const currentProduct = `__global__recent_productIndex__micro_${window.location.hostname}_${window.globalConfig
?.client ?? 'city'}`;
sessionStorage.removeItem(currentProduct); sessionStorage.removeItem(currentProduct);
const currentProductNew = `__global__recent_productIndex__micro_${window.location.hostname}_${cli || 'city'}`; const currentProductNew = `__global__recent_productIndex__micro_${window.location.hostname}_${cli || 'city'}`;
sessionStorage.setItem(currentProductNew, 0); sessionStorage.setItem(currentProductNew, 0);
...@@ -637,7 +650,7 @@ const Layout = props => { ...@@ -637,7 +650,7 @@ const Layout = props => {
// props.updateCurrentIndex(0); // props.updateCurrentIndex(0);
// defaultApp(); // defaultApp();
} }
} };
return ( return (
<> <>
...@@ -647,14 +660,8 @@ const Layout = props => { ...@@ -647,14 +660,8 @@ const Layout = props => {
visible={visible} visible={visible}
content={ content={
<div className={layoutStyles.integrationList}> <div className={layoutStyles.integrationList}>
{ {<Loading loading={integrationLoading} />}
<Loading loading={integrationLoading} /> {inData && inData.map(val => <p onClick={() => checkIntegration(val, loginAction, props)}>{val.name}</p>)}
}
{
inData && inData.map((val) => (
<p onClick={() => checkIntegration(val, loginAction, props)}>{val.name}</p>
))
}
</div> </div>
} }
arrowPointAtCenter arrowPointAtCenter
...@@ -675,8 +682,8 @@ const Layout = props => { ...@@ -675,8 +682,8 @@ const Layout = props => {
) : null} ) : null}
</Popover> </Popover>
</> </>
) );
} };
// 菜单比对方法 // 菜单比对方法
const querySkipUrl = (data, url) => { const querySkipUrl = (data, url) => {
...@@ -759,11 +766,9 @@ const Layout = props => { ...@@ -759,11 +766,9 @@ const Layout = props => {
}} }}
headerSiteRender={() => headerSiteRender={() =>
window?.globalConfig?.isIntegration >= 1 window?.globalConfig?.isIntegration >= 1
? ? // renderIntegration(integrationData, loginAction, props)
// renderIntegration(integrationData, loginAction, props)
null null
: : renderSite({
renderSite({
data: cityData, data: cityData,
config: props.global, config: props.global,
loading: siteLoading, loading: siteLoading,
...@@ -783,13 +788,14 @@ const Layout = props => { ...@@ -783,13 +788,14 @@ const Layout = props => {
{dom} {dom}
</a> </a>
)} )}
menuSuffixRender={() => ( menuSuffixRender={() =>
props.global?.variableTheme?.navTheme === 'chinaWater' ? props.global?.variableTheme?.navTheme === 'chinaWater' ? (
(<img src={require('../assets/basic/chinaWater.png')} style={{width: '100%'}} alt="" />) <img src={require('../assets/basic/chinaWater.png')} style={{ width: '100%' }} alt="" />
: <></> ) : (
)} <></>
)
}
> >
<div id="micro-container" className="subapp-container"> <div id="micro-container" className="subapp-container">
{props.children} {props.children}
</div> </div>
......
...@@ -9,6 +9,7 @@ import { connect } from 'react-redux'; ...@@ -9,6 +9,7 @@ import { connect } from 'react-redux';
import { actionCreators } from '@/containers/App/store'; import { actionCreators } from '@/containers/App/store';
import axios from 'axios'; import axios from 'axios';
import { getImageUrl } from '@/utils/utils'; import { getImageUrl } from '@/utils/utils';
import { getUserInfo, getWebSiteConfig } from '@/api/service/base';
import { FullscreenExitOutlined, FullscreenOutlined } from '@ant-design/icons'; import { FullscreenExitOutlined, FullscreenOutlined } from '@ant-design/icons';
import { message, Button } from 'antd'; import { message, Button } from 'antd';
...@@ -100,7 +101,7 @@ const IntegrationNew = props => { ...@@ -100,7 +101,7 @@ const IntegrationNew = props => {
}) })
.then(res1 => { .then(res1 => {
const list = res1.data || []; const list = res1.data || [];
list.length && localStorage.setItem('integrationData', JSON.stringify(list));
setIntegrationData(list); setIntegrationData(list);
}); });
}; };
...@@ -175,11 +176,24 @@ const IntegrationNew = props => { ...@@ -175,11 +176,24 @@ const IntegrationNew = props => {
} }
}; };
const toClient = (item, loginA) => { const toClient = async (item, loginA) => {
const token = props.global?.token || Cookies.get('token');
const cli = item.appKey;
const res = await getWebSiteConfig({
identity: token,
client: cli,
});
if (!res?.data?.[0]?.widgets?.length) {
message.error({
duration: 3,
content: '您没有该板块权限,请联系管理员',
});
return;
}
if (window.qiankunIsCache) { if (window.qiankunIsCache) {
store.set('event:dropCache'); store.set('event:dropCache');
} }
const cli = item.appKey;
Cookies.set('client', cli, { Cookies.set('client', cli, {
expires: 86400000 / (24 * 60 * 60 * 1000), expires: 86400000 / (24 * 60 * 60 * 1000),
path: '/', path: '/',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment