mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 05:49:20 +08:00
fix: 修复登录加载菜单失败问题
This commit is contained in:
@@ -98,15 +98,6 @@ export async function refreshTokenApi() {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
*/
|
||||
export async function logoutApi() {
|
||||
return baseRequestClient.post('/auth/logout', {
|
||||
withCredentials: true,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户权限码
|
||||
*/
|
||||
|
||||
@@ -107,13 +107,30 @@ function setupAccessGuard(router: Router) {
|
||||
accessStore.setAccessMenus(accessibleMenus);
|
||||
accessStore.setAccessRoutes(accessibleRoutes);
|
||||
accessStore.setIsAccessChecked(true);
|
||||
const redirectPath = (from.query.redirect ??
|
||||
(to.path === preferences.app.defaultHomePath
|
||||
? userInfo.homePath || preferences.app.defaultHomePath
|
||||
: to.fullPath)) as string;
|
||||
|
||||
let redirectPath = to.fullPath;
|
||||
if (typeof from.query.redirect === 'string' && from.query.redirect) {
|
||||
const decoded = decodeURIComponent(from.query.redirect);
|
||||
if (decoded !== LOGIN_PATH && !decoded.startsWith(`${LOGIN_PATH}?`)) {
|
||||
redirectPath = decoded;
|
||||
} else {
|
||||
redirectPath =
|
||||
userInfo.homePath || preferences.app.defaultHomePath;
|
||||
}
|
||||
} else if (to.path === preferences.app.defaultHomePath) {
|
||||
redirectPath =
|
||||
userInfo.homePath || preferences.app.defaultHomePath;
|
||||
}
|
||||
|
||||
const resolved = router.resolve(redirectPath);
|
||||
// 已在目标页则放行;不要展开 resolve(),以免带上过期的 matched(当时可能命中 404)
|
||||
if (resolved.name && resolved.name === to.name) {
|
||||
return true;
|
||||
}
|
||||
return {
|
||||
...router.resolve(decodeURIComponent(redirectPath)),
|
||||
path: resolved.path,
|
||||
query: resolved.query,
|
||||
hash: resolved.hash,
|
||||
replace: true,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -16,7 +16,6 @@ import {
|
||||
getAccessCodesApi,
|
||||
getUserInfoApi,
|
||||
loginApi,
|
||||
logoutApi,
|
||||
registerApi,
|
||||
} from '#/api';
|
||||
import { $t } from '#/locales';
|
||||
@@ -182,11 +181,6 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
}
|
||||
|
||||
async function logout(redirect: boolean = true) {
|
||||
try {
|
||||
await logoutApi();
|
||||
} catch {
|
||||
// 不做任何处理
|
||||
}
|
||||
resetAllStores();
|
||||
accessStore.setLoginExpired(false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user