fix: 增加重新登录意社区

This commit is contained in:
Gsh
2025-07-15 00:54:34 +08:00
parent cab0b61ee0
commit 0d1ee18da0
8 changed files with 133 additions and 30 deletions

View File

@@ -9,7 +9,7 @@ NProgress.configure({ showSpinner: false });
const { getToken, logoutFun ,getRefreshToken} = useAuths();
const whiteList = ["/login", "/auth-redirect", "/bind", "/register"];
router.beforeEach((to, from, next) => {
router.beforeEach(async (to, from, next) => {
NProgress.start();
const hasToken = getToken();
const refreshToken = getRefreshToken();
@@ -18,8 +18,12 @@ router.beforeEach((to, from, next) => {
const isPopup = window.opener && window.opener !== window;
const clientId = urlParams.get('client_id');
const redirectUri = urlParams.get('redirect_uri');
// 检查是否已经处理过SSO登录防重复
if (isPopup && clientId && redirectUri ) {
// ➤ 如果是弹窗+LoginAgain执行登出再跳转回 login 页面
if (clientId === 'LoginAgain' && isPopup && hasToken) {
await logoutFun()
next({ path: '/login', query: { client_id: 'YiXinAi-Login', redirect_uri: redirectUri } });
return;
} else if (isPopup && clientId === 'YiXinAi-Login' && redirectUri) {
if (hasToken) {
// 发送消息给父窗口
const targetOrigin = new URL(decodeURIComponent(redirectUri)).origin;
@@ -30,6 +34,7 @@ router.beforeEach((to, from, next) => {
}, targetOrigin);
// 立即关闭窗口
setTimeout(() => window.close(), 100);
return;
}
}
}
@@ -37,22 +42,22 @@ router.beforeEach((to, from, next) => {
if (hasToken) {
if (to.path === "/login") {
// 已经登陆跳转到首页
next({ path: "/" });
next({path: "/"});
NProgress.done();
} else {
if (useUserStore().roles.length === 0) {
// 判断当前用户是否已拉取完user_info信息
useUserStore()
.getInfo()
.then(() => {
next({ ...to, replace: true });
})
.catch((err) => {
logoutFun.then(() => {
ElMessage.error(err);
next({ path: "/" });
.getInfo()
.then(() => {
next({...to, replace: true});
})
.catch((err) => {
logoutFun.then(() => {
ElMessage.error(err);
next({path: "/"});
});
});
});
} else {
next();
}