From 2f132a33e1f08c58e28f2b36ef6c746c000e757e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Thu, 28 Apr 2022 19:57:53 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90C#=E5=B1=9E=E6=80=A7=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Infrastructure/Extensions/StringExtension.cs | 84 +++++++++++++++++++ .../wwwroot/CodeGenTemplate/v3/README.txt | 0 .../wwwroot/CodeGenTemplate/v3/TreeVue.txt | 14 ++-- .../wwwroot/CodeGenTemplate/v3/Vue.txt | 22 +++-- ZR.CodeGenerator/CodeGeneratorTool.cs | 2 +- 5 files changed, 102 insertions(+), 20 deletions(-) delete mode 100644 ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/README.txt diff --git a/Infrastructure/Extensions/StringExtension.cs b/Infrastructure/Extensions/StringExtension.cs index 7db3ffd..d00fd7b 100644 --- a/Infrastructure/Extensions/StringExtension.cs +++ b/Infrastructure/Extensions/StringExtension.cs @@ -144,5 +144,89 @@ namespace Infrastructure.Extensions } return result; } + + /// + /// 转换为Pascal风格-每一个单词的首字母大写 + /// + /// 字段名 + /// 分隔符 + /// + public static string ConvertToPascal(this string fieldName, string fieldDelimiter) + { + string result = string.Empty; + if (fieldName.Contains(fieldDelimiter)) + { + //全部小写 + string[] array = fieldName.ToLower().Split(fieldDelimiter.ToCharArray()); + foreach (var t in array) + { + //首字母大写 + result += t.Substring(0, 1).ToUpper() + t[1..]; + } + } + else if (string.IsNullOrWhiteSpace(fieldName)) + { + result = fieldName; + } + else if (fieldName.Length == 1) + { + result = fieldName.ToUpper(); + } + else if (fieldName.Length == CountUpper(fieldName)) + { + result = fieldName.Substring(0, 1).ToUpper() + fieldName[1..].ToLower(); + } + else + { + result = fieldName.Substring(0, 1).ToUpper() + fieldName[1..]; + } + return result; + } + + /// + /// 大写字母个数 + /// + /// + /// + public static int CountUpper(this string str) + { + int count1 = 0; + char[] chars = str.ToCharArray(); + foreach (char num in chars) + { + if (num >= 'A' && num <= 'Z') + { + count1++; + } + //else if (num >= 'a' && num <= 'z') + //{ + // count2++; + //} + } + return count1; + } + + /// + /// 转换为Camel风格-第一个单词小写,其后每个单词首字母大写 + /// + /// 字段名 + /// 分隔符 + /// + public static string ConvertToCamel(this string fieldName, string fieldDelimiter) + { + //先Pascal + string result = ConvertToPascal(fieldName, fieldDelimiter); + //然后首字母小写 + if (result.Length == 1) + { + result = result.ToLower(); + } + else + { + result = result.Substring(0, 1).ToLower() + result[1..]; + } + + return result; + } } } diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/README.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/README.txt deleted file mode 100644 index e69de29..0000000 diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/TreeVue.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/TreeVue.txt index c41d79a..f4f65da 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/TreeVue.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/TreeVue.txt @@ -34,7 +34,7 @@ $if(column.HtmlType == "datetime") $elseif(column.HtmlType == "select" || column.HtmlType == "radio") - + $else @@ -119,9 +119,9 @@ $elseif(column.HtmlType == "checkbox" || column.HtmlType == "select" || column.H @@ -227,7 +227,7 @@ $elseif(column.HtmlType == "radio") - {{item.dictLabel}} + {{item.dictLabel}} @@ -247,7 +247,7 @@ $elseif(column.HtmlType == "select") - + @@ -255,7 +255,7 @@ $elseif(column.HtmlType == "checkbox") - {{item.dictLabel}} + {{item.dictLabel}} @@ -349,7 +349,7 @@ const formRef = ref() $foreach(item in genTable.Columns) $if((item.HtmlType == "radio" || item.HtmlType == "select" || item.HtmlType == "checkbox")) // ${item.ColumnComment}选项列表 格式 eg:{ dictLabel: '标签', dictValue: '0'} -const ${item.DictType} = ref([]) +const $if(item.DictType != "") ${item.DictType} $else ${item.CsharpFieldFl}Options$end = ref([]) $elseif(item.HtmlType == "datetime" && item.IsQuery == true) // ${item.ColumnComment}时间范围 const dateRange${item.CsharpField} = ref([]) diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt index 0e52646..4a3727c 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt @@ -34,7 +34,7 @@ $if(column.HtmlType == "datetime") $elseif(column.HtmlType == "select" || column.HtmlType == "radio") - + $else @@ -112,9 +112,9 @@ $elseif(column.HtmlType == "checkbox" || column.HtmlType == "select" || column.H @@ -203,7 +203,7 @@ $elseif(column.HtmlType == "radio") - {{item.dictLabel}} + {{item.dictLabel}} @@ -223,7 +223,7 @@ $elseif(column.HtmlType == "select") - + @@ -231,7 +231,7 @@ $elseif(column.HtmlType == "checkbox") - {{item.dictLabel}} + {{item.dictLabel}} @@ -295,12 +295,10 @@ const open = ref(false) const state = reactive({ form: {}, rules: { - $foreach(column in genTable.Columns) +$foreach(column in genTable.Columns) $if(column.IsRequired && column.IsIncrement == false) - ${column.CsharpFieldFl}: [ - { required: true, message: "${column.ColumnComment}不能为空", trigger: $if(column.htmlType == "select")"change"$else"blur"$end -$if(column.CsharpType == "int" || column.CsharpType == "long"), type: "number"$end } - ], + ${column.CsharpFieldFl}: [{ required: true, message: "${column.ColumnComment}不能为空", trigger: $if(column.htmlType == "select")"change"$else"blur"$end +$if(column.CsharpType == "int" || column.CsharpType == "long"), type: "number"$end }], $end $end } @@ -315,7 +313,7 @@ const formRef = ref() $foreach(item in genTable.Columns) $if((item.HtmlType == "radio" || item.HtmlType == "select" || item.HtmlType == "checkbox")) // ${item.ColumnComment}选项列表 格式 eg:{ dictLabel: '标签', dictValue: '0'} -const ${item.DictType} = ref([]) +const $if(item.DictType != "")${item.DictType}$else${item.CsharpFieldFl}Options$end = ref([]) $elseif(item.HtmlType == "datetime" && item.IsQuery == true) // ${item.ColumnComment}时间范围 const dateRange${item.CsharpField} = ref([]) diff --git a/ZR.CodeGenerator/CodeGeneratorTool.cs b/ZR.CodeGenerator/CodeGeneratorTool.cs index 872d789..c58c6d5 100644 --- a/ZR.CodeGenerator/CodeGeneratorTool.cs +++ b/ZR.CodeGenerator/CodeGeneratorTool.cs @@ -452,7 +452,7 @@ namespace ZR.CodeGenerator TableId = genTable.TableId, TableName = genTable.TableName, CsharpType = GetCSharpDatatype(column.DataType), - CsharpField = column.DbColumnName.UnderScoreToCamelCase().FirstUpperCase(), + CsharpField = column.DbColumnName.ConvertToPascal("_"), IsRequired = !column.IsNullable, IsIncrement = column.IsIdentity, Create_by = genTable.Create_by, From 63cc2de9b90b85dfa412cd459bf2a922c720bc64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Thu, 28 Apr 2022 20:21:56 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=83=A8=E9=97=A8?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=AF=E4=BB=A5=E5=A4=9A=E4=B8=AA=E7=88=B6?= =?UTF-8?q?=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Service/System/SysDeptService.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ZR.Service/System/SysDeptService.cs b/ZR.Service/System/SysDeptService.cs index 24a0cf1..5785b29 100644 --- a/ZR.Service/System/SysDeptService.cs +++ b/ZR.Service/System/SysDeptService.cs @@ -71,12 +71,15 @@ namespace ZR.Service.System { SysDept info = DeptRepository.GetFirst(it => it.DeptId == dept.ParentId); //如果父节点不为正常状态,则不允许新增子节点 - if (!UserConstants.DEPT_NORMAL.Equals(info.Status)) + if (info != null && !UserConstants.DEPT_NORMAL.Equals(info?.Status)) { throw new CustomException("部门停用,不允许新增"); } - - dept.Ancestors = info.Ancestors + "," + dept.ParentId; + dept.Ancestors = ""; + if (info != null) + { + dept.Ancestors = info.Ancestors + "," + dept.ParentId; + } return DeptRepository.Add(dept); } From c25cfc119db5d5f1b13f75797ac5147d057242db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Fri, 29 Apr 2022 20:10:22 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9vue3=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90=E6=97=A5=E6=9C=9F=E9=80=89=E6=8B=A9=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wwwroot/CodeGenTemplate/v3/Vue.txt | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt index 4a3727c..b2a1300 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt @@ -9,27 +9,35 @@