public RoleCache() { var _items = _piAccess.All(); _pages = _items.Where(p => p.ItemType <= PageItemType.Page && !p.IsHide).ToList(); _actions = new Dictionary <int, List <PageItemData> >(); foreach (var page in _items.Where(p => p.ItemType >= PageItemType.Button).GroupBy(p => p.ParentId)) { _actions.Add(page.Key, page.ToList()); } }
private static List <EasyUiTreeNode> LoadTree(PageItemDataAccess access, int parent, List <RolePowerData> powers) { var data = access.All(p => p.ParentId == parent); return(data.Select(item => new EasyUiTreeNode { ID = item.ID, Text = item.Name, Title = item.Caption, Memo = item.Memo, IsOpen = true, IsSelect = powers.Any(p => p.PageItemId == item.ID), Children = LoadTree(access, item.ID, powers) }).ToList()); }
/// <summary> /// 生成角色菜单 /// </summary> static List <EasyUiTreeNode> CreateMenu(RedisProxy proxy) { var root = new EasyUiTreeNode { ID = 0, IsOpen = true, Text = ConfigurationManager.AppSettings["ProjectName"], IsFolder = true }; var access = new PageItemDataAccess(); var pages = access.All(p => p.ItemType <= PageItemType.Page); foreach (var folder in pages.Where(p => p.ItemType == PageItemType.Root).OrderBy(p => p.Index)) { var node = new EasyUiTreeNode { IsOpen = true, Text = folder.Caption, Icon = "icon-item", Attributes = "home.aspx", Tag = folder.ExtendValue, IsFolder = true }; foreach (var page in pages.Where(p => p.ParentId == folder.Id && p.ItemType <= PageItemType.Page).OrderBy(p => p.Index)) { CreateRoleMenu(node, pages, page); } if (node.HaseChildren) { root.Children.Add(node); } } var result = root.Children.OrderByDescending(p => p.ID).ToList( ); proxy.Set(DataKeyBuilder.ToKey("auth", "menu", 0), result); return(result); }