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.
111 lines
2.5 KiB
111 lines
2.5 KiB
import apiService from './apiClient'; |
|
|
|
// 用户接口定义 |
|
export interface User { |
|
"username": string, |
|
"email": string, |
|
"phone": string, |
|
"avatar_url": string, |
|
"status": number, |
|
"user_id": number, |
|
"last_login": string, |
|
"create_time": string, |
|
"update_time": string |
|
currency:string, |
|
country:string, |
|
country_en:string, |
|
language:string |
|
} |
|
|
|
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 { |
|
grant_type: string; |
|
username: string; |
|
password: string; |
|
client_id: string; |
|
client_secret: string; |
|
scope: string; |
|
} |
|
|
|
// 注册参数 |
|
export interface RegisterParams { |
|
username: string; |
|
email: string; |
|
password: string; |
|
} |
|
|
|
// 登录响应 |
|
export interface AuthResponse { |
|
"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) => { |
|
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>('/api/users/me/'); |
|
}, |
|
|
|
// 更新用户信息 |
|
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;
|