Commit 4c0bcfbc authored by 李纪文's avatar 李纪文

feat: 集成登录增加切换菜单

parent dad53c06
Pipeline #89817 waiting for manual action with stages
This diff was suppressed by a .gitattributes entry.
/* eslint-disable prettier/prettier */
import React, { useEffect, useState, useCallback, useRef } from 'react';
import classNames from 'classnames';
import { connect } from 'react-redux';
import { actionCreators } from '@/containers/App/store';
import { store } from '@wisdom-utils/utils';
import LoginAction from '@/pages/user/login/login';
import Cookies from 'js-cookie';
import { notification, Tooltip } from 'antd';
import homeIcon from '@/assets/bootPage/集成登录.png';
import { appService } from '@/api';
import axios from 'axios';
import { defaultApp } from '@/micro';
import { useHistory } from '@wisdom-utils/runtime';
import styles from './index.less';
const IntegratedSwitch = props => {
const history = useHistory();
const [loginAction, setAction] = useState(() => new LoginAction(props));
const [dataList, setDataList] = useState([]);
const [client, setClient] = useState('');
useEffect(() => {
const cli = '';
sessionStorage.setItem('client', cli);
if (!window?.globalConfig?.userInfo?.OID || !(window?.globalConfig?.isIntegration >= 1)) return setDataList([]);
appService.GetIntegrationConfig({
type: '集成登录',
userId: window?.globalConfig?.userInfo?.OID ?? null,
isEnable: true,
client: `${client || cli || props.global.client}`,
})
.then(res => {
setDataList(res?.data || []);
})
.catch(err => {
setDataList([]);
});
}, []);
// 子站跳转
// eslint-disable-next-line no-shadow
const handlePage = useCallback((item, loginAction) => {
if (item.subType === '外链') {
if (item.paramValue === 'ticket') {
// 获取临时token
appService.getTicketByToken({ token: window.globalConfig?.token }).then(res => {
if (res.code === 0) {
const url = `${item.url + (item.url.indexOf('?') > 0 ? '&' : '?') + item.paramName}=${res.data}`;
window.open(url, '_blank');
} else {
notification.error({
message: '提示',
duration: 3,
description: res.msg,
});
}
});
} else {
const url = `${item.url + (item.url.indexOf('?') > 0 ? '&' : '?') + item.paramName}=${window.globalConfig?.token}`;
window.open(url, '_blank');
}
} else if (item.subType === '内链') {
if (window.qiankunIsCache) {
store.set('event:dropCache');
}
const cli = item.url?.indexOf('client=') >= 0 ? item.url.split('client=')[1] : '';
Cookies.set('client', cli, {
expires: 86400000 / (24 * 60 * 60 * 1000),
path: '/',
});
sessionStorage.setItem('client', cli);
const currentProduct = `__global__recent_productIndex__micro_${window.location.hostname}_${window.globalConfig
?.client ?? 'city'}`;
sessionStorage.removeItem(currentProduct);
const currentProductNew = `__global__recent_productIndex__micro_${window.location.hostname}_${cli || 'city'}`;
sessionStorage.setItem(currentProductNew, 0);
setClient(cli);
const config = props.global;
config.uiwidgets = [];
config.widgets = [];
config.allWidgets = [];
window.qiankunStarted = false;
if (cli) {
config.client = cli;
}
// props.instance && props.instance.updateConfig(config);
loginAction && loginAction.getUserInfoAndConfig('', true, item.type);
} else {
let { url } = item;
if (url?.indexOf('{userId}') >= 0) {
url = url.replace('{userId}', window.globalConfig?.userInfo?.OID);
}
axios({
url,
method: 'get',
dataType: 'json',
}).then(res => {
if (res?.data?.code === 0) {
history.push('/thirdParty', { linkUrl: res.data?.data });
}
});
}
});
useEffect(() => {
const cli = '';
sessionStorage.setItem('client', cli);
const handleToggleIndustry = event => {
history.push(`/?client=${client || cli || props.global.client}`);
props.updateCurrentIndex(0);
defaultApp();
};
loginAction.events.on('toggleIndustry', handleToggleIndustry);
return () => {
loginAction.events.removeListener('toggleIndustry', handleToggleIndustry);
};
}, [loginAction.events, props]);
return (
dataList.length > 1 ? <div className={styles.switchPage}>
<ul className={classNames(styles.switchPageCase, styles.switchPageSmall)}>
<li className={styles.switchPageLi} onClick={() => { history.push('/industry'); }}>
<div className={styles.switchPageList}>
<Tooltip placement="top" title="主页">
<img
src={homeIcon}
alt=""
/>
</Tooltip>
</div>
</li>
{dataList.map(item => (
<li className={styles.switchPageLi} key={item.name} onClick={event => handlePage(item, loginAction)}>
<div className={styles.switchPageList}>
<Tooltip placement="top" title={item.name}>
<img
src={`${window.location.origin}/${item.icon ? item.icon : 'center/images/科技风/二供.png'}`}
alt=""
/>
</Tooltip>
</div>
</li>
))}
</ul>
</div > : null
);
};
const mapStateToProps = state => ({
global: state.getIn(['global', 'globalConfig']),
instance: state.getIn(['global', 'instance']),
client: state.getIn(['global', 'client']),
});
const mapDispatchToProps = dispatch => ({
updateConfig(config) {
dispatch(actionCreators.getConfig(config));
},
createContext(data) {
dispatch(actionCreators.createContext(data));
},
updateCurrentIndex(index) {
dispatch(actionCreators.updateCurrentIndex(index));
},
});
export default connect(
mapStateToProps,
mapDispatchToProps,
)(IntegratedSwitch);
.switchPage {
position: fixed;
bottom: 0;
left: 0;
z-index: 1200;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 0px;
.switchPageCase {
position: absolute;
bottom: 0;
padding: 0 10px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 14px;
overflow: hidden;
height: 8px;
width: 80px;
background: rgba(94, 121, 143, .65);
transition: height .5s ease;
margin: 0 0 6px 0;
&:hover {
height: 50px;
width: auto;
.switchPageLi {
display: flex;
}
}
}
.switchPageLi {
padding: 10px;
display: none;
height: 100%;
overflow: hidden;
opacity: 0.8;
&:hover {
opacity: 1;
}
}
.switchPageList {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
height: 100%;
>img {
height: 100%;
cursor: pointer;
}
}
}
\ No newline at end of file
......@@ -30,6 +30,7 @@ import { Storeage as Store } from '@wisdom-utils/utils/lib/helpers';
import { defaultApp } from '@/micro';
import { appService } from '@/api';
import LoginAction from '@/pages/user/login/login';
import IntegratedSwitch from '@/components/IntegratedSwitch';
import Loading from '../components/Loading';
import { waterMark } from '../utils/mark';
import layoutStyles from './BasicLayout.less';
......@@ -797,6 +798,7 @@ const Layout = props => {
<div id="micro-container" className="subapp-container">
{props.children}
</div>
<IntegratedSwitch />
<SoundAi />
{subLoading && <Loading loading={subLoading} />}
{initWebContent && <Loading loading={initWebContent} />}
......
......@@ -107,7 +107,8 @@ const Integration = props => {
dataType: 'json',
}).then(res => {
if (res?.data?.code === 0) {
window.location.href = res.data?.data;
// window.location.href = res.data?.data;
props.history.push('/thirdParty', { linkUrl: res.data?.data });
}
});
}
......
/* eslint-disable prettier/prettier */
import React, { useEffect } from 'react';
import Iframe from 'react-iframe';
import { connect } from 'react-redux';
import Cookies from 'js-cookie';
import { actionCreators } from '@/containers/App/store';
import _ from 'lodash';
import { useHistory, useAliveController } from '@wisdom-utils/runtime';
import IntegratedSwitch from '@/components/IntegratedSwitch';
import styles from './index.less';
const ThirdParty = props => {
const state = props.location.state || {};
const { clear } = useAliveController();
if (!state.linkUrl) {
return props.history.push(`/industry`);
};
// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
const tk = Cookies.get('token') || props.global.token;
const isLogin = tk !== null && tk !== 'undefined' && tk !== void 0;
let client = props?.global?.client || sessionStorage.getItem('client') || null;
client = client !== 'undefined' && !_.isNull(client) && !_.isUndefined(client) ? client : 'city';
// eslint-disable-next-line no-prototype-builtins
const generateType = props.global && props.global.hasOwnProperty('get') ? props.global.get('generateType') : null;
if (!isLogin) {
props.history.push(`/user/login?client=${client}${generateType || ''}`, { reload: true });
clear();
props.logout();
}
}, [props]);
return (
<div className={styles.outerChainPage}>
<Iframe
url={`${state.linkUrl}`}
width="100%"
height="100%"
id="myId"
frameBorder="0"
className="myClassname"
display="initial"
position="relative"
/>
<IntegratedSwitch />
</div>
);
};
const mapStateToProps = state => ({
global: state.getIn(['global', 'globalConfig']),
});
const mapDispatchToProps = dispatch => ({
logout() {
dispatch(actionCreators.logout());
},
});
export default connect(mapStateToProps, mapDispatchToProps)(ThirdParty);
.outerChainPage {
width: 100%;
height: 100%;
position: relative;
overflow: hidden;
}
\ No newline at end of file
......@@ -17,6 +17,7 @@ import TabIframe from '../pages/system/iframe/TabWidget';
import JumpThirdLink from '../pages/system/iframe/JumpThirdLink';
import IntegratedLogin from '../pages/system/iframe/IntegratedLogin';
import IntegratedLoginPage from '../pages/integratedLogin'; // 集成登录管理
import ThirdParty from '../pages/thirdParty'; // 集成登录自定义跳转
import PrevieView from '../pages/system/previews/preview';
export const dyRoutes = (routes, layout, theme) => {
......@@ -56,6 +57,10 @@ export const dyRoutes = (routes, layout, theme) => {
path: '/industry',
component: BootPage,
},
{
path: '/thirdParty',
component: ThirdParty,
},
{
path: '/cloud/analysis/using',
component: UsingAnalysis,
......
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