perf: improve the logic related to login expiration

This commit is contained in:
vince
2024-07-11 20:11:11 +08:00
parent 8e6c1abf19
commit d62a3da009
43 changed files with 552 additions and 347 deletions

View File

@@ -93,24 +93,9 @@ function setupAccessGuard(router: Router) {
// 生成路由表
// 当前登录用户拥有的角色标识列表
let userRoles: string[] = [];
try {
const userInfo =
accessStore.userInfo || (await accessStore.fetchUserInfo());
userRoles = userInfo.roles ?? [];
} catch (error: any) {
if (error.status === 409) {
accessStore.setShowLoginDialog(true);
} else if (error.status === 401) {
accessStore.reset();
return {
path: LOGIN_PATH,
// 如不需要,直接删除 query
query: { redirect: encodeURIComponent(to.fullPath) },
// 携带当前跳转的页面,登录后重新跳转该页面
replace: true,
};
}
}
const userInfo =
accessStore.userInfo || (await accessStore.fetchUserInfo());
userRoles = userInfo.roles ?? [];
// 生成菜单和路由
const { accessibleMenus, accessibleRoutes } = await generateAccess({

View File

@@ -125,6 +125,48 @@ const routes: RouteRecordRaw[] = [
},
],
},
{
meta: {
icon: 'mdi:feature-highlight',
title: $t('page.demos.features.title'),
},
name: 'Features',
path: '/features',
redirect: '/features/hide-menu-children',
children: [
{
name: 'HideChildrenInMenuParent',
path: 'hide-children-in-menu',
component: () =>
import('#/views/demos/features/hide-menu-children/parent.vue'),
meta: {
hideChildrenInMenu: true,
icon: 'ic:round-menu',
title: 'page.demos.features.hideChildrenInMenu',
},
children: [
{
name: 'HideChildrenInMenuChildren',
path: 'hide-children-in-menu',
component: () =>
import(
'#/views/demos/features/hide-menu-children/children.vue'
),
},
],
},
{
name: 'LoginExpired',
path: 'login-expired',
component: () =>
import('#/views/demos/features/login-expired/index.vue'),
meta: {
icon: 'mdi:encryption-expiration',
title: $t('page.demos.features.loginExpired'),
},
},
],
},
{
meta: {
icon: 'mdi:lightbulb-error-outline',