优化代码生成

This commit is contained in:
不做码农
2021-12-24 21:05:42 +08:00
parent a3d0a2b403
commit 5bce7e0464
7 changed files with 59 additions and 22 deletions

View File

@@ -186,10 +186,9 @@ namespace ZR.CodeGenerator
sb.AppendLine($" end-placeholder=\"\" placeholder=\"请选择{dbFieldInfo.ColumnComment}\" ></el-date-picker>");
sb.AppendLine(" </el-form-item>");
}
else if ((dbFieldInfo.HtmlType == GenConstants.HTML_SELECT || dbFieldInfo.HtmlType == GenConstants.HTML_RADIO))
else if (dbFieldInfo.HtmlType == GenConstants.HTML_SELECT || dbFieldInfo.HtmlType == GenConstants.HTML_RADIO)
{
//string value = CodeGeneratorTool.IsNumber(dbFieldInfo.CsharpType) ? "parseInt(item.dictValue)" : "item.dictValue";
sb.AppendLine($" <el-form-item label=\"{ labelName}\" prop=\"{columnName}\">");
sb.AppendLine($" <el-form-item label=\"{labelName}\" prop=\"{columnName}\">");
sb.AppendLine($" <el-select v-model=\"queryParams.{columnName}\" placeholder=\"请选择{dbFieldInfo.ColumnComment}\" size=\"small\" >");
sb.AppendLine($" <el-option v-for=\"item in {columnName}Options\" :key=\"item.dictValue\" :label=\"item.dictLabel\" :value=\"item.dictValue\"></el-option>");
sb.AppendLine(" </el-select>");
@@ -220,12 +219,13 @@ namespace ZR.CodeGenerator
string formatter = GetFormatter(dbFieldInfo.HtmlType, columnName);
StringBuilder sb = new StringBuilder();
//自定义排序字段
if (GenConstants.HTML_SORT.Equals(dbFieldInfo.HtmlType) && !dbFieldInfo.IsPk && CodeGeneratorTool.IsNumber(dbFieldInfo.CsharpType))
if (GenConstants.HTML_CUSTOM_INPUT.Equals(dbFieldInfo.HtmlType) && !dbFieldInfo.IsPk)
{
sb.AppendLine($@" <el-table-column prop=""{columnName}"" label=""{label}"" width=""90"" sortable align=""center"">");
sb.AppendLine(@" <template slot-scope=""scope"">");
sb.AppendLine($@" <el-input size=""mini"" style=""width:50px"" controls-position=""no"" v-model.number=""scope.row.{columnName}"" @blur=""handleChangeSort(scope.row, scope.row.{columnName})"" v-if=""showEditSort"" />");
sb.AppendLine($" <span v-else>{{{{scope.row.{columnName}}}}}</span>");
sb.AppendLine($@" <span v-show=""editIndex != scope.$index"" @click=""editCurrRow(scope.$index,'rowkeY')"">{{{{scope.row.{columnName}}}}}</span>");
sb.AppendLine(@" <el-input :id=""scope.$index+'rowkeY'"" size=""mini"" v-show=""(editIndex == scope.$index)""");
sb.AppendLine($@" v-model=""scope.row.{columnName}"" @blur=""handleChangeSort(scope.row)""></el-input>");
sb.AppendLine(@" </template>");
sb.AppendLine(@" </el-table-column>");
}
@@ -239,7 +239,7 @@ namespace ZR.CodeGenerator
sb.AppendLine(" </template>");
sb.AppendLine(" </el-table-column>");
}
else if (dbFieldInfo.IsList && !string.IsNullOrEmpty(dbFieldInfo.DictType))
else if (dbFieldInfo.IsList && !string.IsNullOrEmpty(formatter))
{
sb.AppendLine($@" <el-table-column label=""{label}"" align=""center"" prop=""{columnName}"">");
sb.AppendLine(@" <template slot-scope=""scope"">");

View File

@@ -447,6 +447,7 @@ namespace ZR.CodeGenerator
{
//Engine.Current.Clean();
dto.GenTable.Columns = dto.GenTable.Columns.OrderBy(x => x.Sort).ToList();
bool showCustomInput = dto.GenTable.Columns.Any(f => f.HtmlType.Equals(GenConstants.HTML_CUSTOM_INPUT, StringComparison.OrdinalIgnoreCase));
//jnt模板引擎全局变量
Engine.Configure((options) =>
{
@@ -461,6 +462,7 @@ namespace ZR.CodeGenerator
options.Data.Set("options", dto.GenOptions);
options.Data.Set("genTable", dto.GenTable);
options.Data.Set("btns", dto.CheckedBtn);
options.Data.Set("showCustomInput", showCustomInput);
options.Data.Set("tool", new CodeGeneratorTool());
options.Data.Set("codeTool", new CodeGenerateTemplate());
options.EnableCache = true;

View File

@@ -111,6 +111,10 @@ namespace ZR.CodeGenerator
public static string HTML_EDITOR = "editor";
// 自定义排序
public static string HTML_SORT = "sort";
/// <summary>
/// 自定义输入框
/// </summary>
public static string HTML_CUSTOM_INPUT = "customInput";
//颜色选择器
public static string HTML_COLORPICKER = "colorPicker";
//switch开关