using System; using System.Collections.Generic; using System.Linq; using SqlSugar; using Yi.Framework.Common.Enum; using Yi.Framework.Common.Models; namespace Yi.Framework.Model.Models { /// /// 菜单表 /// public partial class MenuEntity { [SqlSugar.SugarColumn(IsIgnore = true)] public List Children { get; set; } public static List RouterBuild(List menus) { menus = menus.Where(m => m.MenuType != null && m.MenuType != MenuTypeEnum.Component.GetHashCode()).ToList(); List routers = new(); foreach (var m in menus) { var r = new VueRouterModel(); var routerName = m.Router.Split("/").LastOrDefault(); r.Id = m.Id; r.ParentId = (long)m.ParentId; //开头大写 r.Name = routerName.First().ToString().ToUpper() + routerName.Substring(1); r.Path = m.Router; r.Hidden = (bool)!m.IsShow; if (m.MenuType == MenuTypeEnum.Catalogue.GetHashCode()) { r.Redirect = "noRedirect"; r.AlwaysShow = true; //判断是否为最顶层的路由 if (0==m.ParentId) { r.Component = "Layout"; } else { r.Component = "ParentView"; } } if (m.MenuType == MenuTypeEnum.Menu.GetHashCode()) { r.Redirect = "noRedirect"; r.AlwaysShow = true; r.Component = m.Component; r.AlwaysShow = false; } r.Meta = new Meta { Title = m.MenuName, Icon = m.MenuIcon, NoCache = (bool)!m.IsCache }; if ((bool)m.IsLink) { r.Meta.link = m.Router; r.AlwaysShow = false; } routers.Add(r); } return Common.Helper.TreeHelper.SetTree(routers); } } }