|
1 | | -using System; |
2 | | -using System.Collections.Generic; |
3 | | -using System.Linq; |
4 | | -using System.Threading.Tasks; |
5 | | -using Blog.Core.AuthHelper; |
| 1 | +using Blog.Core.AuthHelper; |
6 | 2 | using Blog.Core.AuthHelper.OverWrite; |
7 | 3 | using Blog.Core.Common.Helper; |
8 | 4 | using Blog.Core.Common.HttpContextUser; |
9 | 5 | using Blog.Core.IServices; |
10 | 6 | using Blog.Core.Model; |
11 | 7 | using Blog.Core.Model.Models; |
12 | 8 | using Microsoft.AspNetCore.Authorization; |
13 | | -using Microsoft.AspNetCore.Http; |
14 | 9 | using Microsoft.AspNetCore.Mvc; |
15 | 10 |
|
16 | 11 | namespace Blog.Core.Controllers |
@@ -442,6 +437,82 @@ orderby child.Id |
442 | 437 | return data; |
443 | 438 | } |
444 | 439 |
|
| 440 | + /// <summary> |
| 441 | + /// 获取路由树【PRO】 |
| 442 | + /// </summary> |
| 443 | + /// <param name="uid"></param> |
| 444 | + /// <returns></returns> |
| 445 | + [HttpGet] |
| 446 | + public async Task<MessageModel<List<NavigationBarPro>>> GetNavigationBarPro(int uid) |
| 447 | + { |
| 448 | + var data = new MessageModel<List<NavigationBarPro>>(); |
| 449 | + |
| 450 | + var uidInHttpcontext1 = 0; |
| 451 | + var roleIds = new List<int>(); |
| 452 | + // ids4和jwt切换 |
| 453 | + if (Permissions.IsUseIds4) |
| 454 | + { |
| 455 | + // ids4 |
| 456 | + uidInHttpcontext1 = (from item in _httpContext.HttpContext.User.Claims |
| 457 | + where item.Type == "sub" |
| 458 | + select item.Value).FirstOrDefault().ObjToInt(); |
| 459 | + roleIds = (from item in _httpContext.HttpContext.User.Claims |
| 460 | + where item.Type == "role" |
| 461 | + select item.Value.ObjToInt()).ToList(); |
| 462 | + } |
| 463 | + else |
| 464 | + { |
| 465 | + // jwt |
| 466 | + uidInHttpcontext1 = ((JwtHelper.SerializeJwt(_httpContext.HttpContext.Request.Headers["Authorization"].ObjToString().Replace("Bearer ", "")))?.Uid).ObjToInt(); |
| 467 | + roleIds = (await _userRoleServices.Query(d => d.IsDeleted == false && d.UserId == uid)).Select(d => d.RoleId.ObjToInt()).Distinct().ToList(); |
| 468 | + } |
| 469 | + |
| 470 | + if (uid > 0 && uid == uidInHttpcontext1) |
| 471 | + { |
| 472 | + if (roleIds.Any()) |
| 473 | + { |
| 474 | + var pids = (await _roleModulePermissionServices.Query(d => d.IsDeleted == false && roleIds.Contains(d.RoleId))) |
| 475 | + .Select(d => d.PermissionId.ObjToInt()).Distinct(); |
| 476 | + if (pids.Any()) |
| 477 | + { |
| 478 | + var rolePermissionMoudles = (await _permissionServices.Query(d => pids.Contains(d.Id) && d.IsButton == false)).OrderBy(c => c.OrderSort); |
| 479 | + var permissionTrees = (from item in rolePermissionMoudles |
| 480 | + where item.IsDeleted == false |
| 481 | + orderby item.Id |
| 482 | + select new NavigationBarPro |
| 483 | + { |
| 484 | + id = item.Id, |
| 485 | + name = item.Name, |
| 486 | + parentId = item.Pid, |
| 487 | + order = item.OrderSort, |
| 488 | + path = item.Code == "-" ? item.Name.GetTotalPingYin().FirstOrDefault() : (item.Code == "/" ? "/dashboard/workplace" : item.Code), |
| 489 | + component = item.Pid == 0 ? (item.Code == "/" ? "dashboard/Workplace" : "RouteView") : item.Code?.TrimStart('/'), |
| 490 | + iconCls = item.Icon, |
| 491 | + Func = item.Func, |
| 492 | + IsHide = item.IsHide.ObjToBool(), |
| 493 | + IsButton = item.IsButton.ObjToBool(), |
| 494 | + meta = new NavigationBarMetaPro |
| 495 | + { |
| 496 | + show = true, |
| 497 | + title = item.Name, |
| 498 | + icon = "user"//item.Icon |
| 499 | + } |
| 500 | + }).ToList(); |
| 501 | + |
| 502 | + permissionTrees = permissionTrees.OrderBy(d => d.order).ToList(); |
| 503 | + |
| 504 | + data.success = true; |
| 505 | + if (data.success) |
| 506 | + { |
| 507 | + data.response = permissionTrees; |
| 508 | + data.msg = "获取成功"; |
| 509 | + } |
| 510 | + } |
| 511 | + } |
| 512 | + } |
| 513 | + return data; |
| 514 | + } |
| 515 | + |
445 | 516 | /// <summary> |
446 | 517 | /// 通过角色获取菜单【无权限】 |
447 | 518 | /// </summary> |
|
0 commit comments