feat: 多层菜单支持
This commit is contained in:
parent
d9a80affcf
commit
d31b056292
|
@ -1,4 +1,6 @@
|
|||
using Bootstrap.Client.DataAccess;
|
||||
using Bootstrap.Security;
|
||||
using Bootstrap.Security.Mvc;
|
||||
using BootstrapBlazor.Components;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
|
@ -87,17 +89,35 @@ namespace Bootstrap.Client.Blazor.Shared.Shared
|
|||
|
||||
if (OperatingSystem.IsBrowser())
|
||||
{
|
||||
|
||||
// 需要调用 webapi 获取菜单数据 暂未实现
|
||||
}
|
||||
else
|
||||
{
|
||||
menus = MenuHelper.RetrieveAppMenus(UserName, "").Select(m => new MenuItem()
|
||||
var appId = BootstrapAppContext.AppId;
|
||||
var data = MenuHelper.RetrieveAppMenus(UserName, "");
|
||||
menus = CascadeMenu(data);
|
||||
}
|
||||
return menus;
|
||||
}
|
||||
|
||||
private List<MenuItem> CascadeMenu(IEnumerable<BootstrapMenu> datasource)
|
||||
{
|
||||
var menus = new List<MenuItem>();
|
||||
foreach (var m in datasource)
|
||||
{
|
||||
var item = new MenuItem()
|
||||
{
|
||||
Text = m.Name,
|
||||
Url = m.Url.TrimStart('~'),
|
||||
Target = m.Target,
|
||||
Icon = m.Icon
|
||||
}).ToList();
|
||||
};
|
||||
menus.Add(item);
|
||||
|
||||
if (m.Menus.Any())
|
||||
{
|
||||
item.Items = CascadeMenu(m.Menus);
|
||||
}
|
||||
}
|
||||
return menus;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace Bootstrap.Client.DataAccess
|
|||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<BootstrapMenu> RetrieveAllMenus(string userName) => CacheManager.GetOrAdd($"{RetrieveMenusAll}-{userName}", key => DbContextManager.Create<Menu>()?.RetrieveAllMenus(userName), RetrieveMenusAll) ?? new BootstrapMenu[0];
|
||||
public static IEnumerable<BootstrapMenu> RetrieveAllMenus(string userName) => CacheManager.GetOrAdd($"{RetrieveMenusAll}-{userName}", key => DbContextManager.Create<Menu>()?.RetrieveAllMenus(userName), RetrieveMenusAll) ?? System.Array.Empty<BootstrapMenu>();
|
||||
|
||||
/// <summary>
|
||||
/// 通过当前用户名与指定菜单路径获取此菜单下所有授权按钮集合 (userName, url, auths) => bool
|
||||
|
|
Loading…
Reference in New Issue