Skip to content

Commit 93361ce

Browse files
committed
fix: GetNavigationBarPro
1 parent 18f012c commit 93361ce

File tree

8 files changed

+274
-9
lines changed

8 files changed

+274
-9
lines changed

Blog.Core.Api/Blog.Core.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Blog.Core.Api/Controllers/PermissionController.cs

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
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;
62
using Blog.Core.AuthHelper.OverWrite;
73
using Blog.Core.Common.Helper;
84
using Blog.Core.Common.HttpContextUser;
95
using Blog.Core.IServices;
106
using Blog.Core.Model;
117
using Blog.Core.Model.Models;
128
using Microsoft.AspNetCore.Authorization;
13-
using Microsoft.AspNetCore.Http;
149
using Microsoft.AspNetCore.Mvc;
1510

1611
namespace Blog.Core.Controllers
@@ -442,6 +437,82 @@ orderby child.Id
442437
return data;
443438
}
444439

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+
445516
/// <summary>
446517
/// 通过角色获取菜单【无权限】
447518
/// </summary>

Blog.Core.Api/wwwroot/BlogCore.Data.json/Modules.tsv

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,5 +1491,27 @@
14911491
"ModifyTime": "2022-03-23 00:00:00",
14921492
"ParentId": 0,
14931493
"Id": 70
1494+
},
1495+
{
1496+
"IsDeleted": 0,
1497+
"ParentId": null,
1498+
"Name": "Get导航条Pro",
1499+
"LinkUrl": "\/api\/permission\/GetNavigationBarPro",
1500+
"Area": null,
1501+
"Controller": null,
1502+
"Action": null,
1503+
"Icon": null,
1504+
"Code": null,
1505+
"OrderSort": 0,
1506+
"Description": null,
1507+
"IsMenu": 0,
1508+
"Enabled": 1,
1509+
"CreateId": 23,
1510+
"CreateBy": "后台总管理员",
1511+
"CreateTime": "\/Date(1546272000000+0800)\/",
1512+
"ModifyId": null,
1513+
"ModifyBy": null,
1514+
"ModifyTime": "\/Date(1546272000000+0800)\/",
1515+
"Id": 71
14941516
}
14951517
]

Blog.Core.Api/wwwroot/BlogCore.Data.json/Permission.tsv

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@
140140
"IsHide": 0
141141
},
142142
{
143-
"Code": "\/Thanks",
144-
"Name": "致谢页",
143+
"Code": "\/System\/BasicSetting",
144+
"Name": "个人设置",
145145
"IsButton": 0,
146-
"Pid": 0,
146+
"Pid": 68,
147147
"Mid": 0,
148148
"OrderSort": 5,
149149
"Icon": "fa-star ",
@@ -2530,5 +2530,25 @@
25302530
"Pid": 115,
25312531
"Mid": 70,
25322532
"Id": 120
2533+
},
2534+
{
2535+
"Code": " ",
2536+
"Name": "左侧导航Pro",
2537+
"IsButton": 1,
2538+
"Pid": 7,
2539+
"Mid": 71,
2540+
"OrderSort": 0,
2541+
"Icon": null,
2542+
"Description": null,
2543+
"Enabled": 1,
2544+
"CreateId": 23,
2545+
"CreateBy": "后台总管理员",
2546+
"CreateTime": "\/Date(1546272000000+0800)\/",
2547+
"ModifyId": null,
2548+
"ModifyBy": null,
2549+
"ModifyTime": "\/Date(1546272000000+0800)\/",
2550+
"IsDeleted": 0,
2551+
"Id": 121,
2552+
"IsHide": 1
25332553
}
25342554
]

Blog.Core.Api/wwwroot/BlogCore.Data.json/RoleModulePermission.tsv

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,5 +1635,18 @@
16351635
"ModuleId": 70,
16361636
"PermissionId": 120,
16371637
"Id": 127
1638+
},
1639+
{
1640+
"IsDeleted": 0,
1641+
"RoleId": 4,
1642+
"ModuleId": 71,
1643+
"PermissionId": 121,
1644+
"CreateId": null,
1645+
"CreateBy": null,
1646+
"CreateTime": "\/Date(1546272000000+0800)\/",
1647+
"ModifyId": null,
1648+
"ModifyBy": null,
1649+
"ModifyTime": "\/Date(1546272000000+0800)\/",
1650+
"Id": 128
16381651
}
16391652
]

Blog.Core.Common/Blog.Core.Common.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
1616
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="5.0.0" />
1717
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
18+
<PackageReference Include="PinYinConverterCore" Version="1.0.2" />
1819
<PackageReference Include="RestSharp" Version="106.11.8-alpha.0.13" />
1920
<PackageReference Include="RSAExtensions" Version="1.0.3" />
2021
<PackageReference Include="Serilog.Sinks.Elasticsearch" Version="8.4.1" />
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
using Microsoft.International.Converters.PinYinConverter;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text.RegularExpressions;
5+
6+
namespace Blog.Core.Common.Helper
7+
{
8+
/// <summary>
9+
/// 汉字转换拼音
10+
/// </summary>
11+
public static class PingYinUtil
12+
{
13+
private static Dictionary<int, List<string>> GetTotalPingYinDictionary(string text)
14+
{
15+
var chs = text.ToCharArray();
16+
17+
//记录每个汉字的全拼
18+
Dictionary<int, List<string>> totalPingYinList = new Dictionary<int, List<string>>();
19+
20+
for (int i = 0; i < chs.Length; i++)
21+
{
22+
var pinyinList = new List<string>();
23+
24+
//是否是有效的汉字
25+
if (ChineseChar.IsValidChar(chs[i]))
26+
{
27+
ChineseChar cc = new ChineseChar(chs[i]);
28+
pinyinList = cc.Pinyins.Where(p => !string.IsNullOrWhiteSpace(p)).ToList();
29+
}
30+
else
31+
{
32+
pinyinList.Add(chs[i].ToString());
33+
}
34+
35+
//去除声调,转小写
36+
pinyinList = pinyinList.ConvertAll(p => Regex.Replace(p, @"\d", "").ToLower());
37+
38+
//去重
39+
pinyinList = pinyinList.Where(p => !string.IsNullOrWhiteSpace(p)).Distinct().ToList();
40+
if (pinyinList.Any())
41+
{
42+
totalPingYinList[i] = pinyinList;
43+
}
44+
}
45+
46+
return totalPingYinList;
47+
}
48+
/// <summary>
49+
/// 获取汉语拼音全拼
50+
/// </summary>
51+
/// <param name="text">The string.</param>
52+
/// <returns></returns>
53+
public static List<string> GetTotalPingYin(this string text)
54+
{
55+
var result = new List<string>();
56+
foreach (var pys in GetTotalPingYinDictionary(text))
57+
{
58+
var items = pys.Value;
59+
if (result.Count <= 0)
60+
{
61+
result = items;
62+
}
63+
else
64+
{
65+
//全拼循环匹配
66+
var newTotalPingYinList = new List<string>();
67+
foreach (var totalPingYin in result)
68+
{
69+
newTotalPingYinList.AddRange(items.Select(item => totalPingYin + item));
70+
}
71+
newTotalPingYinList = newTotalPingYinList.Distinct().ToList();
72+
result = newTotalPingYinList;
73+
}
74+
}
75+
return result;
76+
}
77+
78+
/// <summary>
79+
/// 获取汉语拼音首字母
80+
/// </summary>
81+
/// <param name="text"></param>
82+
/// <returns></returns>
83+
public static List<string> GetFirstPingYin(this string text)
84+
{
85+
var result = new List<string>();
86+
foreach (var pys in GetTotalPingYinDictionary(text))
87+
{
88+
var items = pys.Value;
89+
if (result.Count <= 0)
90+
{
91+
result = items.ConvertAll(p => p.Substring(0, 1)).Distinct().ToList();
92+
}
93+
else
94+
{
95+
//首字母循环匹配
96+
var newFirstPingYinList = new List<string>();
97+
foreach (var firstPingYin in result)
98+
{
99+
newFirstPingYinList.AddRange(items.Select(item => firstPingYin + item.Substring(0, 1)));
100+
}
101+
newFirstPingYinList = newFirstPingYinList.Distinct().ToList();
102+
result = newFirstPingYinList;
103+
}
104+
}
105+
return result;
106+
}
107+
}
108+
}

Blog.Core.Common/Helper/RecursionHelper.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,27 @@ public class NavigationBarMeta
161161

162162

163163
}
164+
165+
166+
public class NavigationBarPro
167+
{
168+
public int id { get; set; }
169+
public int parentId { get; set; }
170+
public int order { get; set; }
171+
public string name { get; set; }
172+
public bool IsHide { get; set; } = false;
173+
public bool IsButton { get; set; } = false;
174+
public string path { get; set; }
175+
public string component { get; set; }
176+
public string Func { get; set; }
177+
public string iconCls { get; set; }
178+
public NavigationBarMetaPro meta { get; set; }
179+
}
180+
181+
public class NavigationBarMetaPro
182+
{
183+
public string title { get; set; }
184+
public string icon { get; set; }
185+
public bool show { get; set; } = false;
186+
}
164187
}

0 commit comments

Comments
 (0)