public string GetMenuTree(int roleId = 0) { var menus = appmenuService.GetList(new AppMenuListQuery() { Status = true }); var roleAuths = app_role_authService.GetRoleAuthList(new DomainModel.RoleAuthListQuery { roleId = roleId }); var menuTree = MapperHelper.Map<List<MenuTreeShow>>(menus); var list = new List<MenuTreeShow>(); var rootMenu = new MenuTreeShow { Name = "根節點", Childs = menuTree }; //用戶沒有權限的菜單集合 var notSelectIds = menus.Select(s => s.Id).Except(roleAuths.Select(s => s.Id)).Select(s => s.ToString()).ToList(); rootMenu.NotSelecteNodes = notSelectIds; list.Insert(0, rootMenu); return JsonHelper.Success(list); }
/// <summary> /// </summary> /// <param name="memberId">用戶Id</param> /// <param name="positionId">職位Id,切換職位時,也要修改樹中節點</param> /// <returns></returns> public string GetMenuTree(int memberId = 0, int positionId = 0) { var menus = appmenuService.GetList(new AppMenuListQuery() { Status = true }); var ownMenus = service.GetOwnMenus(memberId, positionId); var menuTree = MapperHelper.Map<List<MenuTreeShow>>(menus); var list = new List<MenuTreeShow>(); var rootMenu = new MenuTreeShow { Name = "根節點", Childs = menuTree }; //用戶沒有權限的菜單集合 var notSelectIds = menus.Select(s => s.Id.ToString()).Except(ownMenus).ToList(); rootMenu.NotSelecteNodes = notSelectIds; list.Insert(0, rootMenu); return JsonHelper.Success(list); }
public string GetMenuTree(int roleId = 0) { //這邊返回的菜單不包括禁用的,因為給權限給禁用的菜單好像也沒什麼用 var menus = sys_MenuService.GetMenusWithChild(new GetMenuTreeList { IsShowAll = true, IsShowOne = false }) .Where(s => s.Status); var roleAuths = sys_Role_AuthService.GetRoleAuthList(new DomainModel.RoleAuthListQuery { roleId = roleId }); var fistLevelMenus = menus.Where(s => s.ParentId == 0).ToList(); var menuTree = MapperHelper.Map<List<MenuTreeShow>>(fistLevelMenus); var list = new List<MenuTreeShow>(); var rootMenu = new MenuTreeShow { Name = "根節點", Childs = menuTree }; //用戶沒有權限的菜單集合 var notSelectIds = menus.Select(s => s.Id).Except(roleAuths.Select(s => s.Id)).Select(s => s.ToString()).ToList(); rootMenu.NotSelecteNodes = notSelectIds; list.Insert(0, rootMenu); return JsonHelper.Success(list); }
/// <summary> /// (在新增和修改職位時) /// 獲取針對當前所有菜單的樹形結構 /// </summary> /// <param name="positionId"></param> /// <returns></returns> public string GetMenuTree(int positionId = 0) { var menus = appmenuService.GetList(new AppMenuListQuery() { Status = true }); var postion = service.GetModel(positionId); var ownMenus = new List<string>(0); if (postion != null) { ownMenus = postion.Menus.ConvertToList(); //已經擁有全新的菜單 } var menuTree = MapperHelper.Map<List<MenuTreeShow>>(menus); var list = new List<MenuTreeShow>(); var rootMenu = new MenuTreeShow { Name = "根節點", Childs = menuTree }; //用戶沒有權限的菜單集合 var notSelectIds = menus.Select(s => s.Id.ToString()).Except(ownMenus).ToList(); rootMenu.NotSelecteNodes = notSelectIds; list.Insert(0, rootMenu); return JsonHelper.Success(list); }