feat: route permission(#3378)
This commit is contained in:
parent
65959c8caf
commit
be6dd24b4b
@ -5,7 +5,6 @@
|
|||||||
v-hasPermission="menu.meta?.permission"
|
v-hasPermission="menu.meta?.permission"
|
||||||
v-for="(menu, index) in topMenuList"
|
v-for="(menu, index) in topMenuList"
|
||||||
:key="index"
|
:key="index"
|
||||||
v-show="!menu.hidden"
|
|
||||||
>
|
>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
</div>
|
</div>
|
||||||
@ -13,10 +12,21 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import { getChildRouteListByPathAndName } from '@/router/index'
|
import { getChildRouteListByPathAndName } from '@/router/index'
|
||||||
|
import { hasPermission, set_next_route } from '@/utils/permission/index'
|
||||||
import MenuItem from './MenuItem.vue'
|
import MenuItem from './MenuItem.vue'
|
||||||
|
|
||||||
const topMenuList = computed(() => {
|
const topMenuList = computed(() => {
|
||||||
return getChildRouteListByPathAndName('/', 'home')
|
const menu = getChildRouteListByPathAndName('/', 'home').filter(
|
||||||
|
(item) =>
|
||||||
|
item.meta?.menu &&
|
||||||
|
(item.meta.permission ? hasPermission(item.meta.permission as any, 'OR') : true),
|
||||||
|
)
|
||||||
|
menu.sort(
|
||||||
|
(a, b) =>
|
||||||
|
(a.meta ? (a.meta.order ? (a.meta.order as number) : 1) : 1) -
|
||||||
|
(b.meta ? (b.meta.order ? (b.meta.order as number) : 1) : 1),
|
||||||
|
)
|
||||||
|
return menu
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scope>
|
<style lang="scss" scope>
|
||||||
|
|||||||
@ -48,7 +48,7 @@ router.beforeEach(
|
|||||||
next()
|
next()
|
||||||
} else {
|
} else {
|
||||||
// 如果没有权限则直接取404页面
|
// 如果没有权限则直接取404页面
|
||||||
next('404')
|
next({ path: '/no-permission' })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,8 +1,19 @@
|
|||||||
|
import { PermissionConst, EditionConst, RoleConst } from '@/utils/permission/data'
|
||||||
|
import { get_next_route } from '@/utils/permission'
|
||||||
const applicationRouter = {
|
const applicationRouter = {
|
||||||
path: '/application',
|
path: '/application',
|
||||||
name: 'application',
|
name: 'application',
|
||||||
meta: { title: 'views.application.title' },
|
meta: {
|
||||||
|
title: 'views.application.title',
|
||||||
|
menu: true,
|
||||||
|
permission: [
|
||||||
|
RoleConst.ADMIN,
|
||||||
|
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
|
||||||
|
PermissionConst.APPLICATION_READ.getWorkspacePermissionWorkspaceManageRole,
|
||||||
|
PermissionConst.APPLICATION_READ.getWorkspacePermission,
|
||||||
|
],
|
||||||
|
order: 1,
|
||||||
|
},
|
||||||
redirect: '/application',
|
redirect: '/application',
|
||||||
component: () => import('@/layout/layout-template/SimpleLayout.vue'),
|
component: () => import('@/layout/layout-template/SimpleLayout.vue'),
|
||||||
children: [
|
children: [
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import role from '@/api/system/role'
|
import role from '@/api/system/role'
|
||||||
import { ChatUserResourceEnum } from '@/enums/workspaceChatUser'
|
import { ChatUserResourceEnum } from '@/enums/workspaceChatUser'
|
||||||
import {get_next_route} from "@/utils/permission"
|
import { get_next_route } from '@/utils/permission'
|
||||||
import { PermissionConst, EditionConst, RoleConst } from '@/utils/permission/data'
|
import { PermissionConst, EditionConst, RoleConst } from '@/utils/permission/data'
|
||||||
const DocumentRouter = {
|
const DocumentRouter = {
|
||||||
path: '/knowledge/:id/:folderId',
|
path: '/knowledge/:id/:folderId',
|
||||||
@ -22,13 +22,13 @@ const DocumentRouter = {
|
|||||||
permission: [
|
permission: [
|
||||||
RoleConst.ADMIN,
|
RoleConst.ADMIN,
|
||||||
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
|
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
|
||||||
() => {
|
() => {
|
||||||
const to: any = get_next_route()
|
const to: any = get_next_route()
|
||||||
return PermissionConst.KNOWLEDGE_DOCUMENT_READ.getKnowledgeWorkspaceResourcePermission(
|
return PermissionConst.KNOWLEDGE_DOCUMENT_READ.getKnowledgeWorkspaceResourcePermission(
|
||||||
to ? to.params.id : '',
|
to ? to.params.id : '',
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
PermissionConst.KNOWLEDGE_READ.getWorkspacePermissionWorkspaceManageRole,
|
PermissionConst.KNOWLEDGE_READ.getWorkspacePermissionWorkspaceManageRole,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
component: () => import('@/views/document/index.vue'),
|
component: () => import('@/views/document/index.vue'),
|
||||||
@ -52,7 +52,7 @@ const DocumentRouter = {
|
|||||||
to ? to.params.id : '',
|
to ? to.params.id : '',
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
PermissionConst.KNOWLEDGE_PROBLEM_READ.getWorkspacePermissionWorkspaceManageRole
|
PermissionConst.KNOWLEDGE_PROBLEM_READ.getWorkspacePermissionWorkspaceManageRole,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
component: () => import('@/views/problem/index.vue'),
|
component: () => import('@/views/problem/index.vue'),
|
||||||
@ -89,7 +89,7 @@ const DocumentRouter = {
|
|||||||
to ? to.params.id : '',
|
to ? to.params.id : '',
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
PermissionConst.WORKSPACE_CHAT_USER_READ.getWorkspacePermissionWorkspaceManageRole
|
PermissionConst.WORKSPACE_CHAT_USER_READ.getWorkspacePermissionWorkspaceManageRole,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
component: () => import('@/views/chat-user/index.vue'),
|
component: () => import('@/views/chat-user/index.vue'),
|
||||||
@ -113,9 +113,8 @@ const DocumentRouter = {
|
|||||||
to ? to.params.id : '',
|
to ? to.params.id : '',
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
PermissionConst.KNOWLEDGE_EDIT.getWorkspacePermissionWorkspaceManageRole
|
PermissionConst.KNOWLEDGE_EDIT.getWorkspacePermissionWorkspaceManageRole,
|
||||||
]
|
],
|
||||||
|
|
||||||
},
|
},
|
||||||
component: () => import('@/views/knowledge/KnowledgeSetting.vue'),
|
component: () => import('@/views/knowledge/KnowledgeSetting.vue'),
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,7 +1,18 @@
|
|||||||
|
import { PermissionConst, EditionConst, RoleConst } from '@/utils/permission/data'
|
||||||
const ModelRouter = {
|
const ModelRouter = {
|
||||||
path: '/knowledge',
|
path: '/knowledge',
|
||||||
name: 'knowledge',
|
name: 'knowledge',
|
||||||
meta: { title: 'views.knowledge.title' },
|
meta: {
|
||||||
|
title: 'views.knowledge.title',
|
||||||
|
menu: true,
|
||||||
|
permission: [
|
||||||
|
RoleConst.ADMIN,
|
||||||
|
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
|
||||||
|
PermissionConst.KNOWLEDGE_READ.getWorkspacePermission,
|
||||||
|
PermissionConst.KNOWLEDGE_READ.getWorkspacePermissionWorkspaceManageRole,
|
||||||
|
],
|
||||||
|
order: 2,
|
||||||
|
},
|
||||||
redirect: '/knowledge',
|
redirect: '/knowledge',
|
||||||
component: () => import('@/layout/layout-template/SimpleLayout.vue'),
|
component: () => import('@/layout/layout-template/SimpleLayout.vue'),
|
||||||
children: [
|
children: [
|
||||||
@ -20,12 +31,12 @@ const ModelRouter = {
|
|||||||
component: () => import('@/views/document/UploadDocument.vue'),
|
component: () => import('@/views/document/UploadDocument.vue'),
|
||||||
hidden: true,
|
hidden: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/knowledge/import',
|
path: '/knowledge/import',
|
||||||
name: 'ImportLarkDocument',
|
name: 'ImportLarkDocument',
|
||||||
meta: { activeMenu: '/knowledge' },
|
meta: { activeMenu: '/knowledge' },
|
||||||
component: () => import('@/views/document/ImportLarkDocument.vue'),
|
component: () => import('@/views/document/ImportLarkDocument.vue'),
|
||||||
hidden: true
|
hidden: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,17 +1,31 @@
|
|||||||
|
import { PermissionConst, EditionConst, RoleConst } from '@/utils/permission/data'
|
||||||
const ModelRouter = {
|
const ModelRouter = {
|
||||||
path: '/model',
|
path: '/model',
|
||||||
name: 'model',
|
name: 'model',
|
||||||
meta: { title: 'views.model.title' },
|
meta: {
|
||||||
|
title: 'views.model.title',
|
||||||
|
menu: true,
|
||||||
|
permission: [
|
||||||
|
RoleConst.ADMIN,
|
||||||
|
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
|
||||||
|
PermissionConst.MODEL_READ.getWorkspacePermission,
|
||||||
|
PermissionConst.MODEL_READ.getWorkspacePermissionWorkspaceManageRole,
|
||||||
|
],
|
||||||
|
order: 4,
|
||||||
|
},
|
||||||
redirect: '/model',
|
redirect: '/model',
|
||||||
component: () => import('@/layout/layout-template/SimpleLayout.vue'),
|
component: () => import('@/layout/layout-template/SimpleLayout.vue'),
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
path: '/model',
|
path: '/model',
|
||||||
name: 'model-index',
|
name: 'model-index',
|
||||||
meta: { title: '模型主页', activeMenu: '/model' },
|
meta: {
|
||||||
component: () => import('@/views/model/index.vue')
|
title: '模型主页',
|
||||||
}
|
activeMenu: '/model',
|
||||||
]
|
},
|
||||||
|
component: () => import('@/views/model/index.vue'),
|
||||||
|
},
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ModelRouter
|
export default ModelRouter
|
||||||
|
|||||||
@ -1,7 +1,18 @@
|
|||||||
|
import { PermissionConst, EditionConst, RoleConst } from '@/utils/permission/data'
|
||||||
const ModelRouter = {
|
const ModelRouter = {
|
||||||
path: '/tool',
|
path: '/tool',
|
||||||
name: 'tool',
|
name: 'tool',
|
||||||
meta: { title: 'views.tool.title' },
|
meta: {
|
||||||
|
title: 'views.tool.title',
|
||||||
|
menu: true,
|
||||||
|
permission: [
|
||||||
|
RoleConst.ADMIN,
|
||||||
|
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
|
||||||
|
PermissionConst.TOOL_READ.getWorkspacePermission,
|
||||||
|
PermissionConst.TOOL_READ.getWorkspacePermissionWorkspaceManageRole,
|
||||||
|
],
|
||||||
|
order: 3,
|
||||||
|
},
|
||||||
redirect: '/tool',
|
redirect: '/tool',
|
||||||
component: () => import('@/layout/layout-template/SimpleLayout.vue'),
|
component: () => import('@/layout/layout-template/SimpleLayout.vue'),
|
||||||
children: [
|
children: [
|
||||||
@ -9,9 +20,9 @@ const ModelRouter = {
|
|||||||
path: '/tool',
|
path: '/tool',
|
||||||
name: 'tool-index',
|
name: 'tool-index',
|
||||||
meta: { title: '工具主页', activeMenu: '/tool' },
|
meta: { title: '工具主页', activeMenu: '/tool' },
|
||||||
component: () => import('@/views/tool/index.vue')
|
component: () => import('@/views/tool/index.vue'),
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ModelRouter
|
export default ModelRouter
|
||||||
|
|||||||
@ -1,13 +1,41 @@
|
|||||||
import type { RouteRecordRaw } from 'vue-router'
|
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'
|
||||||
const rolesRoutes: RouteRecordRaw[] = [...Object.keys(modules).map((key) => modules[key].default)]
|
const rolesRoutes: RouteRecordRaw[] = [...Object.keys(modules).map((key) => modules[key].default)]
|
||||||
|
|
||||||
export const routes: Array<RouteRecordRaw> = [
|
export const routes: Array<RouteRecordRaw> = [
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
name: 'home',
|
name: 'home',
|
||||||
redirect: '/application',
|
redirect: (to: any) => {
|
||||||
children: [...rolesRoutes],
|
const route = rolesRoutes.find((route: any) => {
|
||||||
|
return (
|
||||||
|
route.meta?.menu &&
|
||||||
|
(route.meta.permission ? hasPermission(route.meta.permission as any, 'OR') : true)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
if (route?.name) {
|
||||||
|
return { name: route?.name }
|
||||||
|
}
|
||||||
|
return { name: 'noPermission' }
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
...rolesRoutes,
|
||||||
|
{
|
||||||
|
path: '/no-permission',
|
||||||
|
name: 'noPermission',
|
||||||
|
redirect: '/no-permission',
|
||||||
|
meta: {},
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: '/no-permission',
|
||||||
|
name: 'noPermissionD',
|
||||||
|
component: () => import('@/views/no-permission/index.vue'),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
component: () => import('@/layout/layout-template/SimpleLayout.vue'),
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
// 高级编排
|
// 高级编排
|
||||||
|
|||||||
5
ui/src/views/no-permission/index.vue
Normal file
5
ui/src/views/no-permission/index.vue
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div>没有权限访问</div>
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts"></script>
|
||||||
|
<style lang="scss" scoped></style>
|
||||||
Loading…
Reference in New Issue
Block a user