You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.4 KiB

import apiService from './apiClient';
// 用户接口定义
export interface User {
id: string;
username: string;
email: string;
avatar?: string;
createdAt: string;
}
// 登录参数
export interface LoginParams {
email: string;
password: string;
}
// 注册参数
export interface RegisterParams {
username: string;
email: string;
password: string;
}
// 登录响应
export interface AuthResponse {
user: User;
token: string;
}
// 用户API服务
export const userApi = {
// 登录
login: (params: LoginParams) => {
return apiService.post<AuthResponse>('/auth/login', params);
},
// 注册
register: (params: RegisterParams) => {
return apiService.post<AuthResponse>('/auth/register', params);
},
// 获取用户信息
getProfile: () => {
return apiService.get<User>('/user/profile');
},
// 更新用户信息
updateProfile: (data: Partial<User>) => {
return apiService.put<User>('/user/profile', data);
},
// 更新用户头像
updateAvatar: (file: FormData) => {
return apiService.upload<{avatar: string}>('/user/avatar', file);
},
// 退出登录
logout: () => {
return apiService.post('/auth/logout');
},
// 检查邮箱是否可用
checkEmailAvailability: (email: string) => {
return apiService.get<{available: boolean}>('/auth/check-email', { email });
}
};
export default userApi;