Files
Environment-Monitoring-System/ems-frontend/ems-monitoring-system/src/api/user.ts
ChuXun 02a830145e 1
2025-10-25 19:18:43 +08:00

74 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}