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:
Ray.Hao
2026-03-30 08:11:03 +08:00
parent 3a27da6607
commit 3fedf4943d
107 changed files with 464 additions and 8264 deletions

105
src/api/codegen/index.ts Normal file
View File

@@ -0,0 +1,105 @@
import request from "@/utils/request";
import type { GeneratorPreviewItem, TableQueryParams, TableItem, GenConfigForm } from "./types";
const GENERATOR_BASE_URL = "/api/v1/codegen";
const GeneratorAPI = {
/** 获取数据表分页列表 */
getTablePage(params: TableQueryParams) {
return request<any, PageResult<TableItem>>({
url: `${GENERATOR_BASE_URL}/table`,
method: "get",
params,
});
},
/** 获取代码生成配置 */
getGenConfig(tableName: string) {
return request<any, GenConfigForm>({
url: `${GENERATOR_BASE_URL}/${tableName}/config`,
method: "get",
});
},
/** 获取代码生成配置 */
saveGenConfig(tableName: string, data: GenConfigForm) {
return request({
url: `${GENERATOR_BASE_URL}/${tableName}/config`,
method: "post",
data,
});
},
/** 获取代码生成预览数据 */
getPreviewData(tableName: string, pageType?: "classic" | "curd", type?: "ts" | "js") {
const params: Record<string, string> = {};
if (pageType) {
params.pageType = pageType;
}
if (type) {
params.type = type;
}
return request<any, GeneratorPreviewItem[]>({
url: `${GENERATOR_BASE_URL}/${tableName}/preview`,
method: "get",
params: Object.keys(params).length ? params : undefined,
});
},
/** 重置代码生成配置 */
resetGenConfig(tableName: string) {
return request({
url: `${GENERATOR_BASE_URL}/${tableName}/config`,
method: "delete",
});
},
/**
* 下载 ZIP 文件
* @param url
* @param fileName
*/
download(tableName: string, pageType?: "classic" | "curd", type?: "ts" | "js") {
const params: Record<string, string> = {};
if (pageType) {
params.pageType = pageType;
}
if (type) {
params.type = type;
}
return request({
url: `${GENERATOR_BASE_URL}/${tableName}/download`,
method: "get",
params: Object.keys(params).length ? params : undefined,
responseType: "blob",
}).then((response) => {
const contentDisposition = response?.headers?.["content-disposition"] as string | undefined;
let fileName = `${tableName}.zip`;
if (contentDisposition) {
// content-disposition: attachment; filename=xxx.zip
const match = /filename\*?=(?:UTF-8''|")?([^;"]+)/i.exec(contentDisposition);
if (match?.[1]) {
try {
fileName = decodeURIComponent(match[1]);
} catch {
fileName = match[1];
}
}
}
const blob = new Blob([response.data], { type: "application/zip" });
const a = document.createElement("a");
const url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(url);
});
},
};
export default GeneratorAPI;
// 重导出类型
export * from "./types";

105
src/api/codegen/types.ts Normal file
View File

@@ -0,0 +1,105 @@
/**
* CodeGen 代码生成类型定义
*/
import type { BaseQueryParams } from "@/api/common";
/** 代码生成预览对象 */
export interface GeneratorPreviewItem {
/** 文件生成路径 */
path: string;
/** 文件名称 */
fileName: string;
/** 文件内容 */
content: string;
/** 文件范围(frontend/backend) */
scope: "frontend" | "backend";
/** 文件语言(扩展名) */
language: string;
}
/** 数据表分页查询参数 */
export interface TableQueryParams extends BaseQueryParams {
/** 搜索关键字(表名) */
keywords?: string;
}
/** 数据表分页对象 */
export interface TableItem {
/** 表名称 */
tableName: string;
/** 表描述 */
tableComment: string;
/** 是否已配置(1:是;0:否) */
isConfigured?: number;
/** 存储引擎 */
engine: string;
/** 字符集排序规则 */
tableCollation: string;
/** 创建时间 */
createTime: string;
}
/** 代码生成配置表单 */
export interface GenConfigForm {
/** 主键 */
id?: string;
/** 表名 */
tableName?: string;
/** 业务名 */
businessName?: string;
/** 模块名 */
moduleName?: string;
/** 包名 */
packageName?: string;
/** 实体名 */
entityName?: string;
/** 作者 */
author?: string;
/** 上级菜单 */
parentMenuId?: string;
/** 后端应用名 */
backendAppName?: string;
/** 前端应用名 */
frontendAppName?: string;
/** 字段配置列表 */
fieldConfigs?: FieldConfig[];
/** 页面类型 classic|curd */
pageType?: "classic" | "curd";
/** 要移除的表前缀,如 sys_ */
removeTablePrefix?: string;
}
/** 字段配置 */
export interface FieldConfig {
/** 主键 */
id?: string;
/** 列名 */
columnName?: string;
/** 列类型 */
columnType?: string;
/** 字段名 */
fieldName?: string;
/** 字段类型 */
fieldType?: string;
/** 字段描述 */
fieldComment?: string;
/** 是否在列表显示 */
isShowInList?: number;
/** 是否在表单显示 */
isShowInForm?: number;
/** 是否在查询条件显示 */
isShowInQuery?: number;
/** 是否必填 */
isRequired?: number;
/** 表单类型 */
formType?: number;
/** 查询类型 */
queryType?: number;
/** 字段长度 */
maxLength?: number;
/** 字段排序 */
fieldSort?: number;
/** 字典类型 */
dictType?: string;
}