mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-25 13:51:04 +00:00
1. 调整后端模块路由与插件文件结构,迁移部分模块代码至api/v1目录 2. 优化代码注释格式与文档字符串,简化冗余代码 3. 添加监控仪表盘、工单评论等新模块功能 4. 修复前端部分组件交互逻辑与类型定义 5. 清理冗余的初始化数据与废弃配置文件 6. 新增租户注册表单字段与国际化支持 7. 优化HTTP请求拦截器与快捷键功能
194 lines
4.1 KiB
TypeScript
194 lines
4.1 KiB
TypeScript
import { request } from "@utils";
|
||
|
||
const API_PATH = "/system/auth";
|
||
|
||
/** 方案提供方 */
|
||
export type OAuthProvider = "wechat" | "qq" | "github" | "gitee";
|
||
|
||
const AuthAPI = {
|
||
/**
|
||
* 登录
|
||
* @param body 登录参数
|
||
* @returns 登录响应
|
||
*/
|
||
login(body: LoginFormData) {
|
||
return request<ApiResponse<LoginResult>>({
|
||
url: `${API_PATH}/login`,
|
||
method: "post",
|
||
headers: {
|
||
"Content-Type": "multipart/form-data",
|
||
},
|
||
data: body,
|
||
});
|
||
},
|
||
|
||
refreshToken(body: RefreshToekenBody) {
|
||
return request<ApiResponse<JWTOut>>({
|
||
url: `${API_PATH}/token/refresh`,
|
||
method: "post",
|
||
data: body,
|
||
});
|
||
},
|
||
|
||
getCaptcha() {
|
||
return request<ApiResponse<CaptchaInfo>>({
|
||
url: `${API_PATH}/captcha/get`,
|
||
method: "get",
|
||
});
|
||
},
|
||
|
||
logout(body: LogoutBody) {
|
||
return request<ApiResponse>({
|
||
url: `${API_PATH}/logout`,
|
||
method: "post",
|
||
data: body,
|
||
});
|
||
},
|
||
|
||
/** 获取当前用户的可选租户列表 */
|
||
getTenants() {
|
||
return request<ApiResponse<TenantOption[]>>({
|
||
url: `${API_PATH}/tenants`,
|
||
method: "get",
|
||
});
|
||
},
|
||
|
||
/** 选择租户,返回含 tenant_id 的新 JWT */
|
||
selectTenant(tenantId: number) {
|
||
return request<ApiResponse<SelectTenantResult>>({
|
||
url: `${API_PATH}/select-tenant`,
|
||
method: "post",
|
||
data: { tenant_id: tenantId },
|
||
});
|
||
},
|
||
|
||
/** 返回平台管理模式,清除 tenant_id 返回平台作用域 JWT */
|
||
enterPlatform() {
|
||
return request<ApiResponse<SelectTenantResult>>({
|
||
url: `${API_PATH}/enter-platform`,
|
||
method: "post",
|
||
});
|
||
},
|
||
|
||
/** 平台管理员代签入(以指定租户身份登录) */
|
||
impersonate(tenantId: number) {
|
||
return request<ApiResponse<ImpersonateResult>>({
|
||
url: `${API_PATH}/impersonate`,
|
||
method: "post",
|
||
data: { tenant_id: tenantId },
|
||
});
|
||
},
|
||
|
||
/** 租户自助注册(PRD §4.5) */
|
||
tenantRegister(body: TenantRegisterForm) {
|
||
return request<ApiResponse<TenantRegisterResult>>({
|
||
url: `${API_PATH}/tenant/register`,
|
||
method: "post",
|
||
data: body,
|
||
});
|
||
},
|
||
|
||
/** 根据编码查询租户 */
|
||
lookupTenant(code: string) {
|
||
return request<ApiResponse>({
|
||
url: `${API_PATH}/tenant/${encodeURIComponent(code)}`,
|
||
method: "get",
|
||
});
|
||
},
|
||
|
||
/** 根据域名查询租户 */
|
||
lookupTenantByDomain(domain: string) {
|
||
return request<ApiResponse>({
|
||
url: `${API_PATH}/tenant-by-domain`,
|
||
method: "get",
|
||
params: { domain },
|
||
});
|
||
},
|
||
};
|
||
|
||
export default AuthAPI;
|
||
|
||
export interface TenantRegisterForm {
|
||
username: string;
|
||
password: string;
|
||
email: string;
|
||
tenant_name?: string;
|
||
}
|
||
|
||
export interface TenantRegisterResult {
|
||
user_id: number;
|
||
username: string;
|
||
tenant_id: number;
|
||
tenant_name: string;
|
||
tenant_code: string;
|
||
package: string | null;
|
||
trial_end: string;
|
||
message: string;
|
||
}
|
||
|
||
// ─── Auth 类型定义 ───
|
||
|
||
/** 登录表单 */
|
||
export interface LoginFormData {
|
||
username: string;
|
||
password: string;
|
||
captcha?: string;
|
||
captcha_key?: string;
|
||
remember?: boolean;
|
||
login_type?: string;
|
||
}
|
||
|
||
/** JWT 响应 (JWTOutSchema) */
|
||
export interface JWTOut {
|
||
access_token: string;
|
||
refresh_token: string;
|
||
token_type: string;
|
||
expires_in: number;
|
||
}
|
||
|
||
/** 登录成功返回 */
|
||
export interface LoginResult extends JWTOut {
|
||
tenants?: TenantOption[];
|
||
}
|
||
|
||
/** 刷新 Token 请求体 */
|
||
export interface RefreshToekenBody {
|
||
refresh_token: string;
|
||
}
|
||
|
||
/** 退出登录请求体 */
|
||
export interface LogoutBody {
|
||
token: string;
|
||
}
|
||
|
||
/** 租户选项 */
|
||
export interface TenantOption {
|
||
id: number;
|
||
name: string;
|
||
code: string;
|
||
}
|
||
|
||
/** 选择租户返回 (SelectTenantOutSchema) */
|
||
export interface SelectTenantResult {
|
||
access_token: string;
|
||
token_type: string;
|
||
expires_in: number;
|
||
}
|
||
|
||
/** 平台管理员代签入返回 (ImpersonateOutSchema) */
|
||
export interface ImpersonateResult {
|
||
access_token: string;
|
||
refresh_token: string;
|
||
token_type: string;
|
||
expires_in: number;
|
||
tenant_id: number;
|
||
tenant_name: string;
|
||
}
|
||
|
||
/** 验证码信息 */
|
||
export interface CaptchaInfo {
|
||
enable: boolean;
|
||
key: string;
|
||
img_base: string;
|
||
}
|