2024-08-07 08:57:56 +08:00
|
|
|
import { useAppConfig } from '@vben/hooks';
|
|
|
|
|
2024-07-28 14:29:05 +08:00
|
|
|
import { requestClient } from '#/api/request';
|
|
|
|
|
2024-08-07 08:57:56 +08:00
|
|
|
const { clientId } = useAppConfig(import.meta.env, import.meta.env.PROD);
|
|
|
|
|
2024-07-28 14:29:05 +08:00
|
|
|
export namespace AuthApi {
|
|
|
|
/** 登录接口参数 */
|
|
|
|
export interface LoginParams {
|
2024-08-07 08:57:56 +08:00
|
|
|
code?: string;
|
|
|
|
grantType: string;
|
2024-07-28 14:29:05 +08:00
|
|
|
password: string;
|
2024-08-07 08:57:56 +08:00
|
|
|
tenantId: string;
|
2024-07-28 14:29:05 +08:00
|
|
|
username: string;
|
2024-08-07 08:57:56 +08:00
|
|
|
uuid?: string;
|
2024-07-28 14:29:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** 登录接口返回值 */
|
|
|
|
export interface LoginResult {
|
2024-08-07 08:57:56 +08:00
|
|
|
access_token: string;
|
|
|
|
client_id: string;
|
|
|
|
expire_in: number;
|
2024-07-28 14:29:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 登录
|
|
|
|
*/
|
|
|
|
export async function login(data: AuthApi.LoginParams) {
|
2024-08-07 08:57:56 +08:00
|
|
|
return requestClient.post<AuthApi.LoginResult>(
|
|
|
|
'/auth/login',
|
|
|
|
{ ...data, clientId },
|
|
|
|
{
|
|
|
|
encrypt: true,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户登出
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
export function doLogout() {
|
|
|
|
return requestClient.post<void>('/auth/logout');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param companyName 租户/公司名称
|
|
|
|
* @param domain 绑定域名(不带http(s)://) 可选
|
|
|
|
* @param tenantId 租户id
|
|
|
|
*/
|
|
|
|
export interface TenantOption {
|
|
|
|
companyName: string;
|
|
|
|
domain?: string;
|
|
|
|
tenantId: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param tenantEnabled 是否启用租户
|
|
|
|
* @param voList 租户列表
|
|
|
|
*/
|
|
|
|
export interface TenantResp {
|
|
|
|
tenantEnabled: boolean;
|
|
|
|
voList: TenantOption[];
|
2024-07-28 14:29:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-08-07 08:57:56 +08:00
|
|
|
* 获取租户列表 下拉框使用
|
2024-07-28 14:29:05 +08:00
|
|
|
*/
|
2024-08-07 08:57:56 +08:00
|
|
|
export function tenantList() {
|
|
|
|
return requestClient.get<TenantResp>('/auth/tenant/list');
|
2024-07-28 14:29:05 +08:00
|
|
|
}
|