|
|
@@ -242,7 +242,37 @@ router.routes.forEach((route: any) => {
|
|
|
const location = useLocation();
|
|
|
const path = location.pathname;
|
|
|
|
|
|
- if (LocalStorage.getToken()) {// 已登录
|
|
|
+ const originUrl = window.location.origin;
|
|
|
+ const fullUrl = window.location.href;
|
|
|
+ const urlParams = new URLSearchParams(new URL(fullUrl).search);
|
|
|
+ const code = urlParams.get('code');
|
|
|
+ const state = urlParams.get('state');
|
|
|
+ const userInfo = localStorage.getItem('userInfo');
|
|
|
+ const token = urlParams.get('token');
|
|
|
+ if (token) {// 通过token登陆
|
|
|
+ const checkToken = async (token: string) => {
|
|
|
+ try {
|
|
|
+ const res = await apis.checkToken(token);
|
|
|
+ if(res.data.status) {
|
|
|
+ localStorage.setItem('token', token);
|
|
|
+ LocalStorage.setPermissions(res.permissions);
|
|
|
+ LocalStorage.setRoles(res.roles);
|
|
|
+ LocalStorage.setUserInfo({
|
|
|
+ id: res.user.userId,
|
|
|
+ name: res.user.nickName,
|
|
|
+ });
|
|
|
+ window.location.replace(originUrl + path);
|
|
|
+ }
|
|
|
+ } catch (error: any) {
|
|
|
+ Modal.error({
|
|
|
+ title: 'Error',
|
|
|
+ content: 'token验证失败',
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return <Navigate to='/login' replace={true} />
|
|
|
+ }
|
|
|
+ checkToken(token);
|
|
|
+ } else if (LocalStorage.getToken()) {// 已登录
|
|
|
return <>{component}</>
|
|
|
} else {// 未登录
|
|
|
|
|
|
@@ -260,13 +290,6 @@ router.routes.forEach((route: any) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- const originUrl = window.location.origin;
|
|
|
- const fullUrl = window.location.href;
|
|
|
- const urlParams = new URLSearchParams(new URL(fullUrl).search);
|
|
|
- const code = urlParams.get('code');
|
|
|
- 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);
|