Skip to content

Commit e0dcc4b

Browse files
1myuanliuruibin
authored andcommitted
feat: role
1 parent cfafc3f commit e0dcc4b

File tree

19 files changed

+746
-2
lines changed

19 files changed

+746
-2
lines changed

ui/src/api/type/role.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { RoleTypeEnum } from '@/enums/system'
2+
3+
interface RoleItem {
4+
id: string,
5+
role_name: string,
6+
type: RoleTypeEnum,
7+
create_user: string,
8+
internal: boolean,
9+
}
10+
11+
interface ChildrenPermissionItem {
12+
id: string
13+
name: string
14+
enable: boolean
15+
}
16+
17+
interface RolePermissionItem {
18+
id: string,
19+
name: string,
20+
children: {
21+
id: string,
22+
name: string,
23+
permission: ChildrenPermissionItem[],
24+
enable: boolean,
25+
}[]
26+
}
27+
28+
interface RoleTableDataItem {
29+
module: string
30+
name: string
31+
permission: ChildrenPermissionItem[]
32+
enable: boolean
33+
perChecked: string[]
34+
indeterminate: boolean
35+
}
36+
37+
interface CreateOrUpdateParams {
38+
role_id?: string,
39+
role_name: string,
40+
role_type?: RoleTypeEnum,
41+
}
42+
43+
export type { RoleItem, RolePermissionItem, RoleTableDataItem, CreateOrUpdateParams, ChildrenPermissionItem }

ui/src/api/user/role.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { get, post, del } from '@/request/index'
2+
import type { Ref } from 'vue'
3+
import { Result } from '@/request/Result'
4+
import type { RoleItem, RolePermissionItem, CreateOrUpdateParams } from '@/api/type/role'
5+
import { RoleTypeEnum } from '@/enums/system'
6+
7+
const prefix = '/system/role'
8+
/**
9+
* 获取角色列表
10+
*/
11+
const getRoleList: (loading?: Ref<boolean>) => Promise<Result<{ internal_role: RoleItem[], custom_role: RoleItem[] }>> = (loading) => {
12+
return get(`${prefix}`, undefined, loading)
13+
}
14+
15+
/**
16+
* 根据类型获取角色权限模版列表
17+
*/
18+
const getRoleTemplate: (role_type: RoleTypeEnum, loading?: Ref<boolean>) => Promise<Result<RolePermissionItem[]>> = (role_type, loading) => {
19+
return get(`${prefix}/template/${role_type}`, undefined, loading)
20+
}
21+
22+
/**
23+
* 获取角色权限选中
24+
*/
25+
const getRolePermissionList: (role_id: string, loading?: Ref<boolean>) => Promise<Result<RolePermissionItem[]>> = (role_id, loading) => {
26+
return get(`${prefix}/${role_id}/permission`, undefined, loading)
27+
}
28+
29+
/**
30+
* 新建或更新角色
31+
*/
32+
const CreateOrUpdateRole: (
33+
data: CreateOrUpdateParams,
34+
loading?: Ref<boolean>,
35+
) => Promise<Result<any>> = (data, loading) => {
36+
return post(`${prefix}`, data, undefined, loading)
37+
}
38+
39+
/**
40+
* 删除角色
41+
*/
42+
const deleteRole: (role_id: string, loading?: Ref<boolean>) => Promise<Result<boolean>> = (
43+
role_id,
44+
loading,
45+
) => {
46+
return del(`${prefix}/${role_id}`, undefined, {}, loading)
47+
}
48+
49+
/**
50+
* 保存角色权限
51+
*/
52+
const saveRolePermission: (
53+
role_id: string,
54+
data: { id: string, enable: boolean }[],
55+
loading?: Ref<boolean>,
56+
) => Promise<Result<any>> = (role_id, data, loading) => {
57+
return post(`${prefix}/${role_id}/permission`, data, undefined, loading)
58+
}
59+
60+
export default {
61+
getRoleList,
62+
getRolePermissionList,
63+
getRoleTemplate,
64+
CreateOrUpdateRole,
65+
deleteRole,
66+
saveRolePermission
67+
}

ui/src/enums/system.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ export enum AuthorizationEnum {
55
KNOWLEDGE = 'KNOWLEDGE',
66
APPLICATION = 'APPLICATION',
77
}
8+
9+
export enum RoleTypeEnum {
10+
ADMIN = 'ADMIN',
11+
USER = 'USER',
12+
WORKSPACE_MANAGE = 'WORKSPACE_MANAGE',
13+
}

ui/src/locales/lang/en-US/common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ export default {
6666
addParam: 'Add Parameter',
6767
},
6868
inputPlaceholder: 'Please input',
69+
selectPlaceholder: 'Please select',
6970
title: 'Title',
7071
content: 'Content',
7172
rename: 'Rename',
73+
renameSuccess: 'Successful',
7274
EditAvatarDialog: {
7375
title: 'App Logo',
7476
customizeUpload: 'Custom Upload',

ui/src/locales/lang/en-US/views/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import notFound from './404'
22
import application from './application'
3+
import role from './role'
34
import applicationOverview from './application-overview'
45
import knowledge from './knowledge'
56
import system from './system'
@@ -32,5 +33,6 @@ export default {
3233
problem,
3334
log,
3435
login,
35-
operateLog
36+
operateLog,
37+
role
3638
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export default {
2+
title: 'Role management',
3+
internalRole: 'System built-in roles',
4+
customRole: 'Custom roles',
5+
systemAdmin: 'System admin',
6+
workspaceAdmin: 'Workspace admin',
7+
user: 'Regular user',
8+
roleName: 'Role name',
9+
inheritingRole: 'Inherited role',
10+
delete: {
11+
confirmTitle: 'Confirm to delete role:',
12+
confirmMessage: 'After deletion, all members under this role will be removed. Please proceed with caution.',
13+
},
14+
permission: {
15+
title: 'Permission configuration',
16+
operationTarget: 'Operation target',
17+
moduleName: 'Module name'
18+
},
19+
member: {
20+
title: 'Members'
21+
}
22+
};

ui/src/locales/lang/zh-CN/common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@ export default {
7070
addParam: '添加参数',
7171
},
7272
inputPlaceholder: '请输入',
73+
selectPlaceholder: '请选择',
7374
title: '标题',
7475
content: '内容',
7576
rename: '重命名',
77+
renameSuccess: '重命名成功',
7678
EditAvatarDialog: {
7779
title: '应用头像',
7880
customizeUpload: '自定义上传',

ui/src/locales/lang/zh-CN/views/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import document from './document'
66
import system from './system'
77
import userManage from './user-manage'
88
import resourceAuthorization from './resource-authorization'
9+
import role from './role'
910
import application from './application'
1011
import problem from './problem'
1112
import applicationOverview from './application-overview'
@@ -24,6 +25,7 @@ export default {
2425
system,
2526
userManage,
2627
resourceAuthorization,
28+
role,
2729
application,
2830
problem,
2931
applicationOverview,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export default {
2+
title: '角色管理',
3+
internalRole: '系统内置角色',
4+
customRole: '自定义角色',
5+
systemAdmin: '系统管理员',
6+
workspaceAdmin: '工作空间管理员',
7+
user: '普通用户',
8+
roleName: '角色名称',
9+
inheritingRole: '继承角色',
10+
delete: {
11+
confirmTitle: '是否删除角色:',
12+
confirmMessage: '删除后,该角色下的成员都会被移除,请谨慎操作。',
13+
},
14+
permission: {
15+
title: '权限配置',
16+
operationTarget: '操作对象',
17+
moduleName: '模块名称'
18+
},
19+
member: {
20+
title: '成员'
21+
}
22+
}

ui/src/locales/lang/zh-Hant/common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ export default {
6666
addParam: '新增參數',
6767
},
6868
inputPlaceholder: '請輸入',
69+
selectPlaceholder: '請選擇',
6970
title: '標題',
7071
content: '内容',
7172
rename: '重命名',
73+
renameSuccess: '重命名成功',
7274
EditAvatarDialog: {
7375
title: '應用頭像',
7476
customizeUpload: '自訂上傳',

0 commit comments

Comments
 (0)