72 lines
1.7 KiB
TypeScript
72 lines
1.7 KiB
TypeScript
|
|
/**
|
||
|
|
* @description 认证相关API
|
||
|
|
* @author yslg
|
||
|
|
* @since 2025-10-06
|
||
|
|
*/
|
||
|
|
|
||
|
|
import { api } from './index';
|
||
|
|
import type { LoginParam, LoginDomain } from '@/types';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 认证API服务
|
||
|
|
*/
|
||
|
|
export const authApi = {
|
||
|
|
/**
|
||
|
|
* 用户登录
|
||
|
|
* @param loginParam 登录参数
|
||
|
|
* @returns Promise<LoginDomain>
|
||
|
|
*/
|
||
|
|
async login(loginParam: LoginParam): Promise<LoginDomain> {
|
||
|
|
const response = await api.post<LoginDomain>('/auth/login', loginParam);
|
||
|
|
return response.data.data!;
|
||
|
|
},
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 用户登出
|
||
|
|
* @returns Promise<string>
|
||
|
|
*/
|
||
|
|
async logout(): Promise<string> {
|
||
|
|
const response = await api.post<string>('/auth/logout');
|
||
|
|
return response.data.data!;
|
||
|
|
},
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 获取验证码
|
||
|
|
* @returns Promise<{captchaId: string, captchaImage: string}>
|
||
|
|
*/
|
||
|
|
async getCaptcha(): Promise<{ captchaId: string; captchaImage: string }> {
|
||
|
|
const response = await api.get<{ captchaId: string; captchaImage: string }>('/auth/captcha');
|
||
|
|
return response.data.data!;
|
||
|
|
},
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 刷新Token
|
||
|
|
* @returns Promise<string>
|
||
|
|
*/
|
||
|
|
async refreshToken(): Promise<string> {
|
||
|
|
const response = await api.post<string>('/auth/refresh-token');
|
||
|
|
return response.data.data!;
|
||
|
|
},
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 发送手机验证码
|
||
|
|
* @param phone 手机号
|
||
|
|
* @returns Promise<boolean>
|
||
|
|
*/
|
||
|
|
async sendSmsCode(phone: string): Promise<boolean> {
|
||
|
|
const response = await api.post<boolean>('/auth/send-sms-code', { phone });
|
||
|
|
return response.data.data!;
|
||
|
|
},
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 发送邮箱验证码
|
||
|
|
* @param email 邮箱
|
||
|
|
* @returns Promise<boolean>
|
||
|
|
*/
|
||
|
|
async sendEmailCode(email: string): Promise<boolean> {
|
||
|
|
const response = await api.post<boolean>('/auth/send-email-code', { email });
|
||
|
|
return response.data.data!;
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|