Commit ad87f58c authored by ZhangRunSong's avatar ZhangRunSong
parents b27a172c a07d52ae
......@@ -169,9 +169,10 @@ function logout() {
})
.then(() => {
userStore.logOut().then(() => {
// 重定向到奇瑞统一身份认证平台的地址
const finalRedirectUrl = 'https://iamuat.mychery.com:5443/idp/oauth2/authorize?client_id=FACTS&redirect_uri=http://106.3.99.64:20073/login&response_type=code';
window.location.href = finalRedirectUrl;
// // 重定向到奇瑞统一身份认证平台的地址
// const finalRedirectUrl = 'https://iamuat.mychery.com:5443/idp/oauth2/authorize?client_id=FACTS&redirect_uri=http://106.3.99.64:20073/login&response_type=code';
// window.location.href = finalRedirectUrl;
location.href = '/index'
})
})
.catch(() => {})
......
......@@ -8,7 +8,6 @@ import { isRelogin } from '@/utils/request'
import useUserStore from '@/store/modules/user'
import useSettingsStore from '@/store/modules/settings'
import usePermissionStore from '@/store/modules/permission'
import axios from 'axios';
NProgress.configure({ showSpinner: false })
......@@ -18,11 +17,6 @@ const isWhiteList = (path) => {
return whiteList.some((pattern) => isPathMatch(pattern, path))
}
// 统一登录页面路由
const unifiedLoginRoute = '/login';
// 后端登录接口
const loginBySSOApi = '/auth/loginBySSO';
router.beforeEach((to, from, next) => {
NProgress.start()
if (getToken()) {
......@@ -69,37 +63,9 @@ router.beforeEach((to, from, next) => {
// 没有token
if (isWhiteList(to.path)) {
// 在免登录白名单,直接进入
if (to.path === unifiedLoginRoute) {
// 从URL中截取code参数
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get('code');
if (code) {
// 请求后端/auth/loginBySSO接口
axios.post(loginBySSOApi, { ticket: code })
.then(response => {
if (response.data.success) {
// 登录成功,跳转到首页
next({ path: '/' });
} else {
ElMessage.error('登录失败,请重试');
next();
}
})
.catch(error => {
ElMessage.error('登录请求出错,请重试');
next();
});
} else {
next();
}
} else {
next()
}
} else {
// 跳转到IAM登录页面
const redirectUri = `http://106.3.99.64:20073${unifiedLoginRoute}`;
const iamLoginUrl = `https://iamuat.mychery.com:5443/idp/oauth2/authorize?client_id=FACTS&redirect_uri=${encodeURIComponent(redirectUri)}&response_type=code`;
window.location.href = iamLoginUrl;
next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
NProgress.done()
}
}
......
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