优化代码生成

更换代码生成上级菜单选择组件
代码生成新增前端路径配置
This commit is contained in:
不做码农
2022-05-26 20:48:49 +08:00
8 changed files with 107 additions and 229 deletions

View File

@@ -10,161 +10,6 @@ namespace ZR.CodeGenerator
/// </summary>
public class CodeGenerateTemplate
{
#region vue
///// <summary>
///// Vue 添加修改表单
///// </summary>
///// <param name="dbFieldInfo"></param>
///// <returns></returns>
//public static string TplVueFormContent(GenTableColumn dbFieldInfo, GenTable genTable)
//{
// string columnName = dbFieldInfo.CsharpFieldFl;
// string labelName = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, columnName);
// string labelDisabled = dbFieldInfo.IsPk ? ":disabled=\"true\"" : "";
// StringBuilder sb = new();
// string value = CodeGeneratorTool.IsNumber(dbFieldInfo.CsharpType) ? "parseInt(item.dictValue)" : "item.dictValue";
// if (GenConstants.inputDtoNoField.Any(f => f.Contains(dbFieldInfo.CsharpField, StringComparison.OrdinalIgnoreCase)))
// {
// }
// else if (!dbFieldInfo.IsInsert && !dbFieldInfo.IsEdit)
// {
// sb.AppendLine(" <el-col :lg=\"12\" v-if=\"opertype == 2\">");
// sb.AppendLine($" <el-form-item label=\"{labelName}\">{{{{form.{columnName}}}}}</el-form-item>");
// sb.AppendLine(" </el-col>");
// }
// else if (genTable.TplCategory.Equals("tree", StringComparison.OrdinalIgnoreCase) && genTable.TreeParentCode != null && dbFieldInfo.CsharpField.Equals(genTable.TreeParentCode))
// {
// //树
// sb.AppendLine(@" <el-col :lg=""24"">");
// sb.AppendLine($@" <el-form-item label=""父级id"" prop=""{columnName}"">");
// sb.AppendLine($@" <treeselect v-model=""form.{columnName}"" :options=""dataList"" :normalizer=""normalizer"" :show-count=""true"" placeholder=""选择上级菜单"" />");
// sb.AppendLine(@" </el-form-item>");
// sb.AppendLine(@" </el-col>");
// }
// //主键、非自增要插入,不能编辑
// else if (dbFieldInfo.IsPk || dbFieldInfo.IsIncrement)
// {
// sb.AppendLine(" <el-col :lg=\"12\">");
// sb.AppendLine($" <el-form-item label=\"{labelName}\" prop=\"{columnName}\">");
// //主键非自增 显示input
// if (!dbFieldInfo.IsIncrement)
// {
// sb.AppendLine($" <el-input-number v-model.number=\"form.{columnName}\" controls-position=\"right\" placeholder=\"请输入{labelName}\" :disabled=\"title=='修改数据'\"/>");
// }
// else if (dbFieldInfo.IsIncrement) //只有是 自增 就显示label
// {
// sb.AppendLine($" <span v-html=\"form.{columnName}\"/>");
// }
// sb.AppendLine(" </el-form-item>");
// sb.AppendLine(" </el-col>");
// }
// else
// {
// if (dbFieldInfo.HtmlType == GenConstants.HTML_INPUT_NUMBER)
// {
// //数字框
// sb.AppendLine(" <el-col :lg=\"12\">");
// sb.AppendLine($" <el-form-item label=\"{labelName}\" prop=\"{columnName}\">");
// sb.AppendLine($" <el-input-number v-model.number=\"form.{columnName}\" controls-position=\"right\" placeholder=\"请输入{labelName}\" {labelDisabled}/>");
// sb.AppendLine(" </el-form-item>");
// sb.AppendLine(" </el-col>");
// }
// else if (dbFieldInfo.HtmlType == GenConstants.HTML_DATETIME)
// {
// //时间
// sb.AppendLine(" <el-col :lg=\"12\">");
// sb.AppendLine($" <el-form-item label=\"{labelName}\" prop=\"{columnName}\">");
// sb.AppendLine($" <el-date-picker v-model=\"form.{columnName}\" format=\"yyyy-MM-dd HH:mm:ss\" value-format=\"yyyy-MM-dd HH:mm:ss\" type=\"datetime\" placeholder=\"选择日期时间\"> </el-date-picker>");
// sb.AppendLine(" </el-form-item>");
// sb.AppendLine(" </el-col>");
// }
// else if (dbFieldInfo.HtmlType == GenConstants.HTML_IMAGE_UPLOAD)
// {
// //图片
// sb.AppendLine(" <el-col :lg=\"24\">");
// sb.AppendLine($" <el-form-item label=\"{labelName}\" prop=\"{columnName}\">");
// sb.AppendLine($@" <UploadImage v-model=""form.{columnName}"" column=""{columnName}"" @input=""handleUploadSuccess"" />");
// sb.AppendLine(" </el-form-item>");
// sb.AppendLine(" </el-col>");
// }
// else if (dbFieldInfo.HtmlType == GenConstants.HTML_FILE_UPLOAD)
// {
// //文件
// sb.AppendLine(" <el-col :lg=\"24\">");
// sb.AppendLine($" <el-form-item label=\"{labelName}\" prop=\"{columnName}\">");
// sb.AppendLine($@" <UploadFile v-model=""form.{columnName}"" column=""{columnName}"" @input=""handleUploadSuccess"" />");
// sb.AppendLine(" </el-form-item>");
// sb.AppendLine(" </el-col>");
// }
// else if (dbFieldInfo.HtmlType == GenConstants.HTML_RADIO)
// {
// //单选按钮
// sb.AppendLine(" <el-col :lg=\"12\">");
// sb.AppendLine($" <el-form-item label=\"{labelName}\" prop=\"{columnName}\">");
// sb.AppendLine($" <el-radio-group v-model=\"form.{columnName}\">");
// sb.AppendLine($" <el-radio v-for=\"item in {columnName}Options\" :key=\"item.dictValue\" :label=\"{value}\">{{{{item.dictLabel}}}}</el-radio>");
// sb.AppendLine(" </el-radio-group>");
// sb.AppendLine(" </el-form-item>");
// sb.AppendLine(" </el-col>");
// }
// else if (dbFieldInfo.HtmlType == GenConstants.HTML_TEXTAREA)
// {
// //文本域
// sb.AppendLine(" <el-col :lg=\"24\">");
// sb.AppendLine($" <el-form-item label=\"{ labelName}\" prop=\"{columnName}\">");
// sb.AppendLine($" <el-input type=\"textarea\" v-model=\"form.{columnName}\" placeholder=\"请输入{labelName}\"/>");
// sb.AppendLine(" </el-form-item>");
// sb.AppendLine(" </el-col>");
// }
// else if (dbFieldInfo.HtmlType == GenConstants.HTML_EDITOR)
// {
// //编辑器
// sb.AppendLine(" <el-col :lg=\"24\">");
// sb.AppendLine($" <el-form-item label=\"{labelName}\" prop=\"{columnName}\">");
// sb.AppendLine($" <editor v-model=\"form.{columnName}\" :min-height=\"200\" />");
// sb.AppendLine(" </el-form-item>");
// sb.AppendLine(" </el-col>");
// }
// else if (dbFieldInfo.HtmlType == GenConstants.HTML_SELECT)
// {
// //下拉框
// sb.AppendLine(" <el-col :lg=\"12\">");
// sb.AppendLine($" <el-form-item label=\"{labelName}\" prop=\"{columnName}\">");
// sb.AppendLine($" <el-select v-model=\"form.{columnName}\" placeholder=\"请选择{labelName}\"> ");
// sb.AppendLine($" <el-option v-for=\"item in {columnName}Options\" :key=\"item.dictValue\" :label=\"item.dictLabel\" :value=\"{value}\"></el-option>");
// sb.AppendLine(" </el-select>");
// sb.AppendLine(" </el-form-item>");
// sb.AppendLine(" </el-col>");
// }
// else if (dbFieldInfo.HtmlType == GenConstants.HTML_CHECKBOX)
// {
// //多选框
// sb.AppendLine(" <el-col :lg=\"24\">");
// sb.AppendLine($" <el-form-item label=\"{labelName}\" prop=\"{columnName}\">");
// sb.AppendLine($" <el-checkbox-group v-model=\"form.{columnName}Checked\"> ");
// sb.AppendLine($" <el-checkbox v-for=\"item in {columnName}Options\" :key=\"item.dictValue\" :label=\"item.dictValue\">{{{{item.dictLabel}}}}</el-checkbox>");
// sb.AppendLine(" </el-checkbox-group>");
// sb.AppendLine(" </el-form-item>");
// sb.AppendLine(" </el-col>");
// }
// else
// {
// string inputNumTxt = CodeGeneratorTool.IsNumber(dbFieldInfo.CsharpType) ? ".number" : "";
// sb.AppendLine(" <el-col :lg=\"12\">");
// sb.AppendLine($" <el-form-item label=\"{labelName}\" prop=\"{columnName}\">");
// sb.AppendLine($" <el-input v-model{inputNumTxt}=\"form.{columnName}\" placeholder=\"请输入{labelName}\" {labelDisabled}/>");
// sb.AppendLine(" </el-form-item>");
// sb.AppendLine(" </el-col>");
// }
// }
// return sb.ToString();
//}
#endregion
//模板调用
public static string QueryExp(string propertyName, string queryType)
{

View File

@@ -38,8 +38,12 @@ namespace ZR.CodeGenerator
_option.ServicesNamespace = _option.BaseNamespace + "Service";
_option.ApiControllerNamespace = _option.BaseNamespace + "Admin.WebApi";
var vuePath = AppSettings.GetConfig("gen:vuePath");
dto.VueParentPath = dto.VueVersion == 3 ? "ZRAdmin-vue" : "ZR.Vue";
if (!vuePath.IsEmpty())
{
dto.VueParentPath = vuePath;
}
dto.GenOptions = _option;
string PKName = "Id";
@@ -52,6 +56,7 @@ namespace ZR.CodeGenerator
replaceDto.ShowBtnEdit = dto.GenTable.Options.CheckedBtn.Any(f => f == 2);
replaceDto.ShowBtnDelete = dto.GenTable.Options.CheckedBtn.Any(f => f == 3);
replaceDto.ShowBtnExport = dto.GenTable.Options.CheckedBtn.Any(f => f == 4);
replaceDto.ShowBtnView = dto.GenTable.Options.CheckedBtn.Any(f => f == 5);
//循环表字段信息

View File

@@ -47,6 +47,7 @@ namespace ZR.CodeGenerator.Model
public bool ShowBtnAdd { get; set; }
public bool ShowBtnEdit { get; set; }
public bool ShowBtnDelete { get; set; }
public bool ShowBtnView { get; set; }
/// <summary>
/// 上传URL data
/// </summary>