import {post, get} from '../request'; // ============================================================ // AuthUrlObj — 认证模块路由常量 // 集中管理,后续接口升级 v2 等只需改此处 // ============================================================ const AuthUrlObj = { login: '/api/v1/auth/login', register: '/api/v1/auth/register', sendSms: '/api/v1/auth/send-sms', refreshToken: '/api/v1/auth/refresh', userInfo: '/api/v1/auth/me', changePassword: '/api/v1/auth/change-password', resetPassword: '/api/v1/auth/reset-password', logout: '/api/v1/auth/logout', } as const; // ============================================================ // 认证相关 DTO 传输模型 // ============================================================ /** 短信验证码请求体 */ export interface SendSMSRequestBody { phone: string; } /** 注册请求体 */ export interface RegisterRequestBody { // 用户名,3~64 位,仅允许字母、数字、-、_ username: string; // 密码,6~128 位 password: string; // 手机号,5~32 位 phone: string; // 短信验证码,4~8 位 sms_code: string; // 设备标识(网卡 MAC),8~128 位 device_id: string; // 设备标签/备注(可选) device_label: string; // 个人昵称(可选) display_name: string; // 邀请码(可选),填写后触发邀请佣金逻辑 referral_code: string; } export interface RegisterResponseBody { access_token: string; refresh_token: string; token_type: string; expires_in: 0; refresh_expires_in: 0; user_id: string; username: string; role: "user" | "admin" | "superadmin"; email: string; balance_cent: 0; account_type: "individual" | "company" | "employee"; display_name: string; company_id: string; real_name: string; phone: string; license_code: string; admin_permissions: string [] } /** 登录请求体 */ export interface LoginRequestBody { username: string; password: string; device_id: string; user_ip: string; } export interface LoginResponseBody { access_token: string; refresh_token: string; token_type: string; expires_in: number; refresh_expires_in: number; user_id: string; username: string; role: "user" | "admin" | "superadmin"; email: string; balance_cent: number; account_type: "individual" | "company" | "employee"; display_name: string; company_id: string; real_name: string; phone: string; license_code: string; admin_permissions: string[]; } export interface RefreshTokenRequestBody { refresh_token: string; } export interface RefreshTokenResponseBody { access_token: string; refresh_token: string; token_type: string; expires_in: number; refresh_expires_in: number; } export interface UserInfoBody { id: string; username: string; email: string; balance_cent: number; gift_balance_cent: number; role: "user" | "admin" | "superadmin"; status: string; account_type: "individual" | "company" | "employee"; display_name: string; real_name: string; phone: string; company_id: string; discount_rate: number; subscription_plan: string; subscription_expires_at: Date; seat_limit: number; last_login_at: Date; created_at: Date; model_package_id: number; vip_level_id: number; software_expires_at: Date; referral_code: string; admin_permissions: string[]; } export interface ChangePasswordRequestBody { current_password: string; new_password: string; } export interface UsePhoneResetPasswordRequestBody { phone: string; sms_code: string; new_password: string; } // ============================================================ // AuthAPI — 认证相关 API 静态方法类 // 调用方式:AuthAPI.login() / AuthAPI.register() 等 // ============================================================ export class AuthAPI { /** 登录 */ static async login(data: LoginRequestBody): Promise { return await post(AuthUrlObj.login, data); } /** 注册 */ static async register(data: RegisterRequestBody): Promise { return await post(AuthUrlObj.register, data); } /** 发送短信验证码 */ static async sendSms(data: SendSMSRequestBody): Promise { return await post(AuthUrlObj.sendSms, data); } /** 刷新 Token */ static async refreshToken(data: RefreshTokenRequestBody): Promise { return await post(AuthUrlObj.refreshToken, data); } /** 获取当前用户信息 */ static async getUserInfo(): Promise { return await get(AuthUrlObj.userInfo); } /** 修改密码(已登录) */ static async changePassword(data: ChangePasswordRequestBody): Promise { return await post(AuthUrlObj.changePassword, data); } /** 手机验证码重置密码 */ static async resetPassword(data: UsePhoneResetPasswordRequestBody): Promise { return await post(AuthUrlObj.resetPassword, data); } /** 退出登录 */ static async logout(): Promise { return await post(AuthUrlObj.logout); } }