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.

88 lines
1.8 KiB

import apiService from './apiClient';
// 用户接口定义
export interface User {
id: string;
username: string;
email: string;
avatar?: string;
createdAt: string;
}
// 登录参数
export interface LoginParams {
2 months ago
grant_type: string;
username: string;
password: string;
2 months ago
client_id: string;
client_secret: string;
scope: string;
}
// 注册参数
export interface RegisterParams {
username: string;
email: string;
password: string;
}
// 登录响应
export interface AuthResponse {
2 months ago
"access_token": string,
"token_type": string,
"user": {
"user_id": number,
"username": string,
"email": string,
"phone": string,
"avatar_url": string,
"status": number,
"last_login": string,
"create_time": string,
"update_time": string
}
}
// 用户API服务
export const userApi = {
// 登录
login: (params: LoginParams) => {
2 months ago
return apiService.post<AuthResponse>('/api/users/login', params,{
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
});
},
// 注册
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;