fix: 接入用户与权限后端接口
This commit is contained in:
@@ -10,6 +10,7 @@ import UserPermissionsView from '@/views/management/users/index.vue'
|
||||
import ConsentTasksView from '@/views/workbench/signing/index.vue'
|
||||
import DashboardView from '@/views/workbench/home/index.vue'
|
||||
import { useLoginStore } from '@/stores/login'
|
||||
import { readStoredAuthSession } from '@/utils/auth-storage'
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
@@ -65,7 +66,11 @@ const router = createRouter({
|
||||
path: 'users',
|
||||
name: 'management-users',
|
||||
component: UserPermissionsView,
|
||||
meta: { title: '用户与权限', group: '管理' },
|
||||
meta: {
|
||||
title: '用户与权限',
|
||||
group: '管理',
|
||||
permission: 'system:user:query',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'document-permissions',
|
||||
@@ -96,6 +101,11 @@ router.beforeEach((to) => {
|
||||
const loginStore = useLoginStore()
|
||||
|
||||
if (to.name === 'login' && loginStore.isLoggedIn) {
|
||||
if (!readStoredAuthSession()) {
|
||||
loginStore.clearSession()
|
||||
return true
|
||||
}
|
||||
|
||||
return { name: 'workbench-home' }
|
||||
}
|
||||
|
||||
@@ -106,6 +116,24 @@ router.beforeEach((to) => {
|
||||
}
|
||||
}
|
||||
|
||||
if (to.meta.requiresAuth) {
|
||||
return loginStore
|
||||
.ensureCurrentUser()
|
||||
.then(() => {
|
||||
const requiredPermission = to.meta.permission as string | string[] | undefined
|
||||
|
||||
if (requiredPermission && !loginStore.hasPermission(requiredPermission)) {
|
||||
return { name: 'workbench-home' }
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
.catch(() => ({
|
||||
name: 'login',
|
||||
query: { redirect: to.fullPath },
|
||||
}))
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user