Beispiel #1
0
        /// <summary>
        /// 菜单递归
        /// </summary>
        /// <param name="menuTree"></param>
        /// <param name="list"></param>
        /// <param name="pid"></param>
        /// <param name="btnList"></param>
        public static void RoleMenuTree(ReturnRoleMenuTree menuTree, List <Sys_AdminMenu> list, int pid, List <Sys_AdminMenuBtn> btnList)
        {
            var childenList = list.Where(p => p.Pid == pid).ToList();

            for (int i = 0; i < childenList.Count; i++)
            {
                var child       = childenList[i];
                var chilBtnList = btnList.Where(p => p.MenuId == child.Id).ToList();

                ReturnRoleMenuTree mTree = new ReturnRoleMenuTree();
                mTree.Id       = child.Id;
                mTree.MenuName = child.MenuName;
                mTree.Type     = "url";
                mTree.TypeId   = "url_" + child.Id;
                mTree.Children = new List <ReturnRoleMenuTree>();
                foreach (var btn in chilBtnList)
                {
                    ReturnRoleMenuTree btnTree = new ReturnRoleMenuTree();
                    btnTree.Id       = btn.Id;
                    btnTree.MenuName = btn.Name;
                    btnTree.Type     = "btn";
                    btnTree.TypeId   = "btn_" + btn.Id;
                    btnTree.Children = new List <ReturnRoleMenuTree>();
                    mTree.Children.Add(btnTree);
                }
                RoleMenuTree(mTree, list, child.Id, btnList);
                menuTree.Children.Add(mTree);
            }
        }
Beispiel #2
0
        public IActionResult GetMenuListFromRole()
        {
            string code       = "000000";
            var    list       = _sysAdminMenuService.GetList(p => true, p => p.Pid);
            var    btnList    = _sysAdminMenuBtnService.GetList(p => p.IsForbidden == 0, p => p.MenuId);
            var    returnList = new List <ReturnRoleMenuTree>();

            if (list.Count == 0)
            {
                code = "000001";
            }
            else
            {
                var lel1List = list.Where(p => p.Level == 1).ToList();
                var menu     = new ReturnRoleMenuTree();
                foreach (var item1 in lel1List)
                {
                    var returnMenuTree = new ReturnRoleMenuTree("url_" + item1.Id, item1.Id, item1.MenuName, "url", new List <ReturnRoleMenuTree>());
                    Common.Util.RoleMenuTree(returnMenuTree, list, item1.Id, btnList);
                    returnList.Add(returnMenuTree);
                }
            }
            return(ReturnJson(code, returnList));
        }