😎优化代码生成
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" />
|
<ProjectReference Include="..\Plugins\Admin.NET.Plugin.GoView\Admin.NET.Plugin.GoView.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="SeedData\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -473,7 +473,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient
|
|||||||
BusName = input.BusName!, // 业务名称
|
BusName = input.BusName!, // 业务名称
|
||||||
NameSpace = input.NameSpace!, // 命名空间
|
NameSpace = input.NameSpace!, // 命名空间
|
||||||
ClassName = input.TableName!, // 类名称
|
ClassName = input.TableName!, // 类名称
|
||||||
input.ConfigId,
|
ConfigId = input.ConfigId, // 库标识
|
||||||
MenuList = menuList, // 菜单集合
|
MenuList = menuList, // 菜单集合
|
||||||
PrintType = input.PrintType!
|
PrintType = input.PrintType!
|
||||||
};
|
};
|
||||||
@ -487,7 +487,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tResult = await _viewEngine.RunCompileFromCachedAsync(tContent, data, builderAction: builder =>
|
tResult = await _viewEngine.RunCompileAsync(tContent, data, builderAction: builder =>
|
||||||
{
|
{
|
||||||
builder.AddAssemblyReferenceByName("System.Linq");
|
builder.AddAssemblyReferenceByName("System.Linq");
|
||||||
builder.AddAssemblyReferenceByName("System.Collections");
|
builder.AddAssemblyReferenceByName("System.Collections");
|
||||||
@ -612,7 +612,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient
|
|||||||
BusName = input.BusName!, // 业务名称
|
BusName = input.BusName!, // 业务名称
|
||||||
NameSpace = input.NameSpace!, // 命名空间
|
NameSpace = input.NameSpace!, // 命名空间
|
||||||
ClassName = input.TableName!, // 类名称
|
ClassName = input.TableName!, // 类名称
|
||||||
input.ConfigId,
|
ConfigId = input.ConfigId, // 库标识
|
||||||
MenuList = menuList, // 菜单集合
|
MenuList = menuList, // 菜单集合
|
||||||
PrintType = input.PrintType!
|
PrintType = input.PrintType!
|
||||||
};
|
};
|
||||||
@ -734,7 +734,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient
|
|||||||
// 若 pid=0 为顶级则创建菜单目录
|
// 若 pid=0 为顶级则创建菜单目录
|
||||||
SysMenu menuType0 = null;
|
SysMenu menuType0 = null;
|
||||||
long tempPid = pid;
|
long tempPid = pid;
|
||||||
List<SysMenu> menuList = new List<SysMenu>();
|
var menuList = new List<SysMenu>();
|
||||||
if (pid == 0)
|
if (pid == 0)
|
||||||
{
|
{
|
||||||
// 目录
|
// 目录
|
||||||
@ -745,13 +745,14 @@ public class SysCodeGenService : IDynamicApiController, ITransient
|
|||||||
Title = busName + "管理",
|
Title = busName + "管理",
|
||||||
Type = MenuTypeEnum.Dir,
|
Type = MenuTypeEnum.Dir,
|
||||||
Icon = "robot",
|
Icon = "robot",
|
||||||
Path = "/" + className.ToLower(),
|
Path = "/" + className.ToLower() + "Manage",
|
||||||
Name = className[..1].ToLower() + className[1..],
|
Name = className[..1].ToLower() + className[1..] + "Manage",
|
||||||
Component = "Layout",
|
Component = "Layout",
|
||||||
OrderNo = 100,
|
OrderNo = 100,
|
||||||
CreateTime = DateTime.Now
|
CreateTime = DateTime.Now
|
||||||
};
|
};
|
||||||
pid = menuType0.Id;
|
pid = menuType0.Id;
|
||||||
|
pPath = menuType0.Path;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -942,10 +943,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient
|
|||||||
public static string ToFirstLetterLowerCase(string input)
|
public static string ToFirstLetterLowerCase(string input)
|
||||||
{
|
{
|
||||||
// 检查字符串是否为空或空格
|
// 检查字符串是否为空或空格
|
||||||
if (string.IsNullOrWhiteSpace(input))
|
if (string.IsNullOrWhiteSpace(input)) return input;
|
||||||
{
|
|
||||||
return input;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 只转换首字母为小写
|
// 只转换首字母为小写
|
||||||
return char.ToLower(input[0]) + input.Substring(1);
|
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");
|
DbColumnInfo orderField = dbColumnInfos.FirstOrDefault(u => u.DbColumnName.ToLower() == "create_time" || u.DbColumnName.ToLower() == "createtime");
|
||||||
if (orderField != null) query = query.OrderBy(orderField.DbColumnName);
|
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();
|
var records = ((IEnumerable)await query.ToListAsync()).ToDynamicList();
|
||||||
|
|
||||||
// 过滤已存在的数据
|
// 过滤已存在的数据
|
||||||
|
|||||||
@ -133,7 +133,7 @@ if (@column.QueryWhether == "Y"){
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[ApiDescriptionSettings(Name = "add", Description = "增加@(@Model.BusName)", Order = 990), HttpPost]
|
[ApiDescriptionSettings(Name = "add", Description = "增加@(@Model.BusName)", Order = 990), HttpPost]
|
||||||
[DisplayName("增加@(@Model.BusName)")]
|
[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)>();
|
var entity = input.Adapt<@(@Model.ClassName)>();
|
||||||
@if(Model.RemoteVerify){
|
@if(Model.RemoteVerify){
|
||||||
@ -144,8 +144,7 @@ if (@column.QueryWhether == "Y"){
|
|||||||
@:throw Oops.Oh(ErrorCodeEnum.D1006);
|
@:throw Oops.Oh(ErrorCodeEnum.D1006);
|
||||||
@:}
|
@:}
|
||||||
}
|
}
|
||||||
await _@(@Model.LowerClassName)Rep.InsertAsync(entity);
|
return await _@(@Model.LowerClassName)Rep.InsertAsync(entity);
|
||||||
return entity.@(@PKName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -157,13 +156,7 @@ if (@column.QueryWhether == "Y"){
|
|||||||
[DisplayName("删除@(@Model.BusName)")]
|
[DisplayName("删除@(@Model.BusName)")]
|
||||||
public async Task Delete(Delete@(@Model.ClassName)Input input)
|
public async Task Delete(Delete@(@Model.ClassName)Input input)
|
||||||
{
|
{
|
||||||
@foreach (var column in Model.TableField){
|
await _@(@Model.LowerClassName)Rep.DeleteByIdAsync(input.Id); // 真删除
|
||||||
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); // 真删除
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -16,8 +16,8 @@ namespace @(@Model.NameSpace).SeedData;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// @(@Model.BusName)系统菜单表种子数据
|
/// @(@Model.BusName)系统菜单表种子数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[IncreSeed]
|
// [IncreSeed]
|
||||||
public class @(@Model.ClassName)SeedData : ISqlSugarEntitySeedData<SysMenu>
|
public class @(@Model.ClassName)MenuSeedData : ISqlSugarEntitySeedData<SysMenu>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 种子数据
|
/// 种子数据
|
||||||
|
|||||||
@ -221,8 +221,8 @@ const userStore = useUserInfo();
|
|||||||
@:const getConstType = userStore.getConstDataByTypeCode;
|
@:const getConstType = userStore.getConstDataByTypeCode;
|
||||||
}
|
}
|
||||||
@if(@Model.TableField.Any(x=>x.EffectType == "DictSelector") || @Model.TableField.Any(x=>x.EffectType == "EnumSelector")){
|
@if(@Model.TableField.Any(x=>x.EffectType == "DictSelector") || @Model.TableField.Any(x=>x.EffectType == "EnumSelector")){
|
||||||
@:const dc = userStore.getDictItemByCode;
|
//@:const dc = userStore.getDictItemByCode;
|
||||||
@:const dv = userStore.getDictLabelByVal;
|
//@:const dv = userStore.getDictLabelByVal;
|
||||||
@:const dl = userStore.getDictDataByCode;
|
@:const dl = userStore.getDictDataByCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -420,7 +420,7 @@ const handleEdit = (row: any) => {
|
|||||||
|
|
||||||
// 删除
|
// 删除
|
||||||
const handleDelete = (row: any) => {
|
const handleDelete = (row: any) => {
|
||||||
ElMessageBox.confirm(`确定删除@(@Model.BusName):【${row.title}】?`, '提示', {
|
ElMessageBox.confirm(`确定删除@(@Model.BusName):【${row.id}】?`, '提示', {
|
||||||
confirmButtonText: '确定',
|
confirmButtonText: '确定',
|
||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
|
|||||||
@ -210,7 +210,7 @@
|
|||||||
<el-tab-pane label="选择模板" name="template">
|
<el-tab-pane label="选择模板" name="template">
|
||||||
<el-table ref="templateTableRef" :data="templateTableData" @selection-change="handleSelectionChange" style="width: 100%">
|
<el-table ref="templateTableRef" :data="templateTableData" @selection-change="handleSelectionChange" style="width: 100%">
|
||||||
<el-table-column type="selection" width="55" />
|
<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-column property="describe" label="描述" show-overflow-tooltip />
|
||||||
</el-table>
|
</el-table>
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
@ -264,6 +264,7 @@ onMounted(async () => {
|
|||||||
state.dbData = await getAPI(SysCodeGenApi)
|
state.dbData = await getAPI(SysCodeGenApi)
|
||||||
.apiSysCodeGenDatabaseListGet()
|
.apiSysCodeGenDatabaseListGet()
|
||||||
.then((res) => res.data.result ?? []);
|
.then((res) => res.data.result ?? []);
|
||||||
|
|
||||||
state.printList = await getAPI(SysPrintApi)
|
state.printList = await getAPI(SysPrintApi)
|
||||||
.apiSysPrintPagePost()
|
.apiSysPrintPagePost()
|
||||||
.then((res) => res.data.result?.items ?? []);
|
.then((res) => res.data.result?.items ?? []);
|
||||||
@ -310,7 +311,7 @@ const handleSelectionChange = (val: any[]) => {
|
|||||||
|
|
||||||
// db改变
|
// db改变
|
||||||
const dbChanged = async () => {
|
const dbChanged = async () => {
|
||||||
if (state.ruleForm.configId === '') return;
|
if (state.ruleForm.configId === '' || state.ruleForm.configId == null) return;
|
||||||
state.tableData = await getAPI(SysCodeGenApi)
|
state.tableData = await getAPI(SysCodeGenApi)
|
||||||
.apiSysCodeGenTableListConfigIdGet(state.ruleForm.configId as string)
|
.apiSysCodeGenTableListConfigIdGet(state.ruleForm.configId as string)
|
||||||
.then((res) => res.data.result ?? []);
|
.then((res) => res.data.result ?? []);
|
||||||
@ -336,7 +337,7 @@ const changeTableUniqueColumn = (value: any, index: number) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getColumnInfoList = async () => {
|
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 =
|
state.columnData =
|
||||||
(await getAPI(SysCodeGenApi)
|
(await getAPI(SysCodeGenApi)
|
||||||
.apiSysCodeGenColumnListByTableNameTableNameConfigIdGet(state.ruleForm.tableName, state.ruleForm.configId)
|
.apiSysCodeGenColumnListByTableNameTableNameConfigIdGet(state.ruleForm.tableName, state.ruleForm.configId)
|
||||||
|
|||||||
@ -36,7 +36,7 @@
|
|||||||
<vxe-tag v-else status="info">否</vxe-tag>
|
<vxe-tag v-else status="info">否</vxe-tag>
|
||||||
</template>
|
</template>
|
||||||
<template #queryWhether="{ row }">
|
<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>
|
||||||
<template #queryType="{ row }">
|
<template #queryType="{ row }">
|
||||||
<vxe-select v-model="row.queryType" class="m-2" placeholder="Select" :disabled="!row.queryWhether" filterable transfer>
|
<vxe-select v-model="row.queryType" class="m-2" placeholder="Select" :disabled="!row.queryWhether" filterable transfer>
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="sys-codeGenPreview-container">
|
<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>
|
<template #header>
|
||||||
<div style="color: #fff">
|
<div style="color: #fff">
|
||||||
<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit /> </el-icon>
|
<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">
|
<script lang="ts" setup name="sysCodeGen">
|
||||||
import { onMounted, reactive, ref, defineAsyncComponent } from 'vue';
|
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 { VxeGridInstance, VxeGridListeners, VxeGridPropTypes } from 'vxe-table';
|
||||||
import { useVxeTable } from '/@/hooks/useVxeTableOptionsHook';
|
import { useVxeTable } from '/@/hooks/useVxeTableOptionsHook';
|
||||||
import { Local } from '/@/utils/storage';
|
import { Local } from '/@/utils/storage';
|
||||||
@ -237,7 +237,13 @@ const handleGenerate = (row: any) => {
|
|||||||
var res = await getAPI(SysCodeGenApi).apiSysCodeGenRunLocalPost(row);
|
var res = await getAPI(SysCodeGenApi).apiSysCodeGenRunLocalPost(row);
|
||||||
if (res.data.result != null && res.data.result.url != null) downloadByUrl({ url: res.data.result.url });
|
if (res.data.result != null && res.data.result.url != null) downloadByUrl({ url: res.data.result.url });
|
||||||
await handleQuery();
|
await handleQuery();
|
||||||
ElMessage.success('操作成功');
|
|
||||||
|
ElNotification({
|
||||||
|
title: '提示',
|
||||||
|
message: '生成成功,请重启项目以加载最新代码',
|
||||||
|
type: 'success',
|
||||||
|
position: 'bottom-right',
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -48,7 +48,7 @@
|
|||||||
|
|
||||||
<script lang="ts" setup name="sysGenEntity">
|
<script lang="ts" setup name="sysGenEntity">
|
||||||
import { reactive, ref } from 'vue';
|
import { reactive, ref } from 'vue';
|
||||||
import { ElMessage } from 'element-plus';
|
import { ElNotification } from 'element-plus';
|
||||||
import { camelCase, upperFirst } from 'lodash-es';
|
import { camelCase, upperFirst } from 'lodash-es';
|
||||||
import { useUserInfo } from '/@/stores/userInfo';
|
import { useUserInfo } from '/@/stores/userInfo';
|
||||||
|
|
||||||
@ -97,7 +97,13 @@ const submit = () => {
|
|||||||
try {
|
try {
|
||||||
await getAPI(SysDatabaseApi).apiSysDatabaseCreateEntityPost(state.ruleForm);
|
await getAPI(SysDatabaseApi).apiSysDatabaseCreateEntityPost(state.ruleForm);
|
||||||
closeDialog();
|
closeDialog();
|
||||||
ElMessage.success('生成成功');
|
|
||||||
|
ElNotification({
|
||||||
|
title: '提示',
|
||||||
|
message: '生成成功,请重启项目以加载最新代码',
|
||||||
|
type: 'success',
|
||||||
|
position: 'bottom-right',
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
/* empty */
|
/* empty */
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
<script lang="ts" setup name="sysGenEntity">
|
<script lang="ts" setup name="sysGenEntity">
|
||||||
import { onMounted, reactive, ref } from 'vue';
|
import { onMounted, reactive, ref } from 'vue';
|
||||||
import { ElMessage } from 'element-plus';
|
import { ElMessage, ElNotification } from 'element-plus';
|
||||||
|
|
||||||
import { getAPI } from '/@/utils/axios-utils';
|
import { getAPI } from '/@/utils/axios-utils';
|
||||||
import { SysDatabaseApi, SysDictTypeApi } from '/@/api-services/api';
|
import { SysDatabaseApi, SysDictTypeApi } from '/@/api-services/api';
|
||||||
@ -99,8 +99,14 @@ const submit = () => {
|
|||||||
try {
|
try {
|
||||||
await getAPI(SysDatabaseApi).apiSysDatabaseCreateSeedDataPost(state.ruleForm);
|
await getAPI(SysDatabaseApi).apiSysDatabaseCreateSeedDataPost(state.ruleForm);
|
||||||
closeDialog();
|
closeDialog();
|
||||||
ElMessage.success('生成成功');
|
|
||||||
} catch (e) {
|
ElNotification({
|
||||||
|
title: '提示',
|
||||||
|
message: '生成成功,请重启项目以加载最新代码',
|
||||||
|
type: 'success',
|
||||||
|
position: 'bottom-right',
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
/* empty */
|
/* empty */
|
||||||
}
|
}
|
||||||
state.loading = false;
|
state.loading = false;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user