using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using ZR.CodeGenerator.CodeGenerator; using ZR.Model.System.Generate; namespace ZR.CodeGenerator { /// /// 代码生成模板 /// public class CodeGenerateTemplate { #region Template /// /// 生成vuejs模板,目前只有上传文件方法 /// /// /// public static string GetVueJsMethod(GenTableColumn dbColumnInfo) { string columnName = dbColumnInfo.ColumnName; string js = ""; if (dbColumnInfo.HtmlType.Equals(GenConstants.HTML_IMAGE_UPLOAD)) { js += $"handleUpload{columnName}Success(res, file) {{\n"; js += $" this.form.{columnName} = URL.createObjectURL(file.raw);\n"; js += " // this.$refs.upload.clearFiles();\n"; js += "},\n"; } return js; } //rules public static string GetFormRules(GenTableColumn dbFieldInfo) { string vueViewEditFromRuleContent = ""; //Rule 规则验证 if (!dbFieldInfo.IsPk && !dbFieldInfo.IsIncrement) { vueViewEditFromRuleContent += $" {dbFieldInfo.ColumnName}: [\n"; vueViewEditFromRuleContent += $" {{ required: true, message: '请输入{dbFieldInfo.ColumnComment}', trigger: \"blur\"}},\n"; vueViewEditFromRuleContent += " ],\n"; } else if (TableMappingHelper.IsNumber(dbFieldInfo.ColumnType) && dbFieldInfo.IsRequired) { vueViewEditFromRuleContent += $" {dbFieldInfo.ColumnName}: [\n"; vueViewEditFromRuleContent += $" {{ type: 'number', message: '{dbFieldInfo.ColumnName}必须为数字值', trigger: \"blur\"}},\n"; vueViewEditFromRuleContent += " ],\n"; } return vueViewEditFromRuleContent; } //model 属性 public static string GetModelTemplate(GenTableColumn dbFieldInfo) { var modelcontent = ""; modelcontent += " /// \n"; modelcontent += $" /// 描述 :{dbFieldInfo.ColumnComment}\n"; modelcontent += $" /// 空值 :{dbFieldInfo.IsRequired}\n"; modelcontent += " /// \n"; if (dbFieldInfo.IsPk || dbFieldInfo.IsIncrement) { modelcontent += $" [SqlSugar.SugarColumn(IsPrimaryKey = {dbFieldInfo.IsPk.ToString().ToLower()}, IsIdentity = {dbFieldInfo.IsIncrement.ToString().ToLower()})]\n"; } modelcontent += $" public {dbFieldInfo.CsharpType} {dbFieldInfo.CsharpField} {{ get; set; }}\n\r"; return modelcontent; } //DTO model public static string GetDtoContent(GenTableColumn dbFieldInfo) { string InputDtoContent = ""; if (dbFieldInfo.IsInsert || dbFieldInfo.IsEdit) { InputDtoContent += $" public {dbFieldInfo.CsharpType} {dbFieldInfo.CsharpField} {{ get; set; }}\n\r"; } return InputDtoContent; } //form-item public static string GetVueViewFormContent(GenTableColumn dbFieldInfo) { string columnName = dbFieldInfo.ColumnName; string labelName = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, columnName); string vueViewFromContent = ""; string labelDisabled = dbFieldInfo.IsPk ? ":disabled=\"true\"" : ""; string placeHolder = dbFieldInfo.IsIncrement ? "" : $"请输入{labelName}"; if (dbFieldInfo.HtmlType == GenConstants.HTML_DATETIME) { //时间 vueViewFromContent += $" \n"; vueViewFromContent += $" \n"; vueViewFromContent += " \n"; } else if (dbFieldInfo.HtmlType == GenConstants.HTML_IMAGE_UPLOAD) { //图片 vueViewFromContent += $" \n"; vueViewFromContent += $" \n"; vueViewFromContent += $" \n"; vueViewFromContent += " \n"; vueViewFromContent += " \n"; vueViewFromContent += $" \n"; vueViewFromContent += " \n"; } else if (dbFieldInfo.HtmlType == GenConstants.HTML_RADIO) { vueViewFromContent += $" \n"; vueViewFromContent += $" \n"; vueViewFromContent += " \n"; vueViewFromContent += " \n"; vueViewFromContent += " \n"; vueViewFromContent += " \n"; } else if (dbFieldInfo.HtmlType == GenConstants.HTML_TEXTAREA) { vueViewFromContent += $" \n"; vueViewFromContent += $" \n"; vueViewFromContent += " \n"; } else { string inputNumTxt = TableMappingHelper.IsNumber(dbFieldInfo.CsharpType) ? ".number" : ""; vueViewFromContent += $" \n"; vueViewFromContent += $" \n"; vueViewFromContent += " \n"; } return vueViewFromContent; } //table-column public static string GetTableColumn(GenTableColumn dbFieldInfo) { string columnName = dbFieldInfo.ColumnName; string label = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, columnName); string vueViewListContent = ""; string showToolTip = dbFieldInfo.ColumnType.Contains("varchar") ? ":show-overflow-tooltip=\"true\"" : ""; if (!dbFieldInfo.IsQuery) { return vueViewListContent; } if (dbFieldInfo.HtmlType.Equals(GenConstants.HTML_IMAGE_UPLOAD)) { vueViewListContent += $" \n"; vueViewListContent += " \n"; vueViewListContent += " \n"; } //else if (dbFieldInfo.HtmlType.Equals(GenConstants.HTML_RADIO)) //{ // vueViewListContent += $" \n"; // vueViewListContent += " \n"; // vueViewListContent += " \n"; //} else { //table-column vueViewListContent += $" \n"; } return vueViewListContent; } #endregion } }