system.ts
5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import {
AccountParams,
OrganizationListItem,
MenuParams,
RoleParams,
RolePageParams,
MenuListGetResultModel,
OrganizationListGetResultModel,
AccountListGetResultModel,
RolePageListGetResultModel,
RoleListGetResultModel,
RoleReqDTO,
AccountListItem,
AccountListModel,
RoleOrOrganizationParam,
ChangeAccountParams,
RoleListItem,
} from './model/systemModel';
import { USER_INFO_KEY } from '/@/enums/cacheEnum';
import { getAuthCache } from '/@/utils/auth';
import { defHttp } from '/@/utils/http/axios';
enum Api {
AccountList = '/user/page',
IsAccountExist = '/user/account_exist/',
IsPhoneExist = '/user/get_user/',
DeptList = '/dept/all',
setRoleStatus = '/role/update_status/',
MenuList = '/system/getMenuList',
RolePageList = '/role',
TenantRolePageList = '/role/tenant',
SaveOrUpdateRoleInfoWithMenu = '/role/save_with_menu',
DeleteRole = '/role',
GetAllRoleList = '/role/find/list',
BaseUserUrl = '/user',
BaseOrganization = '/organization',
RESET_USER_PASSWORD = '/user/reset_password/',
}
export const getAccountInfo = (userId: string) =>
defHttp.get<AccountListModel>({ url: Api.BaseUserUrl + '/' + userId });
export const getAccountList = (params: AccountParams) =>
defHttp.get<AccountListGetResultModel>({ url: Api.AccountList, params });
/**
* 获取组织列表
* @param params 请求参数
*/
export const getOrganizationList = (params?: OrganizationListItem) =>
defHttp.get<OrganizationListGetResultModel>({
url: Api.BaseOrganization + '/me/list',
params,
});
/**
* 更新或者保存组织
* @param params
* @param isUpdate
*/
export const saveOrUpdateOrganization = (params?: OrganizationListItem, isUpdate?: boolean) => {
if (isUpdate) {
return defHttp.put<OrganizationListGetResultModel>({ url: Api.BaseOrganization, params });
} else {
return defHttp.post<OrganizationListGetResultModel>({ url: Api.BaseOrganization, params });
}
};
/**
* 删除组织
* @param ids 删除的ID
*/
export const delOrganization = (ids: string[]) =>
defHttp.delete({
url: Api.BaseOrganization,
data: {
ids,
},
});
export const getMenuList = (params?: MenuParams) =>
defHttp.get<MenuListGetResultModel>({ url: Api.MenuList, params });
export const getRoleListByPage = (params?: RolePageParams) =>
defHttp.get<RolePageListGetResultModel>({ url: Api.RolePageList, params });
export const getTenantRoleRoleListByPage = (params?: RolePageParams) =>
defHttp.get<RolePageListGetResultModel>({ url: Api.TenantRolePageList, params });
export const getTenantRoleListByPage = (params?: RolePageParams) =>
defHttp.get<RolePageListGetResultModel>({ url: Api.RolePageList, params });
export const getAllRoleList = async (params?: RoleParams) => {
return defHttp.post<RoleListGetResultModel>({ url: Api.GetAllRoleList, params });
};
// 过滤角色列表----根据登录的账号所属的角色-过滤掉其他平台类型的角色
export const filterRoleList = async (params?: { roleType: string }) => {
const res = await defHttp.post<RoleListGetResultModel>({
url: Api.GetAllRoleList,
params: params,
});
const userInfo: any = getAuthCache(USER_INFO_KEY);
const role = userInfo.roles[0];
const options = res.filter((item) => {
if (params?.roleType && params.roleType === 'TENANT_ADMIN') {
return item;
} else if (role === 'SYS_ADMIN' || role === 'PLATFORM_ADMIN') {
return item.roleType === 'PLATFORM_ADMIN';
} else {
return item.roleType === 'CUSTOMER_USER';
}
});
return Promise.resolve<RoleListItem[]>(options);
};
export const setRoleStatus = (id: number, status: number) => {
return defHttp.put({ url: Api.setRoleStatus + id + '/' + status });
};
export const saveOrUpdateRoleInfoWithMenu = (roleRequestDto: RoleReqDTO) => {
return defHttp.post({ url: Api.SaveOrUpdateRoleInfoWithMenu, params: roleRequestDto });
};
export const isAccountExist = (account: string) => {
return defHttp.get({ url: Api.IsAccountExist + account }, { errorMessageMode: 'none' });
};
export const IsPhoneExist = (phoneNumber: string) => {
return defHttp.get({
url: Api.IsPhoneExist + phoneNumber,
});
};
export const delRole = (roleIds: string[]) => {
return defHttp.delete({ url: Api.DeleteRole, params: roleIds });
};
/**
* 更新或添加用户信息
* @param params
* @param isUpdate
* @constructor
*/
export const SaveOrUpdateUserInfo = (params: AccountListItem, isUpdate: boolean) => {
return defHttp[isUpdate ? 'put' : 'post']<AccountListModel>({
url: Api.BaseUserUrl,
params,
});
};
/**
* 删除User
* @param ids 删除id数组
*/
export const deleteUser = (ids: string[]) =>
defHttp.delete({
url: Api.BaseUserUrl,
data: {
ids: ids,
},
});
/**
* 查询当前用户的关系
* @param params
*/
export const findCurrentUserRelation = (params: RoleOrOrganizationParam) =>
defHttp.post<Array<string>>({
url: Api.BaseUserUrl + '/relation',
params: params,
});
/**
* 修改密码
* @param params
*/
export const resetPassword = (params: ChangeAccountParams) =>
defHttp.post({
url: Api.BaseUserUrl + '/reset',
params: params,
});
/**
* 清除密码
* @param params
*/
export const clearUserPassword = (userId: string, level: number) =>
defHttp.post({
url: Api.RESET_USER_PASSWORD + userId + '/' + level,
});