2024-08-19 22:59:42 +08:00
|
|
|
|
import { baseRequestClient, requestClient } from '#/api/request';
|
2025-03-20 12:34:02 +08:00
|
|
|
|
import type { AuthPermissionInfo } from '@vben/types';
|
2024-07-28 14:29:05 +08:00
|
|
|
|
|
|
|
|
|
|
export namespace AuthApi {
|
|
|
|
|
|
/** 登录接口参数 */
|
|
|
|
|
|
export interface LoginParams {
|
2024-10-05 17:09:42 +08:00
|
|
|
|
password?: string;
|
|
|
|
|
|
username?: string;
|
2025-03-20 12:34:02 +08:00
|
|
|
|
captchaVerification?: string;
|
2024-07-28 14:29:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 登录接口返回值 */
|
|
|
|
|
|
export interface LoginResult {
|
|
|
|
|
|
accessToken: string;
|
2025-03-20 12:34:02 +08:00
|
|
|
|
refreshToken: string;
|
|
|
|
|
|
userId: number;
|
|
|
|
|
|
expiresTime: number;
|
2024-07-28 14:29:05 +08:00
|
|
|
|
}
|
2024-08-19 22:59:42 +08:00
|
|
|
|
|
2025-03-24 21:35:59 +08:00
|
|
|
|
/** 刷新 token 返回值 */
|
2024-08-19 22:59:42 +08:00
|
|
|
|
export interface RefreshTokenResult {
|
|
|
|
|
|
data: string;
|
|
|
|
|
|
status: number;
|
|
|
|
|
|
}
|
2025-03-20 23:12:55 +08:00
|
|
|
|
|
|
|
|
|
|
/** 租户信息返回值 */
|
|
|
|
|
|
export interface TenantResult {
|
|
|
|
|
|
id: number;
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-24 21:35:59 +08:00
|
|
|
|
/** 手机验证码获取接口参数 */
|
|
|
|
|
|
export interface SmsCodeVO {
|
|
|
|
|
|
mobile: string;
|
|
|
|
|
|
scene: number;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 手机验证码登录接口参数 */
|
|
|
|
|
|
export interface SmsLoginVO {
|
|
|
|
|
|
mobile: string;
|
|
|
|
|
|
code: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-28 14:29:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-24 20:11:44 +08:00
|
|
|
|
/** 登录 */
|
2024-08-07 13:42:33 +08:00
|
|
|
|
export async function loginApi(data: AuthApi.LoginParams) {
|
2025-03-20 12:34:02 +08:00
|
|
|
|
return requestClient.post<AuthApi.LoginResult>('/system/auth/login', data);
|
2024-07-28 14:29:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-24 20:11:44 +08:00
|
|
|
|
/** 刷新 accessToken */
|
2024-08-19 22:59:42 +08:00
|
|
|
|
export async function refreshTokenApi() {
|
2025-03-20 23:12:55 +08:00
|
|
|
|
// TODO @芋艿:refreshToken 传递
|
|
|
|
|
|
return baseRequestClient.post<AuthApi.RefreshTokenResult>('/system/auth/refresh', {
|
2024-08-19 22:59:42 +08:00
|
|
|
|
withCredentials: true,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-24 20:11:44 +08:00
|
|
|
|
/** 退出登录 */
|
2024-08-19 22:59:42 +08:00
|
|
|
|
export async function logoutApi() {
|
2025-03-20 23:12:55 +08:00
|
|
|
|
return baseRequestClient.post('/system/auth/logout', {
|
2024-08-28 22:37:47 +08:00
|
|
|
|
withCredentials: true,
|
|
|
|
|
|
});
|
2024-08-19 22:59:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-24 20:11:44 +08:00
|
|
|
|
/** 获取权限信息 */
|
2025-03-26 07:36:12 +08:00
|
|
|
|
export async function getAuthPermissionInfoApi() {
|
2025-03-20 12:34:02 +08:00
|
|
|
|
return requestClient.get<AuthPermissionInfo>(
|
|
|
|
|
|
'/system/auth/get-permission-info',
|
|
|
|
|
|
);
|
2025-03-20 23:12:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-24 20:11:44 +08:00
|
|
|
|
/** 获取租户列表 */
|
2025-03-26 07:36:12 +08:00
|
|
|
|
export async function getTenantSimpleList() {
|
2025-03-20 23:12:55 +08:00
|
|
|
|
return requestClient.get<AuthApi.TenantResult[]>(
|
|
|
|
|
|
`/system/tenant/simple-list`,
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-24 20:11:44 +08:00
|
|
|
|
/** 使用租户域名,获得租户信息 */
|
2025-03-26 07:36:12 +08:00
|
|
|
|
export async function getTenantByWebsite(website: string) {
|
2025-03-20 23:12:55 +08:00
|
|
|
|
return requestClient.get<AuthApi.TenantResult>(`/system/tenant/get-by-website?website=${website}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-24 20:11:44 +08:00
|
|
|
|
/** 获取验证码 */
|
|
|
|
|
|
export async function getCaptcha(data: any) {
|
|
|
|
|
|
return baseRequestClient.post('/system/captcha/get', data);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 校验验证码 */
|
|
|
|
|
|
export async function checkCaptcha(data: any) {
|
|
|
|
|
|
return baseRequestClient.post('/system/captcha/check', data);
|
|
|
|
|
|
}
|