public async Task <MessageModel <NavigationBar> > GetNavigationBar(int uid) { var data = new MessageModel <NavigationBar>(); var uidInHttpcontext1 = 0; var roleIds = new List <int>(); // ids4和jwt切换 if (Permissions.IsUseIds4) { // ids4 uidInHttpcontext1 = (from item in _httpContext.HttpContext.User.Claims where item.Type == "sub" select item.Value).FirstOrDefault().ObjToInt(); roleIds = (from item in _httpContext.HttpContext.User.Claims where item.Type == "role" select item.Value.ObjToInt()).ToList(); } else { // jwt uidInHttpcontext1 = ((JwtHelper.SerializeJwt(_httpContext.HttpContext.Request.Headers["Authorization"].ObjToString().Replace("Bearer ", "")))?.Uid).ObjToInt(); roleIds = (await _userRoleServices.Query(d => d.IsDeleted == false && d.UserId == uid)).Select(d => d.RoleId.ObjToInt()).Distinct().ToList(); } if (uid > 0 && uid == uidInHttpcontext1) { if (roleIds.Any()) { var pids = (await _roleModulePermissionServices.Query(d => d.IsDeleted == false && roleIds.Contains(d.RoleId))).Select(d => d.PermissionId.ObjToInt()).Distinct(); if (pids.Any()) { var rolePermissionMoudles = (await _permissionServices.Query(d => pids.Contains(d.Id))).OrderBy(c => c.OrderSort); var permissionTrees = (from child in rolePermissionMoudles where child.IsDeleted == false orderby child.Id select new NavigationBar { id = child.Id, name = child.Name, pid = child.Pid, order = child.OrderSort, path = child.Code, iconCls = child.Icon, Func = child.Func, IsHide = child.IsHide.ObjToBool(), IsButton = child.IsButton.ObjToBool(), meta = new NavigationBarMeta { requireAuth = true, title = child.Name, NoTabPage = child.IsHide.ObjToBool(), keepAlive = child.IskeepAlive.ObjToBool() } }).ToList(); NavigationBar rootRoot = new NavigationBar() { id = 0, pid = 0, order = 0, name = "根节点", path = "", iconCls = "", meta = new NavigationBarMeta(), }; permissionTrees = permissionTrees.OrderBy(d => d.order).ToList(); RecursionHelper.LoopNaviBarAppendChildren(permissionTrees, rootRoot); data.success = true; if (data.success) { data.response = rootRoot; data.msg = "获取成功"; } } } } return(data); }
public async Task <MessageModel <NavigationBar> > GetNavigationBar(int uid) { var data = new MessageModel <NavigationBar>(); // 两种方式获取 uid var uidInHttpcontext1 = (from item in _httpContext.HttpContext.User.Claims where item.Type == "jti" select item.Value).FirstOrDefault().ObjToInt(); var uidInHttpcontext = (JwtToken.SerializeJwt(_httpContext.HttpContext.Request.Headers["Authorization"].ObjToString().Replace("Bearer ", "")))?.Uid; if (uid > 0 && uid == uidInHttpcontext) { var roleId = ((await _userRoleRepository.Query(d => d.IsDeleted == false && d.UserId == uid)).FirstOrDefault()?.RoleId).ObjToInt(); var roletype = _iUser.GetClaimValueByType(ClaimTypes.Role); if (roletype.Contains("Teacher_Role")) { roleId = ((await _iRoleRepository.Query(d => d.IsDeleted == false && d.Name == "Teacher_Role")).FirstOrDefault()?.Id).ObjToInt(); } if (roleId > 0) { var pids = (await _roleModulePermissionRepository.Query(d => d.IsDeleted == false && d.RoleId == roleId)).Select(d => d.PermissionId.ObjToInt()).Distinct(); if (pids.Any()) { var rolePermissionMoudles = (await _permissionRepository.Query(d => pids.Contains(d.Id) && d.IsButton == false)).OrderBy(c => c.OrderSort); var permissionTrees = (from child in rolePermissionMoudles where child.IsDeleted == false orderby child.Id select new NavigationBar { id = child.Id, name = child.Name, pid = child.Pid, order = child.OrderSort, path = child.Code, iconCls = child.Icon, IsHide = child.IsHide.ObjToBool(), meta = new NavigationBarMeta { requireAuth = child.IsAuth.ObjToBool(), title = child.Name, NoTabPage = child.IsHide.ObjToBool() } }).ToList(); NavigationBar rootRoot = new NavigationBar() { id = 0, pid = 0, order = 0, name = "根节点", path = "", iconCls = "", meta = new NavigationBarMeta(), }; permissionTrees = permissionTrees.OrderBy(d => d.order).ToList(); RecursionHelper.LoopNaviBarAppendChildren(permissionTrees, rootRoot); data.success = true; if (data.success) { data.response = rootRoot; data.msg = "获取成功"; } } else { data.msg = "没有找到任何权限"; } } } return(data); }