优化代码生成模板
This commit is contained in:
parent
8dc832cdbd
commit
9292396bb2
@ -6,7 +6,6 @@ using Microsoft.Extensions.Options;
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using ZR.Admin.WebApi.Filters;
|
using ZR.Admin.WebApi.Filters;
|
||||||
using ZR.Common;
|
|
||||||
|
|
||||||
namespace ZR.Admin.WebApi.Controllers
|
namespace ZR.Admin.WebApi.Controllers
|
||||||
{
|
{
|
||||||
|
|||||||
@ -148,7 +148,7 @@ export default {
|
|||||||
// 多选框选中数据
|
// 多选框选中数据
|
||||||
handleSelectionChange(selection) {
|
handleSelectionChange(selection) {
|
||||||
this.ids = selection.map((item) => item.{PrimaryKey});
|
this.ids = selection.map((item) => item.{PrimaryKey});
|
||||||
this.single = selection.length !=1
|
this.single = selection.length != 1
|
||||||
this.multiple = !selection.length;
|
this.multiple = !selection.length;
|
||||||
},
|
},
|
||||||
/** 搜索按钮操作 */
|
/** 搜索按钮操作 */
|
||||||
@ -174,14 +174,13 @@ export default {
|
|||||||
this.reset();
|
this.reset();
|
||||||
const {PrimaryKey} = row.{PrimaryKey} || this.ids;
|
const {PrimaryKey} = row.{PrimaryKey} || this.ids;
|
||||||
get{ModelTypeName}({PrimaryKey}).then((res) => {
|
get{ModelTypeName}({PrimaryKey}).then((res) => {
|
||||||
if(res.code == 200){
|
if (res.code == 200) {
|
||||||
this.form = res.data;
|
this.form = res.data;
|
||||||
this.open = true;
|
this.open = true;
|
||||||
this.title = "修改数据";
|
this.title = "修改数据";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
beforeFileUpload(file) { },
|
|
||||||
{vueJsMethod}
|
{vueJsMethod}
|
||||||
/** 提交按钮 */
|
/** 提交按钮 */
|
||||||
submitForm: function () {
|
submitForm: function () {
|
||||||
|
|||||||
@ -87,8 +87,9 @@ namespace ZR.CodeGenerator
|
|||||||
/// 生成vuejs模板,目前只有上传文件方法
|
/// 生成vuejs模板,目前只有上传文件方法
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dbFieldInfo"></param>
|
/// <param name="dbFieldInfo"></param>
|
||||||
|
/// <param name="replaceDto"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string GetVueJsMethod(GenTableColumn dbFieldInfo)
|
public static void TplVueJsMethod(GenTableColumn dbFieldInfo, ReplaceDto replaceDto)
|
||||||
{
|
{
|
||||||
string columnName = dbFieldInfo.ColumnName;
|
string columnName = dbFieldInfo.ColumnName;
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
@ -100,6 +101,8 @@ namespace ZR.CodeGenerator
|
|||||||
sb.AppendLine($" this.form.{columnName} = URL.createObjectURL(file.raw);");
|
sb.AppendLine($" this.form.{columnName} = URL.createObjectURL(file.raw);");
|
||||||
sb.AppendLine($" // this.$refs.upload.clearFiles();");
|
sb.AppendLine($" // this.$refs.upload.clearFiles();");
|
||||||
sb.AppendLine($" }},");
|
sb.AppendLine($" }},");
|
||||||
|
replaceDto.VueBeforeUpload = TplJsBeforeUpload();
|
||||||
|
replaceDto.VueUploadUrl = TplJsUploadUrl();
|
||||||
}
|
}
|
||||||
//有下拉框选项初列表查询数据
|
//有下拉框选项初列表查询数据
|
||||||
if ((dbFieldInfo.HtmlType == GenConstants.HTML_SELECT || dbFieldInfo.HtmlType == GenConstants.HTML_RADIO) && !string.IsNullOrEmpty(dbFieldInfo.DictType))
|
if ((dbFieldInfo.HtmlType == GenConstants.HTML_SELECT || dbFieldInfo.HtmlType == GenConstants.HTML_RADIO) && !string.IsNullOrEmpty(dbFieldInfo.DictType))
|
||||||
@ -109,7 +112,7 @@ namespace ZR.CodeGenerator
|
|||||||
sb.AppendLine(@$" return this.selectDictLabel(this.{columnName}Options, row.{columnName});");
|
sb.AppendLine(@$" return this.selectDictLabel(this.{columnName}Options, row.{columnName});");
|
||||||
sb.AppendLine(@" },");
|
sb.AppendLine(@" },");
|
||||||
}
|
}
|
||||||
return sb.ToString();
|
replaceDto.VueJsMethod += sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -117,7 +120,7 @@ namespace ZR.CodeGenerator
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dbFieldInfo"></param>
|
/// <param name="dbFieldInfo"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string GetFormRules(GenTableColumn dbFieldInfo)
|
public static string TplFormRules(GenTableColumn dbFieldInfo)
|
||||||
{
|
{
|
||||||
StringBuilder sbRule = new StringBuilder();
|
StringBuilder sbRule = new StringBuilder();
|
||||||
//Rule 规则验证
|
//Rule 规则验证
|
||||||
@ -137,7 +140,7 @@ namespace ZR.CodeGenerator
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dbFieldInfo"></param>
|
/// <param name="dbFieldInfo"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string GetVueViewFormContent(GenTableColumn dbFieldInfo)
|
public static string TplVueFormContent(GenTableColumn dbFieldInfo)
|
||||||
{
|
{
|
||||||
string columnName = dbFieldInfo.ColumnName;
|
string columnName = dbFieldInfo.ColumnName;
|
||||||
string labelName = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, columnName);
|
string labelName = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, columnName);
|
||||||
@ -174,8 +177,8 @@ namespace ZR.CodeGenerator
|
|||||||
//图片
|
//图片
|
||||||
sb.AppendLine(" <el-col :span=\"24\">");
|
sb.AppendLine(" <el-col :span=\"24\">");
|
||||||
sb.AppendLine($" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">");
|
sb.AppendLine($" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">");
|
||||||
sb.AppendLine($" <el-upload class=\"avatar-uploader\" name=\"file\" action=\"/api/upload/saveFile/\" :show-file-list=\"false\" :on-success=\"handleUpload{dbFieldInfo.CsharpField}Success\" :before-upload=\"beforeFileUpload\">");
|
sb.AppendLine($" <el-upload class=\"avatar-uploader\" name=\"file\" :action=\"uploadUrl\" :show-file-list=\"false\" :on-success=\"handleUpload{dbFieldInfo.CsharpField}Success\" :before-upload=\"beforeFileUpload\">");
|
||||||
sb.AppendLine($" <img v-if=\"form.{columnName}\" :src=\"form.{columnName}\" class=\"icon\">");
|
sb.AppendLine($" <el-image v-if=\"form.{columnName}\" :src=\"form.{columnName}\" class=\"icon\"/>");
|
||||||
sb.AppendLine(" <i v-else class=\"el-icon-plus uploader-icon\"></i>");
|
sb.AppendLine(" <i v-else class=\"el-icon-plus uploader-icon\"></i>");
|
||||||
sb.AppendLine(" </el-upload>");
|
sb.AppendLine(" </el-upload>");
|
||||||
sb.AppendLine($" <el-input v-model=\"form.{columnName}\" placeholder=\"请上传文件或手动输入文件地址\"></el-input>");
|
sb.AppendLine($" <el-input v-model=\"form.{columnName}\" placeholder=\"请上传文件或手动输入文件地址\"></el-input>");
|
||||||
@ -249,7 +252,7 @@ namespace ZR.CodeGenerator
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dbFieldInfo"></param>
|
/// <param name="dbFieldInfo"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string GetQueryFormHtml(GenTableColumn dbFieldInfo)
|
public static string TplQueryFormHtml(GenTableColumn dbFieldInfo)
|
||||||
{
|
{
|
||||||
StringBuilder sb = new();
|
StringBuilder sb = new();
|
||||||
string labelName = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, dbFieldInfo.ColumnName);
|
string labelName = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, dbFieldInfo.ColumnName);
|
||||||
@ -276,7 +279,7 @@ namespace ZR.CodeGenerator
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dbFieldInfo"></param>
|
/// <param name="dbFieldInfo"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string GetTableColumn(GenTableColumn dbFieldInfo)
|
public static string TplTableColumn(GenTableColumn dbFieldInfo)
|
||||||
{
|
{
|
||||||
string columnName = dbFieldInfo.ColumnName;
|
string columnName = dbFieldInfo.ColumnName;
|
||||||
string label = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, columnName);
|
string label = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, columnName);
|
||||||
@ -307,6 +310,36 @@ namespace ZR.CodeGenerator
|
|||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 文件上传前方法判断
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string TplJsBeforeUpload()
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.AppendLine(@" //文件上传前判断方法");
|
||||||
|
sb.AppendLine(@" beforeFileUpload(file) {");
|
||||||
|
sb.AppendLine(@" const isJPG = file.type === ""image/jpeg"";");
|
||||||
|
sb.AppendLine(@" const isLt2M = file.size / 1024 / 1024 < 2;");
|
||||||
|
sb.AppendLine(@" if (!isJPG) {");
|
||||||
|
sb.AppendLine(@" this.msgError(""上传图片只能是 JPG 格式!"");");
|
||||||
|
sb.AppendLine(@" }");
|
||||||
|
sb.AppendLine(@" if (!isLt2M) {");
|
||||||
|
sb.AppendLine(@" this.msgError(""上传图片大小不能超过 2MB!"");");
|
||||||
|
sb.AppendLine(@" }");
|
||||||
|
sb.AppendLine(@" return isJPG && isLt2M;");
|
||||||
|
sb.AppendLine(@" },");
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
public static string TplJsUploadUrl()
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.AppendLine(@" //文件上传前判断方法");
|
||||||
|
sb.AppendLine(@" uploadUrl: process.env.VUE_APP_BASE_API + ""/upload/SaveFile/"",");
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public static string QueryExp(string propertyName, string queryType)
|
public static string QueryExp(string propertyName, string queryType)
|
||||||
|
|||||||
@ -102,15 +102,17 @@ namespace ZR.CodeGenerator
|
|||||||
|
|
||||||
CodeGenerateTemplate.GetQueryDtoProperty(dbFieldInfo, replaceDto);
|
CodeGenerateTemplate.GetQueryDtoProperty(dbFieldInfo, replaceDto);
|
||||||
replaceDto.ModelProperty += CodeGenerateTemplate.GetModelTemplate(dbFieldInfo);
|
replaceDto.ModelProperty += CodeGenerateTemplate.GetModelTemplate(dbFieldInfo);
|
||||||
replaceDto.VueViewFormHtml += CodeGenerateTemplate.GetVueViewFormContent(dbFieldInfo);
|
replaceDto.VueViewFormHtml += CodeGenerateTemplate.TplVueFormContent(dbFieldInfo);
|
||||||
replaceDto.VueJsMethod += CodeGenerateTemplate.GetVueJsMethod(dbFieldInfo);
|
CodeGenerateTemplate.TplVueJsMethod(dbFieldInfo, replaceDto);
|
||||||
replaceDto.VueViewListHtml += CodeGenerateTemplate.GetTableColumn(dbFieldInfo);
|
replaceDto.VueViewListHtml += CodeGenerateTemplate.TplTableColumn(dbFieldInfo);
|
||||||
replaceDto.VueViewEditFormRuleContent += CodeGenerateTemplate.GetFormRules(dbFieldInfo);
|
replaceDto.VueViewEditFormRuleContent += CodeGenerateTemplate.TplFormRules(dbFieldInfo);
|
||||||
replaceDto.InputDtoProperty += CodeGenerateTemplate.GetDtoProperty(dbFieldInfo);
|
replaceDto.InputDtoProperty += CodeGenerateTemplate.GetDtoProperty(dbFieldInfo);
|
||||||
replaceDto.VueQueryFormHtml += CodeGenerateTemplate.GetQueryFormHtml(dbFieldInfo);
|
replaceDto.VueQueryFormHtml += CodeGenerateTemplate.TplQueryFormHtml(dbFieldInfo);
|
||||||
}
|
}
|
||||||
replaceDto.VueDataContent = sb1.ToString();
|
replaceDto.VueDataContent = sb1.ToString();
|
||||||
replaceDto.MountedMethod = sb2.ToString();
|
replaceDto.MountedMethod = sb2.ToString();
|
||||||
|
replaceDto.VueJsMethod += replaceDto.VueBeforeUpload;
|
||||||
|
replaceDto.VueDataContent += replaceDto.VueUploadUrl;
|
||||||
|
|
||||||
replaceDto.PKName = PKName;
|
replaceDto.PKName = PKName;
|
||||||
replaceDto.PKType = PKType;
|
replaceDto.PKType = PKType;
|
||||||
@ -526,7 +528,7 @@ namespace ZR.CodeGenerator
|
|||||||
genTableColumn.HtmlType = GenConstants.HTML_TEXTAREA;
|
genTableColumn.HtmlType = GenConstants.HTML_TEXTAREA;
|
||||||
}
|
}
|
||||||
//编辑字段
|
//编辑字段
|
||||||
if (column.IsIdentity || column.IsPrimarykey || GenConstants.COLUMNNAME_NOT_EDIT.Any(f => column.DbColumnName.Contains(f)) )
|
if (column.IsIdentity || column.IsPrimarykey || GenConstants.COLUMNNAME_NOT_EDIT.Any(f => column.DbColumnName.Contains(f)))
|
||||||
{
|
{
|
||||||
genTableColumn.IsEdit = false;
|
genTableColumn.IsEdit = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,6 +97,14 @@ namespace ZR.CodeGenerator.Model
|
|||||||
/// vue组件导入
|
/// vue组件导入
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string VueComponentImport { get; set; } = "";
|
public string VueComponentImport { get; set; } = "";
|
||||||
|
/// <summary>
|
||||||
|
/// 上传前js
|
||||||
|
/// </summary>
|
||||||
|
public string VueBeforeUpload { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 上传URL data
|
||||||
|
/// </summary>
|
||||||
|
public string VueUploadUrl { get; set; }
|
||||||
public string Author { get; set; }
|
public string Author { get; set; }
|
||||||
public string AddTime { get; set; } = DateTime.Now.ToString("yyyy-MM-dd");
|
public string AddTime { get; set; } = DateTime.Now.ToString("yyyy-MM-dd");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,9 +10,9 @@ namespace ZR.Model.System.Generate
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[SqlSugar.SugarTable("gen_table_column")]
|
[SqlSugar.SugarTable("gen_table_column")]
|
||||||
[SqlSugar.Tenant("0")]
|
[SqlSugar.Tenant("0")]
|
||||||
public class GenTableColumn: SysBase
|
public class GenTableColumn : SysBase
|
||||||
{
|
{
|
||||||
[SqlSugar.SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
|
[SqlSugar.SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
|
||||||
public int ColumnId { get; set; }
|
public int ColumnId { get; set; }
|
||||||
public string ColumnName { get; set; }
|
public string ColumnName { get; set; }
|
||||||
[SqlSugar.SugarColumn(IsOnlyIgnoreUpdate = true)]
|
[SqlSugar.SugarColumn(IsOnlyIgnoreUpdate = true)]
|
||||||
@ -66,7 +66,7 @@ namespace ZR.Model.System.Generate
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 字典集合
|
/// 字典集合
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SqlSugar.SugarColumn(IsIgnore = true)]
|
//[SqlSugar.SugarColumn(IsIgnore = true)]
|
||||||
public List<SysDictData> DictDatas { get; set; }
|
//public List<SysDictData> DictDatas { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user