1
This commit is contained in:
74
ems-frontend/ems-monitoring-system/src/api/user.ts
Normal file
74
ems-frontend/ems-monitoring-system/src/api/user.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import apiClient from './index';
|
||||
import type { GridWorker } from './grid';
|
||||
|
||||
/**
|
||||
* 用户信息接口
|
||||
*/
|
||||
export interface UserInfo {
|
||||
id: number;
|
||||
name: string;
|
||||
email: string;
|
||||
phone: string;
|
||||
role: string;
|
||||
avatar?: string;
|
||||
permissions?: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户更新请求接口
|
||||
*/
|
||||
export interface UserUpdateRequest {
|
||||
name?: string;
|
||||
phone?: string;
|
||||
email?: string;
|
||||
region?: string;
|
||||
level?: string;
|
||||
gridX?: number | null;
|
||||
gridY?: number | null;
|
||||
currentLatitude?: number | null;
|
||||
currentLongitude?: number | null;
|
||||
skills?: string[];
|
||||
status?: string;
|
||||
gender?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录用户信息
|
||||
* @returns 用户信息
|
||||
*/
|
||||
export function getCurrentUser(): Promise<UserInfo> {
|
||||
return apiClient.get('/auth/profile');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户资料
|
||||
* @param userId 用户ID
|
||||
* @param data 更新数据
|
||||
* @returns 更新后的用户信息
|
||||
*/
|
||||
export function updateUserProfile(userId: number, data: UserUpdateRequest): Promise<GridWorker> {
|
||||
console.log(`API调用: 更新用户资料, userId=${userId}`, data);
|
||||
return apiClient.patch(`/personnel/users/${userId}`, data)
|
||||
.then(response => {
|
||||
console.log('更新用户资料API调用成功:', response.data);
|
||||
return response.data;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('更新用户资料API调用失败:', error);
|
||||
console.error('错误详情:', error.response?.data || error.message);
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户角色
|
||||
* @param userId 用户ID
|
||||
* @param role 角色名称
|
||||
* @param gridX 网格X坐标(可选)
|
||||
* @param gridY 网格Y坐标(可选)
|
||||
* @returns 更新后的用户信息
|
||||
*/
|
||||
export function updateUserRole(userId: number, role: string, gridX?: number, gridY?: number): Promise<GridWorker> {
|
||||
const data = { role, gridX, gridY };
|
||||
return apiClient.put(`/personnel/users/${userId}/role`, data).then(response => response.data);
|
||||
}
|
||||
Reference in New Issue
Block a user