82 lines
2.4 KiB
TypeScript
82 lines
2.4 KiB
TypeScript
import { request } from './request';
|
|
import type { ApiResponse } from '@/types/common';
|
|
|
|
// 登录响应数据类型
|
|
export interface LoginResponse {
|
|
token: string;
|
|
token_expired: string;
|
|
member: {
|
|
id: number;
|
|
username: string;
|
|
account: string;
|
|
avatar?: string;
|
|
s2_accountId: string;
|
|
};
|
|
}
|
|
|
|
// 验证码响应类型
|
|
export interface VerificationCodeResponse {
|
|
code: string;
|
|
expire_time: string;
|
|
}
|
|
|
|
// 认证相关API
|
|
export const authApi = {
|
|
// 账号密码登录
|
|
login: async (account: string, password: string) => {
|
|
const response = await request.post<ApiResponse<LoginResponse>>('/v1/auth/login', {
|
|
account,
|
|
password,
|
|
typeId: 1 // 默认使用用户类型1
|
|
});
|
|
return response as unknown as ApiResponse<LoginResponse>;
|
|
},
|
|
|
|
// 验证码登录
|
|
loginWithCode: async (account: string, code: string) => {
|
|
const response = await request.post<ApiResponse<LoginResponse>>('/v1/auth/login/code', {
|
|
account,
|
|
code,
|
|
typeId: 1
|
|
});
|
|
return response as unknown as ApiResponse<LoginResponse>;
|
|
},
|
|
|
|
// 发送验证码
|
|
sendVerificationCode: async (account: string) => {
|
|
const response = await request.post<ApiResponse<VerificationCodeResponse>>('/v1/auth/send-code', {
|
|
account,
|
|
type: 'login' // 登录验证码
|
|
});
|
|
return response as unknown as ApiResponse<VerificationCodeResponse>;
|
|
},
|
|
|
|
// 获取用户信息
|
|
getUserInfo: async () => {
|
|
const response = await request.get<ApiResponse<any>>('/v1/auth/info');
|
|
return response as unknown as ApiResponse<any>;
|
|
},
|
|
|
|
// 刷新Token
|
|
refreshToken: async () => {
|
|
const response = await request.post<ApiResponse<{ token: string; token_expired: string }>>('/v1/auth/refresh', {});
|
|
return response as unknown as ApiResponse<{ token: string; token_expired: string }>;
|
|
},
|
|
|
|
// 微信登录
|
|
wechatLogin: async (code: string) => {
|
|
const response = await request.post<ApiResponse<LoginResponse>>('/v1/auth/wechat', {
|
|
code
|
|
});
|
|
return response as unknown as ApiResponse<LoginResponse>;
|
|
},
|
|
|
|
// Apple登录
|
|
appleLogin: async (identityToken: string, authorizationCode: string) => {
|
|
const response = await request.post<ApiResponse<LoginResponse>>('/v1/auth/apple', {
|
|
identity_token: identityToken,
|
|
authorization_code: authorizationCode
|
|
});
|
|
return response as unknown as ApiResponse<LoginResponse>;
|
|
},
|
|
};
|