From e0dcc4b29d8f624ee6f988192908fe51b80d0781 Mon Sep 17 00:00:00 2001 From: teukkk Date: Tue, 10 Jun 2025 19:25:17 +0800 Subject: [PATCH] feat: role --- ui/src/api/type/role.ts | 43 +++ ui/src/api/user/role.ts | 67 +++++ ui/src/enums/system.ts | 6 + ui/src/locales/lang/en-US/common.ts | 2 + ui/src/locales/lang/en-US/views/index.ts | 4 +- ui/src/locales/lang/en-US/views/role.ts | 22 ++ ui/src/locales/lang/zh-CN/common.ts | 2 + ui/src/locales/lang/zh-CN/views/index.ts | 2 + ui/src/locales/lang/zh-CN/views/role.ts | 22 ++ ui/src/locales/lang/zh-Hant/common.ts | 2 + ui/src/locales/lang/zh-Hant/views/index.ts | 4 +- ui/src/locales/lang/zh-Hant/views/role.ts | 22 ++ ui/src/router/modules/system.ts | 13 + ui/src/styles/app.scss | 3 + .../component/CreateOrUpdateRoleDialog.vue | 82 ++++++ ui/src/views/role/component/Member.vue | 5 + .../component/PermissionConfiguration.vue | 173 ++++++++++++ ui/src/views/role/index.ts | 8 + ui/src/views/role/index.vue | 266 ++++++++++++++++++ 19 files changed, 746 insertions(+), 2 deletions(-) create mode 100644 ui/src/api/type/role.ts create mode 100644 ui/src/api/user/role.ts create mode 100644 ui/src/locales/lang/en-US/views/role.ts create mode 100644 ui/src/locales/lang/zh-CN/views/role.ts create mode 100644 ui/src/locales/lang/zh-Hant/views/role.ts create mode 100644 ui/src/views/role/component/CreateOrUpdateRoleDialog.vue create mode 100644 ui/src/views/role/component/Member.vue create mode 100644 ui/src/views/role/component/PermissionConfiguration.vue create mode 100644 ui/src/views/role/index.ts create mode 100644 ui/src/views/role/index.vue diff --git a/ui/src/api/type/role.ts b/ui/src/api/type/role.ts new file mode 100644 index 00000000..bc309e0b --- /dev/null +++ b/ui/src/api/type/role.ts @@ -0,0 +1,43 @@ +import { RoleTypeEnum } from '@/enums/system' + +interface RoleItem { + id: string, + role_name: string, + type: RoleTypeEnum, + create_user: string, + internal: boolean, +} + +interface ChildrenPermissionItem { + id: string + name: string + enable: boolean +} + +interface RolePermissionItem { + id: string, + name: string, + children: { + id: string, + name: string, + permission: ChildrenPermissionItem[], + enable: boolean, + }[] +} + +interface RoleTableDataItem { + module: string + name: string + permission: ChildrenPermissionItem[] + enable: boolean + perChecked: string[] + indeterminate: boolean +} + +interface CreateOrUpdateParams { + role_id?: string, + role_name: string, + role_type?: RoleTypeEnum, +} + +export type { RoleItem, RolePermissionItem, RoleTableDataItem, CreateOrUpdateParams, ChildrenPermissionItem } \ No newline at end of file diff --git a/ui/src/api/user/role.ts b/ui/src/api/user/role.ts new file mode 100644 index 00000000..e617b75c --- /dev/null +++ b/ui/src/api/user/role.ts @@ -0,0 +1,67 @@ +import { get, post, del } from '@/request/index' +import type { Ref } from 'vue' +import { Result } from '@/request/Result' +import type { RoleItem, RolePermissionItem, CreateOrUpdateParams } from '@/api/type/role' +import { RoleTypeEnum } from '@/enums/system' + +const prefix = '/system/role' +/** + * 获取角色列表 + */ +const getRoleList: (loading?: Ref) => Promise> = (loading) => { + return get(`${prefix}`, undefined, loading) +} + +/** + * 根据类型获取角色权限模版列表 + */ +const getRoleTemplate: (role_type: RoleTypeEnum, loading?: Ref) => Promise> = (role_type, loading) => { + return get(`${prefix}/template/${role_type}`, undefined, loading) +} + +/** + * 获取角色权限选中 + */ +const getRolePermissionList: (role_id: string, loading?: Ref) => Promise> = (role_id, loading) => { + return get(`${prefix}/${role_id}/permission`, undefined, loading) +} + +/** + * 新建或更新角色 + */ +const CreateOrUpdateRole: ( + data: CreateOrUpdateParams, + loading?: Ref, +) => Promise> = (data, loading) => { + return post(`${prefix}`, data, undefined, loading) +} + +/** + * 删除角色 + */ +const deleteRole: (role_id: string, loading?: Ref) => Promise> = ( + role_id, + loading, +) => { + return del(`${prefix}/${role_id}`, undefined, {}, loading) +} + +/** + * 保存角色权限 + */ +const saveRolePermission: ( + role_id: string, + data: { id: string, enable: boolean }[], + loading?: Ref, +) => Promise> = (role_id, data, loading) => { + return post(`${prefix}/${role_id}/permission`, data, undefined, loading) +} + +export default { + getRoleList, + getRolePermissionList, + getRoleTemplate, + CreateOrUpdateRole, + deleteRole, + saveRolePermission +} \ No newline at end of file diff --git a/ui/src/enums/system.ts b/ui/src/enums/system.ts index 54a1a5ab..16d4221a 100644 --- a/ui/src/enums/system.ts +++ b/ui/src/enums/system.ts @@ -5,3 +5,9 @@ export enum AuthorizationEnum { KNOWLEDGE = 'KNOWLEDGE', APPLICATION = 'APPLICATION', } + +export enum RoleTypeEnum { + ADMIN = 'ADMIN', + USER = 'USER', + WORKSPACE_MANAGE = 'WORKSPACE_MANAGE', +} \ No newline at end of file diff --git a/ui/src/locales/lang/en-US/common.ts b/ui/src/locales/lang/en-US/common.ts index afabb61f..f7358ddd 100644 --- a/ui/src/locales/lang/en-US/common.ts +++ b/ui/src/locales/lang/en-US/common.ts @@ -66,9 +66,11 @@ export default { addParam: 'Add Parameter', }, inputPlaceholder: 'Please input', + selectPlaceholder: 'Please select', title: 'Title', content: 'Content', rename: 'Rename', + renameSuccess: 'Successful', EditAvatarDialog: { title: 'App Logo', customizeUpload: 'Custom Upload', diff --git a/ui/src/locales/lang/en-US/views/index.ts b/ui/src/locales/lang/en-US/views/index.ts index 7d154bf3..c01e4723 100644 --- a/ui/src/locales/lang/en-US/views/index.ts +++ b/ui/src/locales/lang/en-US/views/index.ts @@ -1,5 +1,6 @@ import notFound from './404' import application from './application' +import role from './role' import applicationOverview from './application-overview' import knowledge from './knowledge' import system from './system' @@ -32,5 +33,6 @@ export default { problem, log, login, - operateLog + operateLog, + role } diff --git a/ui/src/locales/lang/en-US/views/role.ts b/ui/src/locales/lang/en-US/views/role.ts new file mode 100644 index 00000000..bd27a6f6 --- /dev/null +++ b/ui/src/locales/lang/en-US/views/role.ts @@ -0,0 +1,22 @@ +export default { + title: 'Role management', + internalRole: 'System built-in roles', + customRole: 'Custom roles', + systemAdmin: 'System admin', + workspaceAdmin: 'Workspace admin', + user: 'Regular user', + roleName: 'Role name', + inheritingRole: 'Inherited role', + delete: { + confirmTitle: 'Confirm to delete role:', + confirmMessage: 'After deletion, all members under this role will be removed. Please proceed with caution.', + }, + permission: { + title: 'Permission configuration', + operationTarget: 'Operation target', + moduleName: 'Module name' + }, + member: { + title: 'Members' + } +}; \ No newline at end of file diff --git a/ui/src/locales/lang/zh-CN/common.ts b/ui/src/locales/lang/zh-CN/common.ts index c7fb3fd9..10b26112 100644 --- a/ui/src/locales/lang/zh-CN/common.ts +++ b/ui/src/locales/lang/zh-CN/common.ts @@ -70,9 +70,11 @@ export default { addParam: '添加参数', }, inputPlaceholder: '请输入', + selectPlaceholder: '请选择', title: '标题', content: '内容', rename: '重命名', + renameSuccess: '重命名成功', EditAvatarDialog: { title: '应用头像', customizeUpload: '自定义上传', diff --git a/ui/src/locales/lang/zh-CN/views/index.ts b/ui/src/locales/lang/zh-CN/views/index.ts index 7f3b3620..556d1810 100644 --- a/ui/src/locales/lang/zh-CN/views/index.ts +++ b/ui/src/locales/lang/zh-CN/views/index.ts @@ -6,6 +6,7 @@ import document from './document' import system from './system' import userManage from './user-manage' import resourceAuthorization from './resource-authorization' +import role from './role' import application from './application' import problem from './problem' import applicationOverview from './application-overview' @@ -24,6 +25,7 @@ export default { system, userManage, resourceAuthorization, + role, application, problem, applicationOverview, diff --git a/ui/src/locales/lang/zh-CN/views/role.ts b/ui/src/locales/lang/zh-CN/views/role.ts new file mode 100644 index 00000000..898e08d5 --- /dev/null +++ b/ui/src/locales/lang/zh-CN/views/role.ts @@ -0,0 +1,22 @@ +export default { + title: '角色管理', + internalRole: '系统内置角色', + customRole: '自定义角色', + systemAdmin: '系统管理员', + workspaceAdmin: '工作空间管理员', + user: '普通用户', + roleName: '角色名称', + inheritingRole: '继承角色', + delete: { + confirmTitle: '是否删除角色:', + confirmMessage: '删除后,该角色下的成员都会被移除,请谨慎操作。', + }, + permission: { + title: '权限配置', + operationTarget: '操作对象', + moduleName: '模块名称' + }, + member: { + title: '成员' + } +} diff --git a/ui/src/locales/lang/zh-Hant/common.ts b/ui/src/locales/lang/zh-Hant/common.ts index a89aabed..bdf0cb33 100644 --- a/ui/src/locales/lang/zh-Hant/common.ts +++ b/ui/src/locales/lang/zh-Hant/common.ts @@ -66,9 +66,11 @@ export default { addParam: '新增參數', }, inputPlaceholder: '請輸入', + selectPlaceholder: '請選擇', title: '標題', content: '内容', rename: '重命名', + renameSuccess: '重命名成功', EditAvatarDialog: { title: '應用頭像', customizeUpload: '自訂上傳', diff --git a/ui/src/locales/lang/zh-Hant/views/index.ts b/ui/src/locales/lang/zh-Hant/views/index.ts index 7d154bf3..c01e4723 100644 --- a/ui/src/locales/lang/zh-Hant/views/index.ts +++ b/ui/src/locales/lang/zh-Hant/views/index.ts @@ -1,5 +1,6 @@ import notFound from './404' import application from './application' +import role from './role' import applicationOverview from './application-overview' import knowledge from './knowledge' import system from './system' @@ -32,5 +33,6 @@ export default { problem, log, login, - operateLog + operateLog, + role } diff --git a/ui/src/locales/lang/zh-Hant/views/role.ts b/ui/src/locales/lang/zh-Hant/views/role.ts new file mode 100644 index 00000000..dc8179c6 --- /dev/null +++ b/ui/src/locales/lang/zh-Hant/views/role.ts @@ -0,0 +1,22 @@ +export default { + title: '角色管理', + internalRole: '系統內置角色', + customRole: '自定義角色', + systemAdmin: '系統管理員', + workspaceAdmin: '工作空間管理員', + user: '普通用戶', + roleName: '角色名稱', + inheritingRole: '繼承角色', + delete: { + confirmTitle: '是否刪除角色:', + confirmMessage: '刪除後,該角色下的成員都會被移除,請謹慎操作。', + }, + permission: { + title: '權限配置', + operationTarget: '操作對象', + moduleName: '模塊名稱' + }, + member: { + title: '成員' + } +}; \ No newline at end of file diff --git a/ui/src/router/modules/system.ts b/ui/src/router/modules/system.ts index ec428940..1e6bd785 100644 --- a/ui/src/router/modules/system.ts +++ b/ui/src/router/modules/system.ts @@ -32,6 +32,19 @@ const systemRouter = { }, component: () => import('@/views/resource-authorization/index.vue'), }, + { + path: '/system/role', + name: 'role', + meta: { + icon: 'app-resource-authorization', // TODO + iconActive: 'app-resource-authorization-active', // TODO + title: 'views.role.title', + activeMenu: '/system', + parentPath: '/system', + parentName: 'system', + }, + component: () => import('@/views/role/index.vue'), + }, { path:'/system/setting', name: 'setting', diff --git a/ui/src/styles/app.scss b/ui/src/styles/app.scss index 835bde91..c7e2a684 100644 --- a/ui/src/styles/app.scss +++ b/ui/src/styles/app.scss @@ -385,6 +385,9 @@ h5 { .color-success { color: var(--el-color-success); } +.color-input-placeholder { + color: var(--app-input-color-placeholder); +} .avatar-purple { background: #7f3bf5; } diff --git a/ui/src/views/role/component/CreateOrUpdateRoleDialog.vue b/ui/src/views/role/component/CreateOrUpdateRoleDialog.vue new file mode 100644 index 00000000..373ee8c0 --- /dev/null +++ b/ui/src/views/role/component/CreateOrUpdateRoleDialog.vue @@ -0,0 +1,82 @@ + + + diff --git a/ui/src/views/role/component/Member.vue b/ui/src/views/role/component/Member.vue new file mode 100644 index 00000000..5b5b2b1d --- /dev/null +++ b/ui/src/views/role/component/Member.vue @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/ui/src/views/role/component/PermissionConfiguration.vue b/ui/src/views/role/component/PermissionConfiguration.vue new file mode 100644 index 00000000..3e9fdbc1 --- /dev/null +++ b/ui/src/views/role/component/PermissionConfiguration.vue @@ -0,0 +1,173 @@ + + + + + \ No newline at end of file diff --git a/ui/src/views/role/index.ts b/ui/src/views/role/index.ts new file mode 100644 index 00000000..b6cca78b --- /dev/null +++ b/ui/src/views/role/index.ts @@ -0,0 +1,8 @@ +import { RoleTypeEnum } from '@/enums/system' +import { t } from '@/locales' + +export const roleTypeMap: Record = { + [RoleTypeEnum.ADMIN]: t('views.role.systemAdmin'), + [RoleTypeEnum.USER]: t('views.role.user'), + [RoleTypeEnum.WORKSPACE_MANAGE]: t('views.role.workspaceAdmin') +} \ No newline at end of file diff --git a/ui/src/views/role/index.vue b/ui/src/views/role/index.vue new file mode 100644 index 00000000..e0858858 --- /dev/null +++ b/ui/src/views/role/index.vue @@ -0,0 +1,266 @@ + + + + +