blob: 9f45f12fc2b17dfcbfb63807d162ab45890bc833 [file] [log] [blame]
86133aaa3f5d2025-04-20 21:33:29 +08001import { formatTreeData } from '@/utils/tree';
2import { request } from '@umijs/max';
3import { DataNode } from 'antd/es/tree';
4import { downLoadXlsx } from '@/utils/downloadfile';
5
6// 查询用户信息列表
7export async function getUserList(params?: API.System.UserListParams, options?: { [key: string]: any }) {
8 return request<API.System.UserPageResult>('/api/system/user/list', {
9 method: 'GET',
10 headers: {
11 'Content-Type': 'application/json;charset=UTF-8',
12 },
13 params,
14 ...(options || {})
15 });
16}
17
18// 查询用户信息详细
19export function getUser(userId: number, options?: { [key: string]: any }) {
20 return request<API.System.UserInfoResult>(`/api/system/user/${userId}`, {
21 method: 'GET',
22 ...(options || {})
23 });
24}
25
26// 新增用户信息
27export async function addUser(params: API.System.User, options?: { [key: string]: any }) {
28 return request<API.Result>('/api/system/user', {
29 method: 'POST',
30 headers: {
31 'Content-Type': 'application/json;charset=UTF-8',
32 },
33 data: params,
34 ...(options || {})
35 });
36}
37
38// 修改用户信息
39export async function updateUser(params: API.System.User, options?: { [key: string]: any }) {
40 return request<API.Result>('/api/system/user', {
41 method: 'PUT',
42 headers: {
43 'Content-Type': 'application/json;charset=UTF-8',
44 },
45 data: params,
46 ...(options || {})
47 });
48}
49
50// 删除用户信息
51export async function removeUser(ids: string, options?: { [key: string]: any }) {
52 return request<API.Result>(`/api/system/user/${ids}`, {
53 method: 'DELETE',
54 ...(options || {})
55 });
56}
57
58// 导出用户信息
59export function exportUser(params?: API.System.UserListParams, options?: { [key: string]: any }) {
60 return downLoadXlsx(`/api/system/user/export`, { params }, `user_${new Date().getTime()}.xlsx`);
61}
62
63// 用户状态修改
64export function changeUserStatus(userId: number, status: string) {
65 const data = {
66 userId,
67 status
68 }
69 return request<API.Result>('/api/system/user/changeStatus', {
70 method: 'put',
71 data: data
72 })
73}
74
75// 查询用户个人信息
76export function getUserProfile() {
77 return request('/api/system/user/profile', {
78 method: 'get'
79 })
80}
81
BirdNETMb0f71532025-05-26 17:37:33 +080082// 查询用户上传,下载,分享率等信息
83export function getUserRateInfo() {
84 return request('/api/system/user/profile/info', {
85 method: 'get'
86 })
87}
88
89
86133aaa3f5d2025-04-20 21:33:29 +080090export function updateUserProfile(data: API.CurrentUser) {
91 return request<API.Result>('/api/system/user/profile', {
92 method: 'put',
93 data: data
94 })
95}
96
97// 用户密码重置
98export function resetUserPwd(userId: number, password: string) {
99 const data = {
100 userId,
101 password
102 }
103 return request<API.Result>('/api/system/user/resetPwd', {
104 method: 'put',
105 data: data
106 })
107}
108
109// 用户t个人密码重置
110export function updateUserPwd(oldPassword: string, newPassword: string) {
111 const data = {
112 oldPassword,
113 newPassword
114 }
115 return request<API.Result>('/api/system/user/profile/updatePwd', {
116 method: 'put',
117 params: data
118 })
119}
120
121// 用户头像上传
122export function uploadAvatar(data: any) {
123 return request('/api/system/user/profile/avatar', {
124 method: 'post',
125 data: data
126 })
127}
128
129
130// 查询授权角色
131export function getAuthRole(userId: number) {
132 return request('/system/user/authRole/' + userId, {
133 method: 'get'
134 })
135}
136
137// 保存授权角色
138export function updateAuthRole(data: Record<string, any>) {
139 return request('/system/user/authRole', {
140 method: 'put',
141 params: data
142 })
143}
144
145// 获取数据列表
146export function getDeptTree(params: any): Promise<DataNode[]> {
147 return new Promise((resolve) => {
148 request(`/api/system/user/deptTree`, {
149 method: 'get',
150 params,
151 }).then((res: any) => {
152 if (res && res.code === 200) {
153 const treeData = formatTreeData(res.data);
154 resolve(treeData);
155 } else {
156 resolve([]);
157 }
158 });
159 });
160}