优化代码生成table列表模板
This commit is contained in:
parent
86169361aa
commit
80517e208b
45
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TableList.txt
Normal file
45
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TableList.txt
Normal file
@ -0,0 +1,45 @@
|
||||
$foreach(column in genTable.Columns)
|
||||
$set(labelName = "")
|
||||
$set(checkboxHtml = "")
|
||||
$set(showToolTipHtml = "")
|
||||
$set(columnName = column.CsharpFieldFl)
|
||||
$if(column.CsharpType == "string" || column.HtmlType == "datetime")
|
||||
$set(showToolTipHtml = " :show-overflow-tooltip=\"true\"")
|
||||
$end
|
||||
$if(column.ColumnComment != "")
|
||||
$set(labelName = column.ColumnComment)
|
||||
$else
|
||||
$set(labelName = column.CsharpFieldFl)
|
||||
$end
|
||||
$if(column.IsList == true)
|
||||
$if(column.HtmlType == "customInput" && column.IsPk == false)
|
||||
<el-table-column prop="${columnName}" label="${labelName}" width="90" sortable align="center">
|
||||
<template slot-scope="scope">;
|
||||
<span v-show="editIndex != scope.${index}index" @click="editCurrRow(scope.${index}index,'rowkeY')">{{{{scope.row.${columnName}}}}}</span>
|
||||
<el-input :id="scope.${index}index+'rowkeY'" size="mini" v-show="(editIndex == scope.${index}index)"
|
||||
v-model="scope.row.${columnName}" @blur="handleChangeSort(scope.row)"></el-input>
|
||||
</template>
|
||||
</el-table-column>
|
||||
$elseif(column.HtmlType == "imageUpload")
|
||||
<el-table-column prop="${columnName}" align="center" label="${labelName}">
|
||||
<template slot-scope="scope">
|
||||
<el-image class="table-td-thumb" fit="contain" :src="scope.row.${columnName}" :preview-src-list="[scope.row.${columnName}]">
|
||||
<div slot="error"><i class="el-icon-document" /></div>
|
||||
</el-image>
|
||||
</template>
|
||||
</el-table-column>
|
||||
$elseif(column.HtmlType == "checkbox" || column.HtmlType == "select" || column.HtmlType == "radio")
|
||||
<el-table-column label="${labelName}" align="center" prop="${columnName}">
|
||||
<template slot-scope="scope">
|
||||
$if(column.HtmlType == "checkbox")
|
||||
<dict-tag :options="${columnName}Options" :value="scope.row.${columnName} ? scope.row.${columnName}.split(',') : []" />
|
||||
$else
|
||||
<dict-tag :options="${columnName}Options" :value="scope.row.${columnName}" />
|
||||
$end
|
||||
</template>
|
||||
</el-table-column>
|
||||
$else
|
||||
<el-table-column prop="${columnName}" label="${labelName}" align="center"${showToolTipHtml} />
|
||||
$end
|
||||
$end
|
||||
$end
|
||||
@ -203,59 +203,59 @@ namespace ZR.CodeGenerator
|
||||
// return sb.ToString();
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Vue 查询列表
|
||||
/// </summary>
|
||||
/// <param name="dbFieldInfo"></param>
|
||||
/// <param name="genTable"></param>
|
||||
/// <returns></returns>
|
||||
public static string TplTableColumn(GenTableColumn dbFieldInfo, GenTable genTable)
|
||||
{
|
||||
string columnName = dbFieldInfo.CsharpFieldFl;
|
||||
string label = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, columnName);
|
||||
string showToolTip = ShowToolTip(dbFieldInfo);
|
||||
string formatter = GetFormatter(dbFieldInfo.HtmlType, columnName);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
//自定义排序字段
|
||||
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($@" <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>");
|
||||
}
|
||||
else if (dbFieldInfo.IsList && dbFieldInfo.HtmlType.Equals(GenConstants.HTML_IMAGE_UPLOAD))
|
||||
{
|
||||
sb.AppendLine($" <el-table-column prop=\"{columnName}\" align=\"center\" label=\"{label}\">");
|
||||
sb.AppendLine(" <template slot-scope=\"scope\">");
|
||||
sb.AppendLine($" <el-image class=\"table-td-thumb\" fit=\"contain\" :src=\"scope.row.{columnName}\" :preview-src-list=\"[scope.row.{columnName}]\">");
|
||||
sb.AppendLine(" <div slot=\"error\"><i class=\"el-icon-document\" /></div>");
|
||||
sb.AppendLine(" </el-image>");
|
||||
sb.AppendLine(" </template>");
|
||||
sb.AppendLine(" </el-table-column>");
|
||||
}
|
||||
else if (dbFieldInfo.IsList && !string.IsNullOrEmpty(formatter))
|
||||
{
|
||||
sb.AppendLine($@" <el-table-column label=""{label}"" align=""center"" prop=""{columnName}"">");
|
||||
sb.AppendLine(@" <template slot-scope=""scope"">");
|
||||
string checkboxHtml = string.Empty;
|
||||
if (dbFieldInfo.HtmlType == GenConstants.HTML_CHECKBOX)
|
||||
{
|
||||
checkboxHtml = $" ? scope.row.{columnName}.split(',') : []";
|
||||
}
|
||||
sb.AppendLine($" <dict-tag :options=\"{columnName}Options\" :value=\"scope.row.{columnName}{checkboxHtml}\"/>");
|
||||
sb.AppendLine(@" </template>");
|
||||
sb.AppendLine(@" </el-table-column>");
|
||||
}
|
||||
else if (dbFieldInfo.IsList)
|
||||
{
|
||||
sb.AppendLine($" <el-table-column prop=\"{columnName}\" label=\"{label}\" align=\"center\"{showToolTip}{formatter}/>");
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
///// <summary>
|
||||
///// Vue 查询列表
|
||||
///// </summary>
|
||||
///// <param name="dbFieldInfo"></param>
|
||||
///// <param name="genTable"></param>
|
||||
///// <returns></returns>
|
||||
//public static string TplTableColumn(GenTableColumn dbFieldInfo, GenTable genTable)
|
||||
//{
|
||||
// string columnName = dbFieldInfo.CsharpFieldFl;
|
||||
// string label = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, columnName);
|
||||
// string showToolTip = ShowToolTip(dbFieldInfo);
|
||||
// string formatter = GetFormatter(dbFieldInfo.HtmlType, columnName);
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// //自定义排序字段
|
||||
// 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($@" <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>");
|
||||
// }
|
||||
// else if (dbFieldInfo.IsList && dbFieldInfo.HtmlType.Equals(GenConstants.HTML_IMAGE_UPLOAD))
|
||||
// {
|
||||
// sb.AppendLine($" <el-table-column prop=\"{columnName}\" align=\"center\" label=\"{label}\">");
|
||||
// sb.AppendLine(" <template slot-scope=\"scope\">");
|
||||
// sb.AppendLine($" <el-image class=\"table-td-thumb\" fit=\"contain\" :src=\"scope.row.{columnName}\" :preview-src-list=\"[scope.row.{columnName}]\">");
|
||||
// sb.AppendLine(" <div slot=\"error\"><i class=\"el-icon-document\" /></div>");
|
||||
// sb.AppendLine(" </el-image>");
|
||||
// sb.AppendLine(" </template>");
|
||||
// sb.AppendLine(" </el-table-column>");
|
||||
// }
|
||||
// else if (dbFieldInfo.IsList && !string.IsNullOrEmpty(formatter))
|
||||
// {
|
||||
// sb.AppendLine($@" <el-table-column label=""{label}"" align=""center"" prop=""{columnName}"">");
|
||||
// sb.AppendLine(@" <template slot-scope=""scope"">");
|
||||
// string checkboxHtml = string.Empty;
|
||||
// if (dbFieldInfo.HtmlType == GenConstants.HTML_CHECKBOX)
|
||||
// {
|
||||
// checkboxHtml = $" ? scope.row.{columnName}.split(',') : []";
|
||||
// }
|
||||
// sb.AppendLine($" <dict-tag :options=\"{columnName}Options\" :value=\"scope.row.{columnName}{checkboxHtml}\"/>");
|
||||
// sb.AppendLine(@" </template>");
|
||||
// sb.AppendLine(@" </el-table-column>");
|
||||
// }
|
||||
// else if (dbFieldInfo.IsList)
|
||||
// {
|
||||
// sb.AppendLine($" <el-table-column prop=\"{columnName}\" label=\"{label}\" align=\"center\"{showToolTip}{formatter}/>");
|
||||
// }
|
||||
// return sb.ToString();
|
||||
//}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -51,6 +51,7 @@ namespace ZR.CodeGenerator
|
||||
replaceDto.ShowBtnDelete = dto.GenTable.CheckedBtn.Any(f => f == 3);
|
||||
replaceDto.ShowBtnExport = dto.GenTable.CheckedBtn.Any(f => f == 4);
|
||||
|
||||
|
||||
//循环表字段信息
|
||||
foreach (GenTableColumn dbFieldInfo in dto.GenTable.Columns.OrderBy(x => x.Sort))
|
||||
{
|
||||
@ -67,7 +68,7 @@ namespace ZR.CodeGenerator
|
||||
//CodeGenerateTemplate.GetQueryDtoProperty(dbFieldInfo, replaceDto);
|
||||
|
||||
replaceDto.VueViewFormHtml += CodeGenerateTemplate.TplVueFormContent(dbFieldInfo, dto.GenTable);
|
||||
replaceDto.VueViewListHtml += CodeGenerateTemplate.TplTableColumn(dbFieldInfo, dto.GenTable);
|
||||
//replaceDto.VueViewListHtml += CodeGenerateTemplate.TplTableColumn(dbFieldInfo, dto.GenTable);
|
||||
//replaceDto.VueQueryFormHtml += CodeGenerateTemplate.TplQueryFormHtml(dbFieldInfo);
|
||||
}
|
||||
|
||||
@ -75,8 +76,9 @@ namespace ZR.CodeGenerator
|
||||
replaceDto.PKType = PKType;
|
||||
replaceDto.FistLowerPk = PKName.FirstLowerCase();
|
||||
InitJntTemplate(dto, replaceDto);
|
||||
|
||||
replaceDto.VueViewListHtml = GenerateVueTableList();
|
||||
replaceDto.VueQueryFormHtml = GenerateVueQueryForm();
|
||||
|
||||
GenerateModels(replaceDto, dto);
|
||||
GenerateInputDto(replaceDto, dto);
|
||||
GenerateRepository(replaceDto, dto);
|
||||
@ -245,8 +247,6 @@ namespace ZR.CodeGenerator
|
||||
/// <summary>
|
||||
/// 生成vue页面查询form
|
||||
/// </summary>
|
||||
/// <param name="replaceDto"></param>
|
||||
/// <param name="generateDto"></param>
|
||||
/// <returns></returns>
|
||||
public static string GenerateVueQueryForm()
|
||||
{
|
||||
@ -254,6 +254,17 @@ namespace ZR.CodeGenerator
|
||||
var result = tpl.Render();
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// 生成vue页面table
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GenerateVueTableList()
|
||||
{
|
||||
var tpl = FileHelper.ReadJtTemplate("TableList.txt");
|
||||
var result = tpl.Render();
|
||||
Console.WriteLine(result);
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 帮助方法
|
||||
@ -467,6 +478,7 @@ namespace ZR.CodeGenerator
|
||||
options.OutMode = OutMode.Auto;
|
||||
//options.DisableeLogogram = true;//禁用简写
|
||||
options.Data.Set("refs", "$");//特殊标签替换
|
||||
options.Data.Set("index", "$");//特殊标签替换
|
||||
options.Data.Set("confirm", "$");//特殊标签替换
|
||||
options.Data.Set("nextTick", "$");
|
||||
options.Data.Set("replaceDto", replaceDto);
|
||||
|
||||
@ -26,8 +26,6 @@ import RightToolbar from "@/components/RightToolbar"
|
||||
import Editor from "@/components/Editor";
|
||||
// 字典标签组件
|
||||
import DictTag from '@/components/DictTag'
|
||||
// 字典数据组件
|
||||
// import DictData from '@/components/DictData'
|
||||
// 上传图片
|
||||
import UploadImage from '@/components/UploadImage/index';
|
||||
// 上传文件
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user