From cd876e2c2f3e9c94621679f559a2e630ecfdb78a Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Tue, 8 Dec 2020 09:38:09 +0800 Subject: [PATCH] update Former-commit-id: 0c110188b0e91457e1d3e10810d95961fea5fad8 Former-commit-id: 3baf87dbe854113b774250031dcafce25abb515d --- .../Views/Shared/DisplayTemplates/SelectList.cshtml | 4 ++++ .../Views/Shared/EditorTemplates/SelectList.cshtml | 2 +- projects/Infrastructure/Web/BaseStartup.cs | 6 +++--- .../Application/Domain/Entities/Users/AreaType.cs | 2 +- .../Domain/Entities/Users/BuildingType.cs | 4 ++-- .../Application/Domain/Entities/Users/OrganType.cs | 13 ++++++++----- projects/IoT.Shared/IoT.Shared.csproj | 1 + .../Platform/Application/Models/EditAreaModel.cs | 2 ++ .../Application/Models/EditBuildingModel.cs | 2 ++ .../Platform/Application/Models/EditOrganModel.cs | 2 ++ projects/Platform/DbConfig.cs | 9 +++++++++ projects/Platform/Resources/Resource.Zh-CN.resx | 3 +++ projects/Platform/Startup.cs | 4 +++- projects/Platform/Views/Shared/_Layout.cshtml | 1 + projects/Platform/libman.json | 5 +++++ .../expressive.annotations.validate.min.js | 7 +++++++ projects/projects.sln | 10 ++++------ 17 files changed, 58 insertions(+), 19 deletions(-) create mode 100644 projects/Platform/wwwroot/lib/expressive.annotations.validate/expressive.annotations.validate.min.js diff --git a/projects/Infrastructure/Views/Shared/DisplayTemplates/SelectList.cshtml b/projects/Infrastructure/Views/Shared/DisplayTemplates/SelectList.cshtml index 2d853341..40d042ee 100644 --- a/projects/Infrastructure/Views/Shared/DisplayTemplates/SelectList.cshtml +++ b/projects/Infrastructure/Views/Shared/DisplayTemplates/SelectList.cshtml @@ -6,6 +6,10 @@ @ViewData.Get(key.Value) } } +else if(ViewData.ModelMetadata.IsEnum) +{ + @((Model as Enum)?.GetDisplayName()); +} else { @Model diff --git a/projects/Infrastructure/Views/Shared/EditorTemplates/SelectList.cshtml b/projects/Infrastructure/Views/Shared/EditorTemplates/SelectList.cshtml index 0dfa5b6e..658a4172 100644 --- a/projects/Infrastructure/Views/Shared/EditorTemplates/SelectList.cshtml +++ b/projects/Infrastructure/Views/Shared/EditorTemplates/SelectList.cshtml @@ -11,7 +11,7 @@ { var enumType = ViewData.ModelMetadata.ModelType.GetGenericArguments()[0]; var items = enumType.GetEnumValues().Cast() - .Select(o => new SelectListItem { Value = o.ToString(), Text = (Enum.Parse(enumType, o.ToString()) as Enum).GetDisplayName() }) + .Select(o => new SelectListItem { Value = ((int)o).ToString(), Text = (Enum.Parse(enumType, o.ToString()) as Enum).GetDisplayName() }) .ToList(); list = new SelectList(items, "Value", "Text", Model); @Html.DropDownList("", list, "请选择", new { @class = htmlClass }) diff --git a/projects/Infrastructure/Web/BaseStartup.cs b/projects/Infrastructure/Web/BaseStartup.cs index c903aa40..d10b0550 100644 --- a/projects/Infrastructure/Web/BaseStartup.cs +++ b/projects/Infrastructure/Web/BaseStartup.cs @@ -125,8 +125,8 @@ namespace Infrastructure.Web o.DefaultApiVersion = new ApiVersion(1, 0); o.ApiVersionReader = ApiVersionReader.Combine( new UrlSegmentApiVersionReader() - //,new QueryStringApiVersionReader() - //,new HeaderApiVersionReader() + , new QueryStringApiVersionReader() + , new HeaderApiVersionReader() ); }); services.AddControllers() @@ -412,4 +412,4 @@ namespace Infrastructure.Web return Task.CompletedTask; } } -} \ No newline at end of file +} diff --git a/projects/IoT.Shared/Application/Domain/Entities/Users/AreaType.cs b/projects/IoT.Shared/Application/Domain/Entities/Users/AreaType.cs index 0f5a835b..9284d4b2 100644 --- a/projects/IoT.Shared/Application/Domain/Entities/Users/AreaType.cs +++ b/projects/IoT.Shared/Application/Domain/Entities/Users/AreaType.cs @@ -16,7 +16,7 @@ namespace IoT.Shared.Application.Domain.Entities [Display(Name = "乡级")] Township = 40, - [Display(Name = "其他")] + [Display(Name = "自定义")] Other = 1000 } } diff --git a/projects/IoT.Shared/Application/Domain/Entities/Users/BuildingType.cs b/projects/IoT.Shared/Application/Domain/Entities/Users/BuildingType.cs index 08997317..7a61ed6e 100644 --- a/projects/IoT.Shared/Application/Domain/Entities/Users/BuildingType.cs +++ b/projects/IoT.Shared/Application/Domain/Entities/Users/BuildingType.cs @@ -13,7 +13,7 @@ namespace IoT.Shared.Application.Domain.Entities [Display(Name = "房间")] Room = 30, - [Display(Name = "其他")] - Other = 10000 + [Display(Name = "自定义")] + Other = 1000 } } diff --git a/projects/IoT.Shared/Application/Domain/Entities/Users/OrganType.cs b/projects/IoT.Shared/Application/Domain/Entities/Users/OrganType.cs index c5a16db3..4b036d1b 100644 --- a/projects/IoT.Shared/Application/Domain/Entities/Users/OrganType.cs +++ b/projects/IoT.Shared/Application/Domain/Entities/Users/OrganType.cs @@ -5,18 +5,21 @@ namespace IoT.Shared.Application.Domain.Entities public enum OrganType { [Display(Name = "企业")] - Type1 = 1, + Type1 = 10, [Display(Name = "机关")] - Type3 = 3, + Type3 = 30, [Display(Name = "事业单位")] - Type5 = 5, + Type5 = 50, [Display(Name = "社会团体")] - Type7 = 7, + Type7 = 70, [Display(Name = "其他组织机构")] - Type9 = 9 + Type9 = 90, + + [Display(Name = "自定义")] + Other = 1000 } } diff --git a/projects/IoT.Shared/IoT.Shared.csproj b/projects/IoT.Shared/IoT.Shared.csproj index 0dced372..f5cb99b5 100644 --- a/projects/IoT.Shared/IoT.Shared.csproj +++ b/projects/IoT.Shared/IoT.Shared.csproj @@ -13,6 +13,7 @@ + diff --git a/projects/Platform/Application/Models/EditAreaModel.cs b/projects/Platform/Application/Models/EditAreaModel.cs index 19975e1a..a343b235 100644 --- a/projects/Platform/Application/Models/EditAreaModel.cs +++ b/projects/Platform/Application/Models/EditAreaModel.cs @@ -2,6 +2,7 @@ using IoT.Shared.Application.Domain.Entities; using System; using System.ComponentModel.DataAnnotations; +using UoN.ExpressiveAnnotations.NetCore.Attributes; namespace Platform.Application.Models { @@ -23,6 +24,7 @@ namespace Platform.Application.Models public AreaType? Type { get; set; } [Display(Name = "自定义类型")] + [RequiredIf("Type==1000", ErrorMessage = "类型为自定时必须填写此字段")] public string CustomType { get; set; } [Display(Name = "上级")] diff --git a/projects/Platform/Application/Models/EditBuildingModel.cs b/projects/Platform/Application/Models/EditBuildingModel.cs index 85cd3ce2..50488565 100644 --- a/projects/Platform/Application/Models/EditBuildingModel.cs +++ b/projects/Platform/Application/Models/EditBuildingModel.cs @@ -3,6 +3,7 @@ using IoT.Shared.Application.Domain.Entities; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using UoN.ExpressiveAnnotations.NetCore.Attributes; namespace Platform.Application.Models { @@ -28,6 +29,7 @@ namespace Platform.Application.Models public BuildingType? Type { get; set; } [Display(Name = "自定义类型")] + [RequiredIf("Type==1000", ErrorMessage = "类型为自定时必须填写此字段")] public string CustomType { get; set; } [Display(Name = "上级")] diff --git a/projects/Platform/Application/Models/EditOrganModel.cs b/projects/Platform/Application/Models/EditOrganModel.cs index 5b4a935b..f3872299 100644 --- a/projects/Platform/Application/Models/EditOrganModel.cs +++ b/projects/Platform/Application/Models/EditOrganModel.cs @@ -2,6 +2,7 @@ using IoT.Shared.Application.Domain.Entities; using System; using System.ComponentModel.DataAnnotations; +using UoN.ExpressiveAnnotations.NetCore.Attributes; namespace Platform.Application.Models { @@ -35,6 +36,7 @@ namespace Platform.Application.Models public OrganType? Type { get; set; } [Display(Name = "自定义类型")] + [RequiredIf("Type==1000", ErrorMessage = "类型为自定时必须填写此字段")] public string CustomType { get; set; } } } diff --git a/projects/Platform/DbConfig.cs b/projects/Platform/DbConfig.cs index aad44360..2cf328dc 100644 --- a/projects/Platform/DbConfig.cs +++ b/projects/Platform/DbConfig.cs @@ -105,6 +105,7 @@ namespace Platform new Organ { Area = db.Set().FirstOrDefault(o => o.Number == "changchun"), + Type= OrganType.Type5, Name="默认教育局", Number="jiaoyuju", Children = new List @@ -112,8 +113,16 @@ namespace Platform new Organ { Area = db.Set().FirstOrDefault(o => o.Number == "nanguan"), + Type= OrganType.Type5, Name="默认学校", Number="xuexiao" + }, + new Organ + { + Area = db.Set().FirstOrDefault(o => o.Number == "nanguan"), + Type= OrganType.Type1, + Name="其他学校", + Number="qitaxuexiao" } } } diff --git a/projects/Platform/Resources/Resource.Zh-CN.resx b/projects/Platform/Resources/Resource.Zh-CN.resx index 4d54de4b..bbbb607a 100644 --- a/projects/Platform/Resources/Resource.Zh-CN.resx +++ b/projects/Platform/Resources/Resource.Zh-CN.resx @@ -123,4 +123,7 @@ 必须输入{0} + + 必须输入{0} + \ No newline at end of file diff --git a/projects/Platform/Startup.cs b/projects/Platform/Startup.cs index c070d9e4..f30746d5 100644 --- a/projects/Platform/Startup.cs +++ b/projects/Platform/Startup.cs @@ -19,6 +19,7 @@ using Platform.Services; using System; using System.Collections.Generic; using System.Transactions; +using UoN.ExpressiveAnnotations.NetCore.DependencyInjection; namespace Platform { @@ -68,6 +69,7 @@ namespace Platform services.AddHangfire(o => o.UseSQLiteStorage("job.db")); } services.AddReverseProxy().LoadFromConfig(Configuration.GetSection("ReverseProxy")); + services.AddExpressiveAnnotations(); } public override void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) @@ -114,4 +116,4 @@ namespace Platform this.UseSignalR(endpoints); } } -} \ No newline at end of file +} diff --git a/projects/Platform/Views/Shared/_Layout.cshtml b/projects/Platform/Views/Shared/_Layout.cshtml index 1c8f991b..e6b71b7e 100644 --- a/projects/Platform/Views/Shared/_Layout.cshtml +++ b/projects/Platform/Views/Shared/_Layout.cshtml @@ -144,6 +144,7 @@ + diff --git a/projects/Platform/libman.json b/projects/Platform/libman.json index 79a455a7..91050dab 100644 --- a/projects/Platform/libman.json +++ b/projects/Platform/libman.json @@ -81,6 +81,11 @@ "destination": "wwwroot/lib/jquery-ajax-unobtrusive/", "files": [ "jquery.unobtrusive-ajax.min.js" ] }, + { + "library": "expressive-annotations-validate@2.7.0", + "destination": "wwwroot/lib/expressive.annotations.validate/", + "files": [ "expressive.annotations.validate.min.js" ] + }, { "library": "vue@2.6.11", "destination": "wwwroot/lib/vue/", diff --git a/projects/Platform/wwwroot/lib/expressive.annotations.validate/expressive.annotations.validate.min.js b/projects/Platform/wwwroot/lib/expressive.annotations.validate/expressive.annotations.validate.min.js new file mode 100644 index 00000000..94a14dab --- /dev/null +++ b/projects/Platform/wwwroot/lib/expressive.annotations.validate/expressive.annotations.validate.min.js @@ -0,0 +1,7 @@ +/* expressive.annotations.validate.js - v2.7.0 + * Client-side component of ExpressiveAnnotations - annotation-based conditional validation library. + * https://github.com/jwaliszko/ExpressiveAnnotations + * + * Copyright (c) 2014 Jarosław Waliszko + * Licensed MIT: http://opensource.org/licenses/MIT */ +!function(e,t){"use strict";var n=t.ea,r={settings:{debug:!1,optimize:!0,enumsAsNumbers:!0,dependencyTriggers:"change keyup",apply:function(t){function n(){if(!s.isBool(r.settings.debug))throw"debug value must be a boolean (true or false)";if(!s.isBool(r.settings.optimize))throw"optimize value must be a boolean (true or false)";if(!s.isBool(r.settings.enumsAsNumbers))throw"enumsAsNumbers value must be a boolean (true or false)";if(!s.isString(r.settings.dependencyTriggers)&&null!==r.settings.dependencyTriggers&&void 0!==r.settings.dependencyTriggers)throw"dependencyTriggers value must be a string (multiple event types can be bound at once by including each one separated by a space), null or undefined"}function i(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])}i(r.settings,t),n(),e("form").each(function(){e(this).find("input, select, textarea").off(".expressive.annotations"),u.bindFields(this,!0)})}},addMethod:function(e,t){a.addMethod(e,t)},addValueParser:function(e,t){s.addValueParser(e,t)},noConflict:function(){return t.ea===this&&(t.ea=n),this}},i={dump:function(e){r.settings.debug&&console&&"function"==typeof console.log&&console.log(e)},warn:function(e){console&&"function"==typeof console.warn&&console.warn(e)},fail:function(e){console&&"function"==typeof console.error&&console.error(e)}},a={methods:{},addMethod:function(e,t){var n=this.methods[e];this.methods[e]=function(){return t.length===arguments.length?t.apply(this,arguments):"function"==typeof n?n.apply(this,arguments):t.apply(this,arguments)}},registerMethods:function(e){var t,n;this.initialize();for(t in this.methods)this.methods.hasOwnProperty(t)&&(n=this.methods[t],e[t]=n)},initialize:function(){this.addMethod("Now",function(){return Date.now()}),this.addMethod("Today",function(){return new Date((new Date).setHours(0,0,0,0)).getTime()}),this.addMethod("ToDate",function(e){return Date.parse(e)}),this.addMethod("Date",function(e,t,n){return new Date(new Date(e,t-1,n).setFullYear(e)).getTime()}),this.addMethod("Date",function(e,t,n,r,i,a){return new Date(new Date(e,t-1,n,r,i,a).setFullYear(e)).getTime()}),this.addMethod("TimeSpan",function(e,t,n,r){return 1e3*r+6e4*n+36e5*t+864e5*e}),this.addMethod("Length",function(e){return null!==e&&void 0!==e?e.length:0}),this.addMethod("Trim",function(t){return null!==t&&void 0!==t?e.trim(t):null}),this.addMethod("Concat",function(e,t){return[e,t].join("")}),this.addMethod("Concat",function(e,t,n){return[e,t,n].join("")}),this.addMethod("CompareOrdinal",function(e,t){return e===t?0:null!==e&&null===t?1:null===e&&null!==t?-1:e>t?1:-1}),this.addMethod("CompareOrdinalIgnoreCase",function(e,t){return e=null!==e&&void 0!==e?e.toLowerCase():null,t=null!==t&&void 0!==t?t.toLowerCase():null,this.CompareOrdinal(e,t)}),this.addMethod("StartsWith",function(e,t){return null!==e&&void 0!==e&&null!==t&&void 0!==t&&e.slice(0,t.length)===t}),this.addMethod("StartsWithIgnoreCase",function(e,t){return e=null!==e&&void 0!==e?e.toLowerCase():null,t=null!==t&&void 0!==t?t.toLowerCase():null,this.StartsWith(e,t)}),this.addMethod("EndsWith",function(e,t){return null!==e&&void 0!==e&&null!==t&&void 0!==t&&e.slice(-t.length)===t}),this.addMethod("EndsWithIgnoreCase",function(e,t){return e=null!==e&&void 0!==e?e.toLowerCase():null,t=null!==t&&void 0!==t?t.toLowerCase():null,this.EndsWith(e,t)}),this.addMethod("Contains",function(e,t){return null!==e&&void 0!==e&&null!==t&&void 0!==t&&e.indexOf(t)>-1}),this.addMethod("ContainsIgnoreCase",function(e,t){return e=null!==e&&void 0!==e?e.toLowerCase():null,t=null!==t&&void 0!==t?t.toLowerCase():null,this.Contains(e,t)}),this.addMethod("IsNullOrWhiteSpace",function(e){return null===e||!/\S/.test(e)}),this.addMethod("IsDigitChain",function(e){return/^[0-9]+$/.test(e)}),this.addMethod("IsNumber",function(e){return/^[+-]?(?:(?:[0-9]+)|(?:[0-9]+[eE][+-]?[0-9]+)|(?:[0-9]*\.[0-9]+(?:[eE][+-]?[0-9]+)?))$/.test(e)}),this.addMethod("IsEmail",function(e){return/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(e)}),this.addMethod("IsPhone",function(e){return/^(\+\s?)?((?!\+.*)\(\+?\d+([\s\-\.]?\d+)?\)|\d+)([\s\-\.]?(\(\d+([\s\-\.]?\d+)?\)|\d+))*(\s?(x|ext\.?)\s?\d+)?$/.test(e)}),this.addMethod("IsUrl",function(e){return/^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/i.test(e)}),this.addMethod("IsRegexMatch",function(e,t){return null!==e&&void 0!==e&&null!==t&&void 0!==t&&new RegExp(t).test(e)}),this.addMethod("Guid",function(e){var t=s.guid.tryParse(e);if(t.error)throw t.msg;return t}),this.addMethod("Min",function(e){if(0===arguments.length)throw"no arguments";if(1===arguments.length&&s.isArray(e)){if(0===e.length)throw"empty sequence";return Math.min.apply(null,e)}return Math.min.apply(null,arguments)}),this.addMethod("Max",function(e){if(0===arguments.length)throw"no arguments";if(1===arguments.length&&s.isArray(e)){if(0===e.length)throw"empty sequence";return Math.max.apply(null,e)}return Math.max.apply(null,arguments)}),this.addMethod("Sum",function(e){if(0===arguments.length)throw"no arguments";var t,n,r=0;if(1===arguments.length&&s.isArray(e)){if(0===e.length)throw"empty sequence";for(t=0,n=e.length;t2&&i.warn(s.string.format("DOM field {0} is ambiguous (unless custom value parser is provided).",e.attr("name"))),e.is(":checked");case"radio":return e.filter(":checked").val();default:return e.length>1&&i.warn(s.string.format("DOM field {0} is ambiguous (unless custom value parser is provided).",e.attr("name"))),e.val()}}var d,l,f,c;if(l=r+n,d=e(t).find(s.string.format(':input[name="{0}"]',l)),0===d.length)throw s.string.format("DOM field {0} not found.",l);if(f=u(d),null===f||void 0===f||""===f)return null;if(c=s.tryParse(f,a,l,o),null!==c&&void 0!==c&&c.error)throw s.string.format("DOM field {0} value conversion to {1} failed. {2}",l,a,c.msg);return c},deserializeObject:function(e,t,n,i,a,s){function o(e,t,n){var r,i,a,s,o;for(r=e.split("."),i=n,a=0;a