refactor(codegen): 代码生成API模板的接口定义方式和文件路径添加模块

This commit is contained in:
Ray.Hao
2024-10-25 18:16:46 +08:00
parent 3de3417d14
commit 4005bafbc8
2 changed files with 15 additions and 12 deletions

View File

@@ -173,11 +173,14 @@ public class CodegenServiceImpl implements CodegenService {
+ File.separator + subPackageName + File.separator + subPackageName
); );
} else if ("API".equals(templateName)) { } else if ("API".equals(templateName)) {
// path = "src/api/system";
path = (codegenProperties.getFrontendAppName() path = (codegenProperties.getFrontendAppName()
+ File.separator + File.separator + "src"
+ "src" + File.separator + subPackageName + File.separator + subPackageName
+ File.separator + moduleName
); );
} else if ("VIEW".equals(templateName)) { } else if ("VIEW".equals(templateName)) {
// path = "src/views/system/user";
path = (codegenProperties.getFrontendAppName() path = (codegenProperties.getFrontendAppName()
+ File.separator + "src" + File.separator + "src"
+ File.separator + subPackageName + File.separator + subPackageName

View File

@@ -2,36 +2,36 @@ import request from "@/utils/request";
const ${entityName.toUpperCase()}_BASE_URL = "/api/v1/${lowerFirstEntityName}s"; const ${entityName.toUpperCase()}_BASE_URL = "/api/v1/${lowerFirstEntityName}s";
class ${entityName}API { const ${entityName}API = {
/** 获取${businessName}分页数据 */ /** 获取${businessName}分页数据 */
static getPage(queryParams?: ${entityName}PageQuery) { getPage(queryParams?: ${entityName}PageQuery) {
return request<any, PageResult<${entityName}PageVO[]>>({ return request<any, PageResult<${entityName}PageVO[]>>({
url: `${${entityName.toUpperCase()}_BASE_URL}/page`, url: `${${entityName.toUpperCase()}_BASE_URL}/page`,
method: "get", method: "get",
params: queryParams, params: queryParams,
}); });
} },
/** /**
* 获取${businessName}表单数据 * 获取${businessName}表单数据
* *
* @param id ${entityName}ID * @param id ${entityName}ID
* @returns ${entityName}表单数据 * @returns ${entityName}表单数据
*/ */
static getFormData(id: number) { getFormData(id: number) {
return request<any, ${entityName}Form>({ return request<any, ${entityName}Form>({
url: `${${entityName.toUpperCase()}_BASE_URL}/${id}/form`, url: `${${entityName.toUpperCase()}_BASE_URL}/${id}/form`,
method: "get", method: "get",
}); });
} },
/** 添加${businessName}*/ /** 添加${businessName}*/
static add(data: ${entityName}Form) { add(data: ${entityName}Form) {
return request({ return request({
url: `${${entityName.toUpperCase()}_BASE_URL}`, url: `${${entityName.toUpperCase()}_BASE_URL}`,
method: "post", method: "post",
data: data, data: data,
}); });
} },
/** /**
* 更新${businessName} * 更新${businessName}
@@ -39,20 +39,20 @@ class ${entityName}API {
* @param id ${entityName}ID * @param id ${entityName}ID
* @param data ${entityName}表单数据 * @param data ${entityName}表单数据
*/ */
static update(id: number, data: ${entityName}Form) { update(id: number, data: ${entityName}Form) {
return request({ return request({
url: `${${entityName.toUpperCase()}_BASE_URL}/${id}`, url: `${${entityName.toUpperCase()}_BASE_URL}/${id}`,
method: "put", method: "put",
data: data, data: data,
}); });
} },
/** /**
* 批量删除${businessName},多个以英文逗号(,)分割 * 批量删除${businessName},多个以英文逗号(,)分割
* *
* @param ids ${businessName}ID字符串多个以英文逗号(,)分割 * @param ids ${businessName}ID字符串多个以英文逗号(,)分割
*/ */
static deleteByIds(ids: string) { deleteByIds(ids: string) {
return request({ return request({
url: `${${entityName.toUpperCase()}_BASE_URL}/${ids}`, url: `${${entityName.toUpperCase()}_BASE_URL}/${ids}`,
method: "delete", method: "delete",