feat: route permission (#3379)
This commit is contained in:
parent
be6dd24b4b
commit
bba7a60789
@ -47,6 +47,13 @@ router.beforeEach(
|
|||||||
if (to.meta.permission ? hasPermission(to.meta.permission as any, 'OR') : true) {
|
if (to.meta.permission ? hasPermission(to.meta.permission as any, 'OR') : true) {
|
||||||
next()
|
next()
|
||||||
} else {
|
} else {
|
||||||
|
console.log('s')
|
||||||
|
if (to.meta.get_permission_route) {
|
||||||
|
const t = to.meta.get_permission_route()
|
||||||
|
console.log(t)
|
||||||
|
next(t)
|
||||||
|
return
|
||||||
|
}
|
||||||
// 如果没有权限则直接取404页面
|
// 如果没有权限则直接取404页面
|
||||||
next({ path: '/no-permission' })
|
next({ path: '/no-permission' })
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,12 +2,7 @@ import type { RouteRecordRaw } from 'vue-router'
|
|||||||
const modules: any = import.meta.glob('./modules/*.ts', { eager: true })
|
const modules: any = import.meta.glob('./modules/*.ts', { eager: true })
|
||||||
import { hasPermission, set_next_route } from '@/utils/permission/index'
|
import { hasPermission, set_next_route } from '@/utils/permission/index'
|
||||||
const rolesRoutes: RouteRecordRaw[] = [...Object.keys(modules).map((key) => modules[key].default)]
|
const rolesRoutes: RouteRecordRaw[] = [...Object.keys(modules).map((key) => modules[key].default)]
|
||||||
|
const get_workspace_permission_route = () => {
|
||||||
export const routes: Array<RouteRecordRaw> = [
|
|
||||||
{
|
|
||||||
path: '/',
|
|
||||||
name: 'home',
|
|
||||||
redirect: (to: any) => {
|
|
||||||
const route = rolesRoutes.find((route: any) => {
|
const route = rolesRoutes.find((route: any) => {
|
||||||
return (
|
return (
|
||||||
route.meta?.menu &&
|
route.meta?.menu &&
|
||||||
@ -18,9 +13,20 @@ export const routes: Array<RouteRecordRaw> = [
|
|||||||
return { name: route?.name }
|
return { name: route?.name }
|
||||||
}
|
}
|
||||||
return { name: 'noPermission' }
|
return { name: 'noPermission' }
|
||||||
},
|
}
|
||||||
|
|
||||||
|
export const routes: Array<RouteRecordRaw> = [
|
||||||
|
{
|
||||||
|
path: '/',
|
||||||
|
name: 'home',
|
||||||
|
redirect: '/application',
|
||||||
children: [
|
children: [
|
||||||
...rolesRoutes,
|
...rolesRoutes.map((r) => {
|
||||||
|
if (r.meta) {
|
||||||
|
r.meta.get_permission_route = get_workspace_permission_route
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}),
|
||||||
{
|
{
|
||||||
path: '/no-permission',
|
path: '/no-permission',
|
||||||
name: 'noPermission',
|
name: 'noPermission',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user