refactor: 重构 API 层目录结构 & 样式模块化拆分
- API 层按业务域拆分(api/auth/, api/file/, api/system/*) - 类型定义从 types/api/ 移入对应 api 模块内(就近原则) - 公共类型统一为 api/common.ts,移除冗余类型重导出 - 样式文件按职责拆分(base/, layout/, vendors/),移除 common.scss - 移除失效的单元测试文件
This commit is contained in:
69
src/api/auth/index.ts
Normal file
69
src/api/auth/index.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import request from "@/utils/request";
|
||||
import type { LoginRequest, LoginResponse, CaptchaInfo } from "./types";
|
||||
|
||||
const AUTH_BASE_URL = "/api/v1/auth";
|
||||
|
||||
const AuthAPI = {
|
||||
/** 登录接口*/
|
||||
login(data: LoginRequest) {
|
||||
const payload: Record<string, any> = {
|
||||
username: data.username,
|
||||
password: data.password,
|
||||
captchaId: data.captchaId,
|
||||
captchaCode: data.captchaCode,
|
||||
};
|
||||
|
||||
// tenantId 可选,仅在提供时包含(多租户功能)
|
||||
if (typeof data.tenantId !== "undefined") {
|
||||
payload.tenantId = data.tenantId;
|
||||
}
|
||||
|
||||
return request<any, LoginResponse>({
|
||||
url: `${AUTH_BASE_URL}/login`,
|
||||
method: "post",
|
||||
data: payload,
|
||||
});
|
||||
},
|
||||
|
||||
/** 切换租户(平台用户) - 返回新的 token */
|
||||
switchTenant(tenantId: number) {
|
||||
return request<any, LoginResponse>({
|
||||
url: `${AUTH_BASE_URL}/switch-tenant`,
|
||||
method: "post",
|
||||
params: { tenantId },
|
||||
});
|
||||
},
|
||||
|
||||
/** 刷新 token 接口*/
|
||||
refreshToken(refreshToken: string) {
|
||||
return request<any, LoginResponse>({
|
||||
url: `${AUTH_BASE_URL}/refresh-token`,
|
||||
method: "post",
|
||||
params: { refreshToken },
|
||||
headers: {
|
||||
Authorization: "no-auth",
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
/** 退出登录接口 */
|
||||
logout() {
|
||||
return request({
|
||||
url: `${AUTH_BASE_URL}/logout`,
|
||||
method: "delete",
|
||||
});
|
||||
},
|
||||
|
||||
/** 获取验证码接口*/
|
||||
getCaptcha() {
|
||||
return request<any, CaptchaInfo>({
|
||||
url: `${AUTH_BASE_URL}/captcha`,
|
||||
method: "get",
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export default AuthAPI;
|
||||
|
||||
// 重导出类型
|
||||
export * from "./types";
|
||||
45
src/api/auth/types.ts
Normal file
45
src/api/auth/types.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* 认证相关类型定义
|
||||
*/
|
||||
|
||||
/**
|
||||
* 登录请求参数
|
||||
*/
|
||||
export interface LoginRequest {
|
||||
/** 用户名 */
|
||||
username: string;
|
||||
/** 密码 */
|
||||
password: string;
|
||||
/** 验证码缓存key */
|
||||
captchaId?: string;
|
||||
/** 验证码 */
|
||||
captchaCode?: string;
|
||||
/** 记住我 */
|
||||
rememberMe?: boolean;
|
||||
/** 租户ID */
|
||||
tenantId?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录响应
|
||||
*/
|
||||
export interface LoginResponse {
|
||||
/** 访问令牌 */
|
||||
accessToken: string;
|
||||
/** 刷新令牌 */
|
||||
refreshToken: string;
|
||||
/** 令牌类型 */
|
||||
tokenType: string;
|
||||
/** 过期时间(单位:秒) */
|
||||
expiresIn: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证码响应
|
||||
*/
|
||||
export interface CaptchaInfo {
|
||||
/** 验证码缓存key */
|
||||
captchaId: string;
|
||||
/** 验证码图片Base64 */
|
||||
captchaBase64: string;
|
||||
}
|
||||
Reference in New Issue
Block a user