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.

116 lines
2.6 KiB

import apiService from './apiClient';
// 用户接口定义
export interface User {
1 month ago
"username": string,
"email": string,
"phone": string,
"avatar_url": string,
"status": number,
"user_id": number,
"last_login": string,
"create_time": string,
"update_time": string,
country_code:number,
vip_discount:number,
balance:number,
1 month ago
currency:string,
country:string,
balance_currency:string,
1 month ago
country_en:string,
4 weeks ago
language:string,
vip_level:number
1 month ago
}
export interface UserSettings {
country: number;
create_time: string; // 或使用 Date 类型,如果需要进行日期操作
currency: string;
email_notifications: number; // 或用 boolean 如果值只能是 0 或 1
language: string;
notifications_enabled: number; // 或用 boolean
setting_id: number;
sms_notifications: number; // 或用 boolean
theme: string; // 或用联合类型,如 'light' | 'dark'
timezone: string;
update_time: string; // 或使用 Date 类型
user_id: number;
}
// 登录参数
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: () => {
4 weeks ago
return apiService.get<User>('/api/users/me/');
},
// 更新用户信息
updateProfile: (data: Partial<User>) => {
4 weeks ago
return apiService.put<User>('/user/profile/', data);
},
// 更新用户头像
updateAvatar: (file: FormData) => {
4 weeks ago
return apiService.upload<{avatar: string}>('/user/avatar/', file);
},
// 退出登录
logout: () => {
4 weeks ago
return apiService.post('/auth/logout/');
},
// 检查邮箱是否可用
checkEmailAvailability: (email: string) => {
4 weeks ago
return apiService.get<{available: boolean}>('/auth/check-email/', { email });
}
};
export default userApi;