using System.ComponentModel.DataAnnotations; using Dlhis.Entity.Sys.Enums; namespace Dlhis.Sys.Menu.Request; public class SaveMenuRequest : IValidatableObject { public int? Id { get; set; } /// /// code /// public string Code { get; set; } /// /// 上级 /// public string PCode { get; set; } /// /// Name /// [Required(ErrorMessage = "Name不能为空")] public string Name { get; set; } /// /// 标题 /// [Required(ErrorMessage = "标题不能为空")] public string Title { get; set; } /// /// 图标 /// public string Icon { get; set; } /// /// 路由地址 /// public string Route { get; set; } /// /// 权限标识 /// public string Permission { get; set; } /// /// 是否可见 /// public bool? Visible { get; set; } /// /// 是否为外链 /// public bool IsLink { get; set; } /// /// 序号 /// public int Sequence { get; set; } /// /// 菜单类型 MenuEnumType /// [EnumDataType(typeof(MenuEnumType))] public MenuEnumType MenuType { get; set; } /// /// 平台 PlatformEnumType /// [EnumDataType(typeof(PlatformEnumType))] public PlatformEnumType Platform { get; set; } /// /// 兼容reset处理 /// public List Items { get; set; } public IEnumerable Validate(ValidationContext validationContext) { if ((MenuType == MenuEnumType.Menu || MenuType == MenuEnumType.Button) && string.IsNullOrEmpty(Permission)) { yield return new ValidationResult("当类型为菜单或者按钮时,权限标识不能为空", new[] { nameof(Permission) }); } if (MenuType == MenuEnumType.Folder && !string.IsNullOrEmpty(PCode)) { yield return new ValidationResult($"{Title} , 目录类型无需传入上级code", new[] { nameof(PCode) }); } //自动生成code if (string.IsNullOrEmpty(Code)) { Code = Guid.NewGuid().ToString(); } if (!Visible.HasValue) { Visible = true; } } }