增加额外的 api_build

增加选择生成接口模式
This commit is contained in:
Master 2024-07-10 10:26:55 +08:00
parent 9946502355
commit 1186e6acf3
16 changed files with 1551 additions and 1310 deletions

View File

@ -122,4 +122,10 @@ public partial class SysCodeGen : EntityBase
[SugarColumn(ColumnDescription = "打印模版名称", Length = 32)] [SugarColumn(ColumnDescription = "打印模版名称", Length = 32)]
[MaxLength(32)] [MaxLength(32)]
public string? PrintName { get; set; } public string? PrintName { get; set; }
/// <summary>
/// 是否使用 Api Service
/// </summary>
[SugarColumn(ColumnDescription = "是否使用 Api Service")]
public bool IsApiService { get; set; } = false;
} }

View File

@ -52,6 +52,8 @@ public class CustomViewEngine : ViewEngineModel
public string PrintName { get; set; } public string PrintName { get; set; }
public bool IsApiService { get; set; }
public List<CodeGenConfig> QueryWhetherList { get; set; } public List<CodeGenConfig> QueryWhetherList { get; set; }
public List<CodeGenConfig> TableField { get; set; } public List<CodeGenConfig> TableField { get; set; }

View File

@ -100,6 +100,11 @@ public class CodeGenInput : BasePageInput
/// 打印模版名称 /// 打印模版名称
/// </summary> /// </summary>
public virtual string PrintName { get; set; } public virtual string PrintName { get; set; }
/// <summary>
/// 是否使用 Api Service
/// </summary>
public virtual bool IsApiService { get; set; }
} }
public class AddCodeGenInput : CodeGenInput public class AddCodeGenInput : CodeGenInput
@ -157,6 +162,11 @@ public class AddCodeGenInput : CodeGenInput
/// </summary> /// </summary>
[Required(ErrorMessage = "是否生成菜单不能为空")] [Required(ErrorMessage = "是否生成菜单不能为空")]
public override bool GenerateMenu { get; set; } public override bool GenerateMenu { get; set; }
/// <summary>
/// 是否使用 Api Service
/// </summary>
public override bool IsApiService { get; set; }
} }
public class DeleteCodeGenInput public class DeleteCodeGenInput

View File

@ -80,4 +80,9 @@ public class CodeGenOutput
/// 打印模版名称 /// 打印模版名称
/// </summary> /// </summary>
public string PrintName { get; set; } public string PrintName { get; set; }
/// <summary>
/// 是否使用 Api Service
/// </summary>
public bool IsApiService { get; set; }
} }

View File

@ -347,6 +347,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient
IsUpload = joinTableList.Where(u => u.EffectType == "Upload").Any(), IsUpload = joinTableList.Where(u => u.EffectType == "Upload").Any(),
PrintType = input.PrintType, PrintType = input.PrintType,
PrintName = input.PrintName, PrintName = input.PrintName,
IsApiService = input.IsApiService
}; };
// 模板目录 // 模板目录
var templatePathList = GetTemplatePathList(input); var templatePathList = GetTemplatePathList(input);
@ -412,6 +413,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient
IsUpload = joinTableList.Where(u => u.EffectType == "Upload").Any(), IsUpload = joinTableList.Where(u => u.EffectType == "Upload").Any(),
PrintType = input.PrintType, PrintType = input.PrintType,
PrintName = input.PrintName, PrintName = input.PrintName,
IsApiService = input.IsApiService
}; };
// 获取模板文件并替换 // 获取模板文件并替换

View File

@ -169,16 +169,24 @@
import { ref,onMounted, reactive } from "vue"; import { ref,onMounted, reactive } from "vue";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import type { FormRules } from "element-plus"; import type { FormRules } from "element-plus";
@if (@Model.IsApiService) {
// 接口函数 // 接口函数
import { getAPI } from '/@@/utils/axios-utils'; @:import { getAPI } from '/@@/utils/axios-utils';
// 接口 // 接口
import { @(@Model.ClassName)Api } from '/@@/api-services/api'; @:import { @(@Model.ClassName)Api } from '/@@/api-services/api';
// 模型 // 模型
import { Update@(@Model.ClassName)Input } from '/@@/api-services/models'; @:import { Update@(@Model.ClassName)Input } from '/@@/api-services/models';
} else {
@:import { add@(@Model.ClassName), update@(@Model.ClassName), detail@(@Model.ClassName) } from "/@@/api/@(@Model.PagePath)/@(@Model.LowerClassName)";
if(@Model.TableField.Any(x=>x.EffectType == "Upload")){
@:import { Plus } from "@@element-plus/icons-vue";
@:import { UploadRequestOptions } from "element-plus";
@:import {@string.Join(",",Model.TableField.Where(x=>x.EffectType == "Upload").Select(x=>"upload"+x.PropertyName).ToList())} from '/@@/api/@(@Model.PagePath)/@(@Model.LowerClassName)';
}
}
@if(@Model.TableField.Any(x=>x.EffectType == "ConstSelector")){ @if(@Model.TableField.Any(x=>x.EffectType == "ConstSelector")){
@:import { getConstType } from "/@@/utils/constHelper"; @:import { getConstType } from "/@@/utils/constHelper";
@ -244,8 +252,11 @@
// 改用detail获取最新数据来编辑 // 改用detail获取最新数据来编辑
let rowData = JSON.parse(JSON.stringify(row)); let rowData = JSON.parse(JSON.stringify(row));
if (rowData.id) if (rowData.id)
//state.ruleForm = (await detail@(@Model.ClassName)(rowData.id)).data.result; @if (@Model.IsApiService) {
state.ruleForm = (await getAPI(@(@Model.ClassName)Api).api@(@Model.ClassName)DetailGet(rowData.id)).data.result; @:state.ruleForm = (await getAPI(@(@Model.ClassName)Api).api@(@Model.ClassName)DetailGet(rowData.id)).data.result;
} else {
@:state.ruleForm = (await detail@(@Model.ClassName)(rowData.id)).data.result;
}
else else
state.ruleForm = rowData; state.ruleForm = rowData;
state.isShowDialog = true; state.isShowDialog = true;
@ -268,11 +279,17 @@
if (isValid) { if (isValid) {
let values = state.ruleForm; let values = state.ruleForm;
if (state.ruleForm.@(@pkFieldName) == undefined || state.ruleForm.@(@pkFieldName) == null || state.ruleForm.@(@pkFieldName) == "" || state.ruleForm.@(@pkFieldName) == 0) { if (state.ruleForm.@(@pkFieldName) == undefined || state.ruleForm.@(@pkFieldName) == null || state.ruleForm.@(@pkFieldName) == "" || state.ruleForm.@(@pkFieldName) == 0) {
//await add@(@Model.ClassName)(values); @if (@Model.IsApiService) {
await getAPI(@(@Model.ClassName)Api).api@(@Model.ClassName)AddPost(state.ruleForm); @:await getAPI(@(@Model.ClassName)Api).api@(@Model.ClassName)AddPost(state.ruleForm);
} else { } else {
//await update@(@Model.ClassName)(values); @:await add@(@Model.ClassName)(values);
await getAPI(@(@Model.ClassName)Api).api@(@Model.ClassName)UpdatePost(state.ruleForm); }
} else {
@if (@Model.IsApiService) {
@:await getAPI(@(@Model.ClassName)Api).api@(@Model.ClassName)UpdatePost(state.ruleForm);
} else {
@:await update@(@Model.ClassName)(values);
}
} }
closeDialog(); closeDialog();
} else { } else {
@ -324,7 +341,11 @@
if(column.WhetherAddUpdate=="N") continue; if(column.WhetherAddUpdate=="N") continue;
if(@column.EffectType == "Upload"){ if(@column.EffectType == "Upload"){
@:const upload@(@column.PropertyName)Handle = async (options: UploadRequestOptions) => { @:const upload@(@column.PropertyName)Handle = async (options: UploadRequestOptions) => {
@if (@Model.IsApiService) {
@:let list = await getAPI(@(@Model.ClassName)Api).api@(@Model.ClassName)Upload@(@column.FkEntityName)PostForm(options); @:let list = await getAPI(@(@Model.ClassName)Api).api@(@Model.ClassName)Upload@(@column.FkEntityName)PostForm(options);
} else {
@:let list = await upload@(@column.PropertyName)(options);
}
@:state.ruleForm.@(column.LowerPropertyName) = res.data.result?.url; @:state.ruleForm.@(column.LowerPropertyName) = res.data.result?.url;
@:}; @:};
} }

View File

@ -225,6 +225,7 @@ import PrintDialog from '/@@/views/system/print/component/hiprint/preview.vue';
import EditDialog from '/@@/views/@(@Model.PagePath)/@(@Model.LowerClassName)/component/editDialog.vue'; import EditDialog from '/@@/views/@(@Model.PagePath)/@(@Model.LowerClassName)/component/editDialog.vue';
import ModifyRecord from '/@@/components/table/modifyRecord.vue'; import ModifyRecord from '/@@/components/table/modifyRecord.vue';
@if (@Model.IsApiService) {
// 接口函数 // 接口函数
import { getAPI } from '/@@/utils/axios-utils'; import { getAPI } from '/@@/utils/axios-utils';
@ -234,6 +235,15 @@ import { @(@Model.ClassName)Api } from '/@@/api-services/api';
// 模型 // 模型
import { @(@Model.ClassName), @(@Model.ClassName)Input, @(@Model.ClassName)Output } from '/@@/api-services/models'; import { @(@Model.ClassName), @(@Model.ClassName)Input, @(@Model.ClassName)Output } from '/@@/api-services/models';
} else {
@:import { page@(@Model.EntityName), delete@(@Model.EntityName) } from '/@@/api/@(@Model.PagePath)/@(@Model.LowerEntityName)';
foreach (var column in Model.QueryWhetherList){
if(@column.EffectType == "fk"){
@:import { get@(@column.FkEntityName)@(@column.PropertyName)Dropdown } from '/@@/api/@(@Model.PagePath)/@(@Model.LowerEntityName)';
}
}
}
// 子窗口对象 // 子窗口对象
const xGrid = ref<VxeGridInstance>(); const xGrid = ref<VxeGridInstance>();
const printDialogRef = ref<InstanceType<typeof PrintDialog>>(); const printDialogRef = ref<InstanceType<typeof PrintDialog>>();
@ -325,7 +335,11 @@ const handleQuery = async (reset = false) => {
// 获取数据 // 获取数据
const fetchData = async (tableParams: any) => { const fetchData = async (tableParams: any) => {
let params = Object.assign(state.queryParams, state.tableParams, tableParams); let params = Object.assign(state.queryParams, state.tableParams, tableParams);
return getAPI(@(@Model.ClassName)Api).api@(@Model.ClassName)PagePost(params); @if (@Model.IsApiService) {
@:return getAPI(@(@Model.ClassName)Api).api@(@Model.ClassName)PagePost(params);
} else {
@:return page@(@Model.ClassName)(params);
}
}; };
// 重置操作 // 重置操作
@ -369,7 +383,11 @@ const handleEdit = (row: any) => {
const handlePrint = async (row: any) => { const handlePrint = async (row: any) => {
state.title = '打印@(@Model.BusName)'; state.title = '打印@(@Model.BusName)';
@if(@Model.PrintType == "custom"){ @if(@Model.PrintType == "custom"){
if (@Model.IsApiService) {
@:var res = await getAPI(SysPrintApi).apiSysPrintPrintNameGet('@Model.PrintName'); @:var res = await getAPI(SysPrintApi).apiSysPrintPrintNameGet('@Model.PrintName');
} else {
@:var res = await getPrint@(@Model.ClassName)(row);
}
@:var printTemplate = res.data.result as SysPrint; @:var printTemplate = res.data.result as SysPrint;
@:var template = JSON.parse(printTemplate.template); @:var template = JSON.parse(printTemplate.template);
@:var width = template.panels[0].width; @:var width = template.panels[0].width;
@ -390,7 +408,11 @@ const handleDelete = (row: any) => {
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning', type: 'warning',
}).then(async () => { }).then(async () => {
await getAPI(@(@Model.ClassName)Api).api@(@Model.ClassName)DeletePost({ id: row.id }); @if (@Model.IsApiService) {
@:await getAPI(@(@Model.ClassName)Api).api@(@Model.ClassName)DeletePost({ id: row.id });
} else {
@:await delete@(@Model.ClassName)(row);
}
handleQuery(); handleQuery();
ElMessage.success('删除成功'); ElMessage.success('删除成功');
}) })

View File

@ -12,7 +12,7 @@ if exist %apiServicesPath% (
echo ================================ 开始生成 api-services ================================ echo ================================ 开始生成 api-services ================================
java -jar %dir%swagger-codegen-cli.jar generate -i http://localhost:5005/swagger/All%%20Groups/swagger.json -l typescript-axios -o %apiServicesPath% java -jar %dir%swagger-codegen-cli.jar generate -i http://localhost:5005/swagger/Default/swagger.json -l typescript-axios -o %apiServicesPath%
@rem 删除不必要的文件和文件夹 @rem 删除不必要的文件和文件夹
rd /s /q %apiServicesPath%.swagger-codegen rd /s /q %apiServicesPath%.swagger-codegen

View File

@ -14,7 +14,7 @@ fi
echo "================================ 开始生成 api-services ================================" echo "================================ 开始生成 api-services ================================"
java -jar "${currPath}"/swagger-codegen-cli.jar generate -i http://localhost:5005/swagger/All%20Groups/swagger.json -l typescript-axios -o "${apiServicesPath}" java -jar "${currPath}"/swagger-codegen-cli.jar generate -i http://localhost:5005/swagger/Default/swagger.json -l typescript-axios -o "${apiServicesPath}"
rm -rf "${apiServicesPath}".swagger-codegen rm -rf "${apiServicesPath}".swagger-codegen
rm -f "${apiServicesPath}".gitignore rm -f "${apiServicesPath}".gitignore

View File

@ -0,0 +1,27 @@
@echo off
CHCP 65001
set dir=%~dp0
set apiServicesPath=%dir%..\src\api-services\_approvalFlow
if exist %apiServicesPath% (
echo ================================ 删除目录 api-services ================================
rd /s /q %apiServicesPath%
)
echo ================================ 开始生成 api-services ================================
java -jar %dir%swagger-codegen-cli.jar generate -i http://localhost:5005/swagger/ApprovalFlow/swagger.json -l typescript-axios -o %apiServicesPath%
@rem 删除不必要的文件和文件夹
rd /s /q %apiServicesPath%.swagger-codegen
del /q %apiServicesPath%.gitignore
del /q %apiServicesPath%.npmignore
del /q %apiServicesPath%.swagger-codegen-ignore
del /q %apiServicesPath%git_push.sh
del /q %apiServicesPath%package.json
del /q %apiServicesPath%README.md
del /q %apiServicesPath%tsconfig.json
echo ================================ 生成结束 ================================

View File

@ -0,0 +1,28 @@
#!/bin/sh
currPath=$(pwd)
parentPath=$(dirname "$currPath")
apiServicesPath=${parentPath}/src/api-services/_approvalFlow
echo "================================ 生成目录 ${apiServicesPath} ================================"
# 判断目录是否存在
if test -d "$apiServicesPath"; then
echo "================================ 删除目录 api-services ================================"
rm -rf "${apiServicesPath}"
fi
echo "================================ 开始生成 api-services ================================"
java -jar "${currPath}"/swagger-codegen-cli.jar generate -i http://localhost:5005/swagger/ApprovalFlow/swagger.json -l typescript-axios -o "${apiServicesPath}"
rm -rf "${apiServicesPath}".swagger-codegen
rm -f "${apiServicesPath}".gitignore
rm -f "${apiServicesPath}".npmignore
rm -f "${apiServicesPath}".swagger-codegen-ignore
rm -f "${apiServicesPath}"git_push.sh
rm -f "${apiServicesPath}"package.json
rm -f "${apiServicesPath}"README.md
rm -f "${apiServicesPath}"tsconfig.json
echo "================================ 生成结束 ================================"

View File

@ -0,0 +1,27 @@
@echo off
CHCP 65001
set dir=%~dp0
set apiServicesPath=%dir%..\src\api-services\_goView
if exist %apiServicesPath% (
echo ================================ 删除目录 api-services ================================
rd /s /q %apiServicesPath%
)
echo ================================ 开始生成 api-services ================================
java -jar %dir%swagger-codegen-cli.jar generate -i http://localhost:5005/swagger/GoView/swagger.json -l typescript-axios -o %apiServicesPath%
@rem 删除不必要的文件和文件夹
rd /s /q %apiServicesPath%.swagger-codegen
del /q %apiServicesPath%.gitignore
del /q %apiServicesPath%.npmignore
del /q %apiServicesPath%.swagger-codegen-ignore
del /q %apiServicesPath%git_push.sh
del /q %apiServicesPath%package.json
del /q %apiServicesPath%README.md
del /q %apiServicesPath%tsconfig.json
echo ================================ 生成结束 ================================

View File

@ -0,0 +1,28 @@
#!/bin/sh
currPath=$(pwd)
parentPath=$(dirname "$currPath")
apiServicesPath=${parentPath}/src/api-services/_goView
echo "================================ 生成目录 ${apiServicesPath} ================================"
# 判断目录是否存在
if test -d "$apiServicesPath"; then
echo "================================ 删除目录 api-services ================================"
rm -rf "${apiServicesPath}"
fi
echo "================================ 开始生成 api-services ================================"
java -jar "${currPath}"/swagger-codegen-cli.jar generate -i http://localhost:5005/swagger/All%20Groups/swagger.json -l typescript-axios -o "${apiServicesPath}"
rm -rf "${apiServicesPath}".swagger-codegen
rm -f "${apiServicesPath}".gitignore
rm -f "${apiServicesPath}".npmignore
rm -f "${apiServicesPath}".swagger-codegen-ignore
rm -f "${apiServicesPath}"git_push.sh
rm -f "${apiServicesPath}"package.json
rm -f "${apiServicesPath}"README.md
rm -f "${apiServicesPath}"tsconfig.json
echo "================================ 生成结束 ================================"

View File

@ -0,0 +1,27 @@
@echo off
CHCP 65001
set dir=%~dp0
set apiServicesPath=%dir%..\src\api-services\_goView
if exist %apiServicesPath% (
echo ================================ 删除目录 api-services ================================
rd /s /q %apiServicesPath%
)
echo ================================ 开始生成 api-services ================================
java -jar %dir%swagger-codegen-cli.jar generate -i http://localhost:5005/swagger/GoView/swagger.json -l typescript-axios -o %apiServicesPath%
@rem 删除不必要的文件和文件夹
rd /s /q %apiServicesPath%.swagger-codegen
del /q %apiServicesPath%.gitignore
del /q %apiServicesPath%.npmignore
del /q %apiServicesPath%.swagger-codegen-ignore
del /q %apiServicesPath%git_push.sh
del /q %apiServicesPath%package.json
del /q %apiServicesPath%README.md
del /q %apiServicesPath%tsconfig.json
echo ================================ 生成结束 ================================

View File

@ -0,0 +1,28 @@
#!/bin/sh
currPath=$(pwd)
parentPath=$(dirname "$currPath")
apiServicesPath=${parentPath}/src/api-services/_dingTalk
echo "================================ 生成目录 ${apiServicesPath} ================================"
# 判断目录是否存在
if test -d "$apiServicesPath"; then
echo "================================ 删除目录 api-services ================================"
rm -rf "${apiServicesPath}"
fi
echo "================================ 开始生成 api-services ================================"
java -jar "${currPath}"/swagger-codegen-cli.jar generate -i http://localhost:5005/swagger/DingTalk/swagger.json -l typescript-axios -o "${apiServicesPath}"
rm -rf "${apiServicesPath}".swagger-codegen
rm -f "${apiServicesPath}".gitignore
rm -f "${apiServicesPath}".npmignore
rm -f "${apiServicesPath}".swagger-codegen-ignore
rm -f "${apiServicesPath}"git_push.sh
rm -f "${apiServicesPath}"package.json
rm -f "${apiServicesPath}"README.md
rm -f "${apiServicesPath}"tsconfig.json
echo "================================ 生成结束 ================================"

View File

@ -135,6 +135,14 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
<el-form-item label="是否选择 Api Service 模式" prop="isApiService">
<el-radio-group v-model="state.ruleForm.isApiService">
<el-radio :value="true"></el-radio>
<el-radio :value="false"></el-radio>
</el-radio-group>
</el-form-item>
</el-col>
</el-row> </el-row>
</el-form> </el-form>
<template #footer> <template #footer>