Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions ui/src/layout/layout-header/top-menu/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,28 @@
v-hasPermission="menu.meta?.permission"
v-for="(menu, index) in topMenuList"
:key="index"
v-show="!menu.hidden"
>
</MenuItem>
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue'
import { getChildRouteListByPathAndName } from '@/router/index'
import { hasPermission, set_next_route } from '@/utils/permission/index'
import MenuItem from './MenuItem.vue'

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>
<style lang="scss" scope>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ router.beforeEach(
next()
} else {
// 如果没有权限则直接取404页面
next('404')
next({ path: '/no-permission' })
}
},
)
Expand Down
15 changes: 13 additions & 2 deletions ui/src/router/modules/application.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@

import { PermissionConst, EditionConst, RoleConst } from '@/utils/permission/data'
import { get_next_route } from '@/utils/permission'
const applicationRouter = {
path: '/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',
component: () => import('@/layout/layout-template/SimpleLayout.vue'),
children: [
Expand Down
15 changes: 7 additions & 8 deletions ui/src/router/modules/document.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import role from '@/api/system/role'
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'
const DocumentRouter = {
path: '/knowledge/:id/:folderId',
Expand All @@ -22,13 +22,13 @@ const DocumentRouter = {
permission: [
RoleConst.ADMIN,
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
() => {
() => {
const to: any = get_next_route()
return PermissionConst.KNOWLEDGE_DOCUMENT_READ.getKnowledgeWorkspaceResourcePermission(
to ? to.params.id : '',
)
},
PermissionConst.KNOWLEDGE_READ.getWorkspacePermissionWorkspaceManageRole,
PermissionConst.KNOWLEDGE_READ.getWorkspacePermissionWorkspaceManageRole,
],
},
component: () => import('@/views/document/index.vue'),
Expand All @@ -52,7 +52,7 @@ const DocumentRouter = {
to ? to.params.id : '',
)
},
PermissionConst.KNOWLEDGE_PROBLEM_READ.getWorkspacePermissionWorkspaceManageRole
PermissionConst.KNOWLEDGE_PROBLEM_READ.getWorkspacePermissionWorkspaceManageRole,
],
},
component: () => import('@/views/problem/index.vue'),
Expand Down Expand Up @@ -89,7 +89,7 @@ const DocumentRouter = {
to ? to.params.id : '',
)
},
PermissionConst.WORKSPACE_CHAT_USER_READ.getWorkspacePermissionWorkspaceManageRole
PermissionConst.WORKSPACE_CHAT_USER_READ.getWorkspacePermissionWorkspaceManageRole,
],
},
component: () => import('@/views/chat-user/index.vue'),
Expand All @@ -113,9 +113,8 @@ const DocumentRouter = {
to ? to.params.id : '',
)
},
PermissionConst.KNOWLEDGE_EDIT.getWorkspacePermissionWorkspaceManageRole
]

PermissionConst.KNOWLEDGE_EDIT.getWorkspacePermissionWorkspaceManageRole,
],
},
component: () => import('@/views/knowledge/KnowledgeSetting.vue'),
},
Expand Down
17 changes: 14 additions & 3 deletions ui/src/router/modules/knowledge.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { PermissionConst, EditionConst, RoleConst } from '@/utils/permission/data'
const ModelRouter = {
path: '/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',
component: () => import('@/layout/layout-template/SimpleLayout.vue'),
children: [
Expand All @@ -20,12 +31,12 @@ const ModelRouter = {
component: () => import('@/views/document/UploadDocument.vue'),
hidden: true,
},
{
{
path: '/knowledge/import',
name: 'ImportLarkDocument',
meta: { activeMenu: '/knowledge' },
component: () => import('@/views/document/ImportLarkDocument.vue'),
hidden: true
hidden: true,
},
],
}
Expand Down
24 changes: 19 additions & 5 deletions ui/src/router/modules/model.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
import { PermissionConst, EditionConst, RoleConst } from '@/utils/permission/data'
const ModelRouter = {
path: '/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',
component: () => import('@/layout/layout-template/SimpleLayout.vue'),
children: [
{
path: '/model',
name: 'model-index',
meta: { title: '模型主页', activeMenu: '/model' },
component: () => import('@/views/model/index.vue')
}
]
meta: {
title: '模型主页',
activeMenu: '/model',
},
component: () => import('@/views/model/index.vue'),
},
],
}

export default ModelRouter
19 changes: 15 additions & 4 deletions ui/src/router/modules/tool.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
import { PermissionConst, EditionConst, RoleConst } from '@/utils/permission/data'
const ModelRouter = {
path: '/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',
component: () => import('@/layout/layout-template/SimpleLayout.vue'),
children: [
{
path: '/tool',
name: 'tool-index',
meta: { title: '工具主页', activeMenu: '/tool' },
component: () => import('@/views/tool/index.vue')
}
]
component: () => import('@/views/tool/index.vue'),
},
],
}

export default ModelRouter
32 changes: 30 additions & 2 deletions ui/src/router/routes.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,41 @@
import type { RouteRecordRaw } from 'vue-router'
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)]

export const routes: Array<RouteRecordRaw> = [
{
path: '/',
name: 'home',
redirect: '/application',
children: [...rolesRoutes],
redirect: (to: any) => {
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'),
},
],
},

// 高级编排
Expand Down
5 changes: 5 additions & 0 deletions ui/src/views/no-permission/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div>没有权限访问</div>
</template>
<script setup lang="ts"></script>
<style lang="scss" scoped></style>
Loading