|
|
@@ -342,12 +342,14 @@ export function Home() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- const frameLogin = async (data: { clientId: string,
|
|
|
+ const frameLogin = async (data: {
|
|
|
+ clientId: string,
|
|
|
workspaceId: string,
|
|
|
workspaceName: string,
|
|
|
userName: string,
|
|
|
timestamp: string,
|
|
|
- signature: string }, url: string,fullUrl:string) => {
|
|
|
+ signature: string
|
|
|
+ }, url: string, fullUrl: string) => {
|
|
|
try {
|
|
|
const res = await api.post('frame_login', data);
|
|
|
localStorage.setItem('userInfo', JSON.stringify(res.data));
|
|
|
@@ -359,13 +361,13 @@ export function Home() {
|
|
|
});
|
|
|
//停留5秒
|
|
|
setTimeout(() => {
|
|
|
- toUninLogin(url,fullUrl);
|
|
|
+ toUninLogin(url, fullUrl);
|
|
|
}, 5000);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- const toUninLogin = async (originUrl:string, fullUrl:string) => {
|
|
|
+ const toUninLogin = async (originUrl: string, fullUrl: string) => {
|
|
|
// return
|
|
|
//测试环境
|
|
|
//const loginUrl = 'https://esctest.sribs.com.cn/esc-sso/oauth2.0/authorize?client_id=e97f94cf93761f4d69e8&response_type=code';
|
|
|
@@ -393,6 +395,25 @@ export function Home() {
|
|
|
// if (loginRes) {
|
|
|
// return localStorage.setItem('userInfo', JSON.stringify(loginRes));
|
|
|
// }
|
|
|
+ // 如果有token就先去存数据
|
|
|
+ const hash = window.location.hash;
|
|
|
+ const queryString = hash.includes("?") ? hash.split("?")[1] : "";
|
|
|
+ const urlHachParams = new URLSearchParams(queryString);
|
|
|
+ const token = urlHachParams.get('token');
|
|
|
+ const nickName = urlHachParams.get('nickName');
|
|
|
+ const userId = urlHachParams.get('userId');
|
|
|
+ if(token) {
|
|
|
+ localStorage.setItem('userInfo', JSON.stringify({ token, nickName, userId }));
|
|
|
+ // 清除url中的token参数
|
|
|
+ if (window.history.replaceState) {
|
|
|
+ const cleanUrl = window.location.href.split("#")[0];
|
|
|
+ // http://localhost:4000/#/knowledgeChat?showMenu=true&chatMode=LOCAL&appId=2965620717148049408&userId=8&nickName=test&token=eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjQ3M2QzOWI0LTVhOGYtNGYxZS1iOGY
|
|
|
+ window.history.replaceState({}, document.title, `${cleanUrl}#/knowledgeChat?showMenu=true&chatMode=LOCAL&&appId=${urlHachParams.get('appId')}`);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
const originUrl = window.location.origin;
|
|
|
const fullUrl = window.location.href;
|
|
|
const urlParams = new URLSearchParams(new URL(fullUrl).search);
|
|
|
@@ -400,47 +421,48 @@ export function Home() {
|
|
|
const state = urlParams.get('state');
|
|
|
const userInfo = localStorage.getItem('userInfo');
|
|
|
|
|
|
+
|
|
|
if (fullUrl.includes(originUrl + '/?code') && code && state) {// 通过code登陆
|
|
|
if (!userInfo) {
|
|
|
jkLogin({ code: code, redirectUrl: encodeURIComponent(originUrl) }, state);
|
|
|
}
|
|
|
} else {
|
|
|
|
|
|
- //判断是否是frame方式联登/frame
|
|
|
- if (fullUrl.includes(originUrl + '/?frame=Y')) {
|
|
|
-
|
|
|
- const workspaceId = urlParams.get('workspace_id');
|
|
|
- const workspaceName = urlParams.get('workspace_name');
|
|
|
- const username = urlParams.get('username');
|
|
|
- const clientId = urlParams.get('client_id');
|
|
|
- const timestamp = urlParams.get('timestamp');
|
|
|
- const signature = urlParams.get('signature');
|
|
|
- if (!clientId || !workspaceId || !workspaceName || !username || !timestamp || !signature) {
|
|
|
- // 处理缺失参数的情况
|
|
|
- Modal.error({
|
|
|
- title: '参数错误',
|
|
|
- content: '缺少必要的参数',
|
|
|
- });
|
|
|
- //停留5秒
|
|
|
- setTimeout(() => {
|
|
|
- toUninLogin(originUrl,fullUrl);
|
|
|
- }, 5000);
|
|
|
- return;
|
|
|
- }
|
|
|
- frameLogin({
|
|
|
- clientId: clientId,
|
|
|
- workspaceId: workspaceId,
|
|
|
- workspaceName: workspaceName,
|
|
|
- userName: username,
|
|
|
- timestamp: timestamp,
|
|
|
- signature: signature
|
|
|
- },originUrl,fullUrl);
|
|
|
-
|
|
|
- } else {
|
|
|
- if (!userInfo) {
|
|
|
+ //判断是否是frame方式联登/frame
|
|
|
+ if (fullUrl.includes(originUrl + '/?frame=Y')) {
|
|
|
+
|
|
|
+ const workspaceId = urlParams.get('workspace_id');
|
|
|
+ const workspaceName = urlParams.get('workspace_name');
|
|
|
+ const username = urlParams.get('username');
|
|
|
+ const clientId = urlParams.get('client_id');
|
|
|
+ const timestamp = urlParams.get('timestamp');
|
|
|
+ const signature = urlParams.get('signature');
|
|
|
+ if (!clientId || !workspaceId || !workspaceName || !username || !timestamp || !signature) {
|
|
|
+ // 处理缺失参数的情况
|
|
|
+ Modal.error({
|
|
|
+ title: '参数错误',
|
|
|
+ content: '缺少必要的参数',
|
|
|
+ });
|
|
|
+ //停留5秒
|
|
|
+ setTimeout(() => {
|
|
|
toUninLogin(originUrl, fullUrl);
|
|
|
- }
|
|
|
+ }, 5000);
|
|
|
+ return;
|
|
|
}
|
|
|
+ frameLogin({
|
|
|
+ clientId: clientId,
|
|
|
+ workspaceId: workspaceId,
|
|
|
+ workspaceName: workspaceName,
|
|
|
+ userName: username,
|
|
|
+ timestamp: timestamp,
|
|
|
+ signature: signature
|
|
|
+ }, originUrl, fullUrl);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ if (!userInfo) {
|
|
|
+ toUninLogin(originUrl, fullUrl);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}, []);
|
|
|
|