64 lines
1.6 KiB
TypeScript
64 lines
1.6 KiB
TypeScript
/**
|
||
* 认证相关 API
|
||
*/
|
||
|
||
import { BaseService } from '../BaseService'
|
||
import type {
|
||
LoginParams,
|
||
LoginData,
|
||
UserInfo,
|
||
UserInfoResponse,
|
||
RefreshTokenParams,
|
||
RefreshTokenData,
|
||
ChangePasswordParams,
|
||
BaseResponse
|
||
} from '@/types/api'
|
||
|
||
export class AuthService extends BaseService {
|
||
/**
|
||
* 用户登录(统一认证接口)
|
||
* @param params 登录参数
|
||
*/
|
||
static login(params: LoginParams): Promise<BaseResponse<LoginData>> {
|
||
return this.post<BaseResponse<LoginData>>('/api/auth/login', params)
|
||
}
|
||
|
||
/**
|
||
* 退出登录(统一认证接口)
|
||
*/
|
||
static logout(): Promise<BaseResponse> {
|
||
return this.post<BaseResponse>('/api/auth/logout')
|
||
}
|
||
|
||
/**
|
||
* 获取当前用户信息(统一认证接口)
|
||
* GET /api/auth/me
|
||
*/
|
||
static getUserInfo(): Promise<BaseResponse<UserInfoResponse>> {
|
||
return this.get<BaseResponse<UserInfoResponse>>('/api/auth/me')
|
||
}
|
||
|
||
/**
|
||
* 刷新 Token(统一认证接口)
|
||
* @param params 刷新参数
|
||
*/
|
||
static refreshToken(params: RefreshTokenParams): Promise<BaseResponse<RefreshTokenData>> {
|
||
return this.post<BaseResponse<RefreshTokenData>>('/api/auth/refresh-token', params)
|
||
}
|
||
|
||
/**
|
||
* 修改密码(统一认证接口)
|
||
* @param params 修改密码参数
|
||
*/
|
||
static changePassword(params: ChangePasswordParams): Promise<BaseResponse> {
|
||
return this.put<BaseResponse>('/api/auth/password', params)
|
||
}
|
||
|
||
/**
|
||
* 获取验证码(如果需要)
|
||
*/
|
||
static getCaptcha(): Promise<BaseResponse<{ captchaId: string; captchaImage: string }>> {
|
||
return this.get<BaseResponse<{ captchaId: string; captchaImage: string }>>('/api/auth/captcha')
|
||
}
|
||
}
|