1+ import { Result } from '@/request/Result'
2+ import type { Ref } from 'vue'
3+ import { get , post , del } from '@/request/index'
4+ import type { WorkspaceItem , CreateWorkspaceMemberParamsItem , WorkspaceMemberItem } from '@/api/type/workspace'
5+ import type { pageRequest , PageList } from '@/api/type/common'
6+
7+ const prefix = '/system/workspace'
8+
9+ /**
10+ * 获取添加成员时的工作空间下拉列表
11+ */
12+ const getWorkspaceList : ( loading ?: Ref < boolean > ) => Promise < Result < Record < string , any > [ ] > > = ( loading ) => {
13+ return get ( '/workspace/current_user' , undefined , loading )
14+ }
15+
16+ /**
17+ * 获取工作空间列表
18+ */
19+ const getSystemWorkspaceList : ( loading ?: Ref < boolean > ) => Promise < Result < WorkspaceItem [ ] > > = ( loading ) => {
20+ return get ( `${ prefix } ` , undefined , loading )
21+ }
22+
23+ /**
24+ * 新建或更新工作空间
25+ */
26+ const CreateOrUpdateWorkspace : (
27+ data : WorkspaceItem ,
28+ loading ?: Ref < boolean > ,
29+ ) => Promise < Result < any > > = ( data , loading ) => {
30+ return post ( `${ prefix } ` , data , undefined , loading )
31+ }
32+
33+ /**
34+ * 删除工作空间
35+ */
36+ const deleteWorkspace : ( workspace_id : string , loading ?: Ref < boolean > ) => Promise < Result < boolean > > = (
37+ workspace_id ,
38+ loading ,
39+ ) => {
40+ return del ( `${ prefix } /${ workspace_id } ` , undefined , { } , loading )
41+ }
42+
43+ /**
44+ * 获取工作空间成员列表
45+ */
46+ const getWorkspaceMemberList : (
47+ workspace_id : string ,
48+ page : pageRequest ,
49+ param : any ,
50+ loading ?: Ref < boolean > ,
51+ ) => Promise < Result < PageList < WorkspaceMemberItem [ ] > > > = ( workspace_id , page , param , loading ) => {
52+ return get (
53+ `${ prefix } /${ workspace_id } /user_list/${ page . current_page } /${ page . page_size } ` ,
54+ param ,
55+ loading ,
56+ )
57+ }
58+
59+ /**
60+ * 新建工作空间成员
61+ */
62+ const CreateWorkspaceMember : (
63+ workspace_id : string ,
64+ data : CreateWorkspaceMemberParamsItem [ ] ,
65+ loading ?: Ref < boolean > ,
66+ ) => Promise < Result < any > > = ( workspace_id , data , loading ) => {
67+ return post ( `${ prefix } /${ workspace_id } /add_member` , data , undefined , loading )
68+ }
69+
70+ /**
71+ * 删除工作空间成员
72+ */
73+ const deleteWorkspaceMember : ( workspace_id : string , user_relation_id : string , loading ?: Ref < boolean > ) => Promise < Result < any > > = (
74+ workspace_id ,
75+ user_relation_id ,
76+ loading ,
77+ ) => {
78+ return post ( `${ prefix } /${ workspace_id } /remove_member/${ user_relation_id } ` , undefined , { } , loading )
79+ }
80+
81+ /**
82+ * 获取添加成员时的角色下拉列表
83+ */
84+ const getWorkspaceRoleList : ( loading ?: Ref < boolean > ) => Promise < Result < Record < string , any > [ ] > > = ( loading ) => {
85+ return get ( '/role_list/current_user' , undefined , loading )
86+ }
87+
88+ export default {
89+ getWorkspaceList,
90+ getSystemWorkspaceList,
91+ CreateOrUpdateWorkspace,
92+ deleteWorkspace,
93+ getWorkspaceMemberList,
94+ CreateWorkspaceMember,
95+ deleteWorkspaceMember,
96+ getWorkspaceRoleList,
97+ }
0 commit comments