Commit 54f969e0 authored by 周宏民's avatar 周宏民

pref: 集成登录支持 站内跳转到指定功能

parent a1fc4dec
Pipeline #93673 passed with stages
......@@ -15,6 +15,7 @@ import { defaultApp } from '@/micro';
import { useHistory } from '@wisdom-utils/runtime';
import LoadPage from '@/components/LoadPage';
import { getUserInfo, getWebSiteConfig } from '@/api/service/base';
import { goToPath } from '@/utils/utils';
import styles from './index.less';
const IntegratedSwitch = props => {
......@@ -26,6 +27,7 @@ const IntegratedSwitch = props => {
const [dataList, setDataList] = useState([]);
const [client, setClient] = useState('');
const clientRef = useRef(props.global.client);
const clientInfo = useRef({}); // 跳转子站信息
const [jumpLoading, setJumpLoading] = useState(false);
const [progressValue, setProgressValue] = useState(0);
......@@ -139,7 +141,13 @@ const IntegratedSwitch = props => {
}
}
} else if (item.subType === '内链') {
const cli = item.appKey;
const cli = item.client;
if (item.client === props.global.client) {
if (item.url) {
goToPath(clientInfo.current?.url);
return;
}
}
const token = props.global?.token || Cookies.get('token');
getWebSiteConfig({
identity: token,
......@@ -245,6 +253,9 @@ const IntegratedSwitch = props => {
<li
className={styles.switchPageLi}
onClick={() => {
const integrationClient = localStorage.getItem('integrationClient');
sessionStorage.setItem('client', integrationClient);
localStorage.removeItem('integrationClient');
history.push('/industry');
}}
>
......@@ -254,9 +265,7 @@ const IntegratedSwitch = props => {
</Tooltip>
</div>
</li>
{dataList.map(item => {
if (item.subType === '内链' && item.appKey === props?.global?.client) return null;
return (
{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}>
......@@ -267,8 +276,7 @@ const IntegratedSwitch = props => {
</Tooltip>
</div>
</li>
);
})}
))}
</ul>
</div>
) : null;
......
......@@ -8,7 +8,7 @@ import { appService } from '@/api';
import { connect } from 'react-redux';
import { actionCreators } from '@/containers/App/store';
import axios from 'axios';
import { getImageUrl } from '@/utils/utils';
import { getImageUrl, goToPath } from '@/utils/utils';
import { getUserInfo, getWebSiteConfig } from '@/api/service/base';
import { FullscreenExitOutlined, FullscreenOutlined } from '@ant-design/icons';
......@@ -41,6 +41,7 @@ const IntegrationNew = props => {
const timer3 = useRef(null);
const timer4 = useRef(null);
const clientRef = useRef(props.global.client);
const clientInfo = useRef({}); // 跳转子站信息
const progressRef2 = useRef(0);
const loadingTime = integratedConfig?.loadingTime || 5;
const [loginAction, setAction] = useState(() => new LoginAction(props));
......@@ -192,6 +193,7 @@ const IntegrationNew = props => {
});
return;
}
clientInfo.current = item;
if (window.qiankunIsCache) {
store.set('event:dropCache');
}
......@@ -343,9 +345,13 @@ const IntegrationNew = props => {
setJumpLoading(false);
jumpProgressEnd();
window.jumpLoadingProgress = 0;
if (clientInfo.current?.url && clientInfo.current.subType === '内链') {
goToPath(clientInfo.current?.url);
} else {
props.history.push(`/?client=${clientRef.current || props.global.client}`);
props.updateCurrentIndex && props.updateCurrentIndex(0);
defaultApp();
}
};
const handleError = () => {
......
import Cookies from 'js-cookie';
import pathRegexp from 'path-to-regexp';
import { parse } from 'querystring';
import { cloneDeep } from 'lodash';
import pkg from '../../package.json';
/* eslint no-useless-escape:0 import/prefer-default-export:0 */
const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;
......@@ -107,3 +109,51 @@ export const getImageUrl = path => {
return `/PandaOMS/OMS/FileCenter/DownLoadFiles?module=图库&filePath=${encodeURIComponent(path)}`;
};
/**
* 跳转到指定页面
* @param {*} path 功能地址
*/
export const goToPath = (path, data, widgetId, mode) => {
const routes = window.globalConfig?.allWidgets || [];
let info = null;
const target = path.substr(0, 1) === '/' ? path.slice(1) : path;
function urlSearch(arr) {
arr.forEach(a => {
if (a.url) {
if (a.url.indexOf(target) > -1 && (!widgetId || a.url.indexOf(widgetId) > -1)) {
// 跳转到指定板块功能
if (mode) {
if (a.widgetId && a.widgetId.split('_').includes(mode)) {
info = cloneDeep(a);
}
} else {
info = cloneDeep(a);
}
}
}
if (a.widgets) {
urlSearch(a.widgets);
}
});
}
urlSearch(routes);
if (!info) return info;
info.url = info.url.substr(0, 1) === '/' ? info.url : `/${info.url}`;
let url = `/civbase/${info.product}${info.url}`;
const arr = url.split('|');
let params = {};
url = arr[0];
if (arr[1]) {
url += encodeURI(`|${arr[1]}`);
const arrObj = arr[1].split('&');
arrObj.forEach(item => {
const temp = item.split('=');
params[temp[0]] = temp[1];
});
}
params = { ...params, ...data };
params.widget = widgetId || params.widget;
console.log(params, url);
window.history.pushState(params, '', url);
};
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