public async Task <IActionResult> RoleMenuTreeData(int RoleID) { string msg = string.Empty; bool status = false; string sWhere = string.Empty; IEnumerable <ETree> listMenus = null; IEnumerable <ESysMenu> rootMenus = null; List <int> listRoleMenuIDs = new List <int>(); try { if (RoleID > 0) { var param = new Dapper.DynamicParameters(); //查询该角色Menus sWhere += " and RoleID=@RoleID"; param.Add("RoleID", RoleID); var listRoleMenuData = await _SysRoleMenuRepository.GetMenuByRoleAsync(sWhere, param); rootMenus = await _SysMenuRepository.GetMenuByParentIDAsync(0); foreach (var p in listRoleMenuData) { bool flag = true; foreach (var pp in rootMenus) { if (p.MenuID == pp.MenuID) { flag = false; break; } } if (flag) { listRoleMenuIDs.Add(p.MenuID); } } //获取该权限的MenuIDs 排除RootMenuID listMenus = await BuilderTreeAsync(listRoleMenuIDs); status = true; } } catch (Exception ex) { msg = ex.Message; } return(Ok(new { status = status, msg = msg, listRoleMenuIDs = listRoleMenuIDs, listMenuData = listMenus })); }