/** * 认证模块 API */ import { get, post } from '@/utils/request' /** * 登录请求参数 */ export interface LoginParams { username: string password: string } /** * 登录响应 */ export interface LoginResponse { access_token: string refresh_token: string expires_in: number user: { id: number username: string user_type: 1 | 2 | 3 | 4 // 1=超级管理员 2=平台 3=代理 4=企业 enterprise_id?: number shop_id?: number } } /** * 用户信息 */ export interface UserInfo { id: number username: string phone: string user_type: 1 | 2 | 3 | 4 user_type_name: string shop_id?: number enterprise_id?: number // 以下字段为可选扩展字段(根据实际接口返回) nickname?: string shop_name?: string enterprise_name?: string email?: string avatar?: string status?: 'active' | 'inactive' create_time?: string last_login_time?: string } /** * 修改密码参数 */ export interface ChangePasswordParams { old_password: string new_password: string } /** * 登录 * POST /api/auth/login */ export function login(data: LoginParams) { return post('/api/auth/login', { data }) } /** * 登出 * POST /api/auth/logout */ export function logout() { return post('/api/auth/logout') } /** * 获取当前用户信息响应 */ export interface GetUserInfoResponse { user: UserInfo permissions: string[] } /** * 获取当前用户信息 * GET /api/auth/me */ export function getUserInfo() { return get('/api/auth/me').then(res => res.user) } /** * 刷新Token * POST /api/auth/refresh */ export function refreshToken(refresh_token: string) { return post('/api/auth/refresh', { data: { refresh_token }, }) } /** * 修改密码 * PUT /api/auth/password */ export function changePassword(data: ChangePasswordParams) { return post('/api/auth/password', { data, method: 'PUT', }) }