😎优化代码生成
This commit is contained in:
parent
5e17c0f7d6
commit
91d03d8142
@ -29,4 +29,8 @@
|
||||
<ProjectReference Include="..\Plugins\Admin.NET.Plugin.GoView\Admin.NET.Plugin.GoView.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="SeedData\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -473,7 +473,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient
|
||||
BusName = input.BusName!, // 业务名称
|
||||
NameSpace = input.NameSpace!, // 命名空间
|
||||
ClassName = input.TableName!, // 类名称
|
||||
input.ConfigId,
|
||||
ConfigId = input.ConfigId, // 库标识
|
||||
MenuList = menuList, // 菜单集合
|
||||
PrintType = input.PrintType!
|
||||
};
|
||||
@ -487,7 +487,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient
|
||||
}
|
||||
else
|
||||
{
|
||||
tResult = await _viewEngine.RunCompileFromCachedAsync(tContent, data, builderAction: builder =>
|
||||
tResult = await _viewEngine.RunCompileAsync(tContent, data, builderAction: builder =>
|
||||
{
|
||||
builder.AddAssemblyReferenceByName("System.Linq");
|
||||
builder.AddAssemblyReferenceByName("System.Collections");
|
||||
@ -612,7 +612,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient
|
||||
BusName = input.BusName!, // 业务名称
|
||||
NameSpace = input.NameSpace!, // 命名空间
|
||||
ClassName = input.TableName!, // 类名称
|
||||
input.ConfigId,
|
||||
ConfigId = input.ConfigId, // 库标识
|
||||
MenuList = menuList, // 菜单集合
|
||||
PrintType = input.PrintType!
|
||||
};
|
||||
@ -734,7 +734,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient
|
||||
// 若 pid=0 为顶级则创建菜单目录
|
||||
SysMenu menuType0 = null;
|
||||
long tempPid = pid;
|
||||
List<SysMenu> menuList = new List<SysMenu>();
|
||||
var menuList = new List<SysMenu>();
|
||||
if (pid == 0)
|
||||
{
|
||||
// 目录
|
||||
@ -745,13 +745,14 @@ public class SysCodeGenService : IDynamicApiController, ITransient
|
||||
Title = busName + "管理",
|
||||
Type = MenuTypeEnum.Dir,
|
||||
Icon = "robot",
|
||||
Path = "/" + className.ToLower(),
|
||||
Name = className[..1].ToLower() + className[1..],
|
||||
Path = "/" + className.ToLower() + "Manage",
|
||||
Name = className[..1].ToLower() + className[1..] + "Manage",
|
||||
Component = "Layout",
|
||||
OrderNo = 100,
|
||||
CreateTime = DateTime.Now
|
||||
};
|
||||
pid = menuType0.Id;
|
||||
pPath = menuType0.Path;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -942,10 +943,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient
|
||||
public static string ToFirstLetterLowerCase(string input)
|
||||
{
|
||||
// 检查字符串是否为空或空格
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
{
|
||||
return input;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(input)) return input;
|
||||
|
||||
// 只转换首字母为小写
|
||||
return char.ToLower(input[0]) + input.Substring(1);
|
||||
|
||||
@ -345,7 +345,7 @@ public class SysDatabaseService : IDynamicApiController, ITransient
|
||||
DbColumnInfo orderField = dbColumnInfos.FirstOrDefault(u => u.DbColumnName.ToLower() == "create_time" || u.DbColumnName.ToLower() == "createtime");
|
||||
if (orderField != null) query = query.OrderBy(orderField.DbColumnName);
|
||||
// 再使用第一个主键排序
|
||||
query = query.OrderBy(dbColumnInfos.First(u => u.IsPrimarykey).DbColumnName);
|
||||
//query = query.OrderBy(dbColumnInfos.First(u => u.IsPrimarykey).DbColumnName);
|
||||
var records = ((IEnumerable)await query.ToListAsync()).ToDynamicList();
|
||||
|
||||
// 过滤已存在的数据
|
||||
|
||||
@ -133,7 +133,7 @@ if (@column.QueryWhether == "Y"){
|
||||
/// <returns></returns>
|
||||
[ApiDescriptionSettings(Name = "add", Description = "增加@(@Model.BusName)", Order = 990), HttpPost]
|
||||
[DisplayName("增加@(@Model.BusName)")]
|
||||
public async Task<long> Add(Add@(@Model.ClassName)Input input)
|
||||
public async Task<bool> Add(Add@(@Model.ClassName)Input input)
|
||||
{
|
||||
var entity = input.Adapt<@(@Model.ClassName)>();
|
||||
@if(Model.RemoteVerify){
|
||||
@ -144,8 +144,7 @@ if (@column.QueryWhether == "Y"){
|
||||
@:throw Oops.Oh(ErrorCodeEnum.D1006);
|
||||
@:}
|
||||
}
|
||||
await _@(@Model.LowerClassName)Rep.InsertAsync(entity);
|
||||
return entity.@(@PKName);
|
||||
return await _@(@Model.LowerClassName)Rep.InsertAsync(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -157,13 +156,7 @@ if (@column.QueryWhether == "Y"){
|
||||
[DisplayName("删除@(@Model.BusName)")]
|
||||
public async Task Delete(Delete@(@Model.ClassName)Input input)
|
||||
{
|
||||
@foreach (var column in Model.TableField){
|
||||
if (@column.ColumnKey == "True"){
|
||||
@:var entity = await _@(@Model.LowerClassName)Rep.GetFirstAsync(u => u.@(@column.PropertyName) == input.@(@column.PropertyName)) ?? throw Oops.Oh(ErrorCodeEnum.D1002);
|
||||
}
|
||||
}
|
||||
await _@(@Model.LowerClassName)Rep.FakeDeleteAsync(entity); // 假删除
|
||||
//await _@(@Model.LowerClassName)Rep.DeleteAsync(entity); // 真删除
|
||||
await _@(@Model.LowerClassName)Rep.DeleteByIdAsync(input.Id); // 真删除
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -16,8 +16,8 @@ namespace @(@Model.NameSpace).SeedData;
|
||||
/// <summary>
|
||||
/// @(@Model.BusName)系统菜单表种子数据
|
||||
/// </summary>
|
||||
[IncreSeed]
|
||||
public class @(@Model.ClassName)SeedData : ISqlSugarEntitySeedData<SysMenu>
|
||||
// [IncreSeed]
|
||||
public class @(@Model.ClassName)MenuSeedData : ISqlSugarEntitySeedData<SysMenu>
|
||||
{
|
||||
/// <summary>
|
||||
/// 种子数据
|
||||
|
||||
@ -221,19 +221,19 @@ const userStore = useUserInfo();
|
||||
@:const getConstType = userStore.getConstDataByTypeCode;
|
||||
}
|
||||
@if(@Model.TableField.Any(x=>x.EffectType == "DictSelector") || @Model.TableField.Any(x=>x.EffectType == "EnumSelector")){
|
||||
@:const dc = userStore.getDictItemByCode;
|
||||
@:const dv = userStore.getDictLabelByVal;
|
||||
//@:const dc = userStore.getDictItemByCode;
|
||||
//@:const dv = userStore.getDictLabelByVal;
|
||||
@:const dl = userStore.getDictDataByCode;
|
||||
}
|
||||
|
||||
//父级传递来的参数
|
||||
// 父级传递来的参数
|
||||
var props = defineProps({
|
||||
title: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
});
|
||||
//父级传递来的函数,用于回调
|
||||
// 父级传递来的函数,用于回调
|
||||
const emit = defineEmits(["reloadTable"]);
|
||||
const ruleFormRef = ref();
|
||||
const state = reactive({
|
||||
@ -260,7 +260,7 @@ const state = reactive({
|
||||
}
|
||||
});
|
||||
|
||||
//自行添加其他规则
|
||||
// 自行添加其他规则
|
||||
const rules = ref<FormRules>({
|
||||
@foreach (var column in Model.TableField){
|
||||
if(@column.WhetherAddUpdate == "Y"){
|
||||
@ -391,7 +391,7 @@ const submit = async () => {
|
||||
|
||||
@foreach (var column in Model.TableField){
|
||||
if(@column.EffectType == "ForeignKey" && @column.WhetherAddUpdate == "Y"){
|
||||
@://下拉列表@(@column.ColumnComment)
|
||||
@:// 下拉列表@(@column.ColumnComment)
|
||||
@:const @LowerFirstLetter(@column.FkEntityName)@(@column.PropertyName)DropdownList = ref<any>([]);
|
||||
@:const get@(@column.FkEntityName)@(@column.PropertyName)DropdownList = async () => {
|
||||
@if (@Model.IsApiService) {
|
||||
@ -431,7 +431,7 @@ else if(@column.EffectType == "ConstSelector"){
|
||||
@foreach (var column in Model.TableField){
|
||||
if(column.WhetherAddUpdate=="N") continue;
|
||||
if(@column.EffectType == "Upload"){
|
||||
@://上传@(@column.ColumnComment)
|
||||
@:// 上传@(@column.ColumnComment)
|
||||
@:const upload@(@column.PropertyName)Handle = async (options: UploadRequestOptions) => {
|
||||
@if (@Model.IsApiService) {
|
||||
@:let res = await getAPI(@(@Model.ClassName)Api).api@(@Model.ClassName)Upload@(@column.FkEntityName)PostForm(options);
|
||||
@ -442,7 +442,7 @@ if(@column.EffectType == "Upload"){
|
||||
@:};
|
||||
}
|
||||
}
|
||||
//将属性或者函数暴露给父组件
|
||||
// 将属性或者函数暴露给父组件
|
||||
defineExpose({ openDialog });
|
||||
</script>
|
||||
|
||||
|
||||
@ -420,7 +420,7 @@ const handleEdit = (row: any) => {
|
||||
|
||||
// 删除
|
||||
const handleDelete = (row: any) => {
|
||||
ElMessageBox.confirm(`确定删除@(@Model.BusName):【${row.title}】?`, '提示', {
|
||||
ElMessageBox.confirm(`确定删除@(@Model.BusName):【${row.id}】?`, '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
|
||||
@ -210,7 +210,7 @@
|
||||
<el-tab-pane label="选择模板" name="template">
|
||||
<el-table ref="templateTableRef" :data="templateTableData" @selection-change="handleSelectionChange" style="width: 100%">
|
||||
<el-table-column type="selection" width="55" />
|
||||
<el-table-column property="name" label="模板文件名" width="200" />
|
||||
<el-table-column property="name" label="模板文件名" width="280" />
|
||||
<el-table-column property="describe" label="描述" show-overflow-tooltip />
|
||||
</el-table>
|
||||
</el-tab-pane>
|
||||
@ -264,6 +264,7 @@ onMounted(async () => {
|
||||
state.dbData = await getAPI(SysCodeGenApi)
|
||||
.apiSysCodeGenDatabaseListGet()
|
||||
.then((res) => res.data.result ?? []);
|
||||
|
||||
state.printList = await getAPI(SysPrintApi)
|
||||
.apiSysPrintPagePost()
|
||||
.then((res) => res.data.result?.items ?? []);
|
||||
@ -310,7 +311,7 @@ const handleSelectionChange = (val: any[]) => {
|
||||
|
||||
// db改变
|
||||
const dbChanged = async () => {
|
||||
if (state.ruleForm.configId === '') return;
|
||||
if (state.ruleForm.configId === '' || state.ruleForm.configId == null) return;
|
||||
state.tableData = await getAPI(SysCodeGenApi)
|
||||
.apiSysCodeGenTableListConfigIdGet(state.ruleForm.configId as string)
|
||||
.then((res) => res.data.result ?? []);
|
||||
@ -336,7 +337,7 @@ const changeTableUniqueColumn = (value: any, index: number) => {
|
||||
};
|
||||
|
||||
const getColumnInfoList = async () => {
|
||||
if (state.ruleForm.configId == '' || state.ruleForm.tableName == '') return;
|
||||
if (state.ruleForm.configId == '' || state.ruleForm.configId == null || state.ruleForm.tableName == '' || state.ruleForm.tableName == null) return;
|
||||
state.columnData =
|
||||
(await getAPI(SysCodeGenApi)
|
||||
.apiSysCodeGenColumnListByTableNameTableNameConfigIdGet(state.ruleForm.tableName, state.ruleForm.configId)
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
<vxe-tag v-else status="info">否</vxe-tag>
|
||||
</template>
|
||||
<template #queryWhether="{ row }">
|
||||
<vxe-switch readonly v-model="row.queryWhether" open-label="是" close-label="否" :openValue="true" :closeValue="false"></vxe-switch>
|
||||
<vxe-switch v-model="row.queryWhether" open-label="是" close-label="否" :openValue="true" :closeValue="false"></vxe-switch>
|
||||
</template>
|
||||
<template #queryType="{ row }">
|
||||
<vxe-select v-model="row.queryType" class="m-2" placeholder="Select" :disabled="!row.queryWhether" filterable transfer>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="sys-codeGenPreview-container">
|
||||
<el-dialog v-model="state.isShowDialog" draggable :close-on-click-modal="false" width="80vw">
|
||||
<el-dialog v-model="state.isShowDialog" draggable :close-on-click-modal="false" width="70vw">
|
||||
<template #header>
|
||||
<div style="color: #fff">
|
||||
<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit /> </el-icon>
|
||||
|
||||
@ -73,7 +73,7 @@
|
||||
|
||||
<script lang="ts" setup name="sysCodeGen">
|
||||
import { onMounted, reactive, ref, defineAsyncComponent } from 'vue';
|
||||
import { ElMessageBox, ElMessage } from 'element-plus';
|
||||
import { ElMessageBox, ElMessage, ElNotification } from 'element-plus';
|
||||
import { VxeGridInstance, VxeGridListeners, VxeGridPropTypes } from 'vxe-table';
|
||||
import { useVxeTable } from '/@/hooks/useVxeTableOptionsHook';
|
||||
import { Local } from '/@/utils/storage';
|
||||
@ -237,7 +237,13 @@ const handleGenerate = (row: any) => {
|
||||
var res = await getAPI(SysCodeGenApi).apiSysCodeGenRunLocalPost(row);
|
||||
if (res.data.result != null && res.data.result.url != null) downloadByUrl({ url: res.data.result.url });
|
||||
await handleQuery();
|
||||
ElMessage.success('操作成功');
|
||||
|
||||
ElNotification({
|
||||
title: '提示',
|
||||
message: '生成成功,请重启项目以加载最新代码',
|
||||
type: 'success',
|
||||
position: 'bottom-right',
|
||||
});
|
||||
})
|
||||
.catch(() => {});
|
||||
};
|
||||
|
||||
@ -48,7 +48,7 @@
|
||||
|
||||
<script lang="ts" setup name="sysGenEntity">
|
||||
import { reactive, ref } from 'vue';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { ElNotification } from 'element-plus';
|
||||
import { camelCase, upperFirst } from 'lodash-es';
|
||||
import { useUserInfo } from '/@/stores/userInfo';
|
||||
|
||||
@ -97,7 +97,13 @@ const submit = () => {
|
||||
try {
|
||||
await getAPI(SysDatabaseApi).apiSysDatabaseCreateEntityPost(state.ruleForm);
|
||||
closeDialog();
|
||||
ElMessage.success('生成成功');
|
||||
|
||||
ElNotification({
|
||||
title: '提示',
|
||||
message: '生成成功,请重启项目以加载最新代码',
|
||||
type: 'success',
|
||||
position: 'bottom-right',
|
||||
});
|
||||
} catch (e) {
|
||||
/* empty */
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
<script lang="ts" setup name="sysGenEntity">
|
||||
import { onMounted, reactive, ref } from 'vue';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { ElMessage, ElNotification } from 'element-plus';
|
||||
|
||||
import { getAPI } from '/@/utils/axios-utils';
|
||||
import { SysDatabaseApi, SysDictTypeApi } from '/@/api-services/api';
|
||||
@ -99,8 +99,14 @@ const submit = () => {
|
||||
try {
|
||||
await getAPI(SysDatabaseApi).apiSysDatabaseCreateSeedDataPost(state.ruleForm);
|
||||
closeDialog();
|
||||
ElMessage.success('生成成功');
|
||||
} catch (e) {
|
||||
|
||||
ElNotification({
|
||||
title: '提示',
|
||||
message: '生成成功,请重启项目以加载最新代码',
|
||||
type: 'success',
|
||||
position: 'bottom-right',
|
||||
});
|
||||
} catch {
|
||||
/* empty */
|
||||
}
|
||||
state.loading = false;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user