refactor: 移除 Extensions 工程

This commit is contained in:
Argo-Lenovo 2022-01-02 11:24:31 +08:00
parent e4cb1b4a9d
commit 1e0203472e
5 changed files with 64 additions and 15 deletions

View File

@ -1,11 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="BootstrapBlazor" Version="6.1.2-beta06" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BootstrapAdmin.DataAccess.Models\BootstrapAdmin.DataAccess.Models.csproj" />
</ItemGroup>
</Project>

View File

@ -1,8 +1,7 @@
using BootstrapAdmin.DataAccess.Models;
using BootstrapBlazor.Components;
using Microsoft.AspNetCore.Components.Routing;
namespace BootstrapAdmin.Extensions
namespace BootstrapAdmin.Web.Extensions
{
/// <summary>
///

View File

@ -1,6 +1,6 @@
using Bootstrap.Security.Blazor;
using BootstrapAdmin.Extensions;
using BootstrapAdmin.Web.Core;
using BootstrapAdmin.Web.Extensions;
using BootstrapAdmin.Web.Services;
using Microsoft.AspNetCore.Components.Authorization;

View File

@ -0,0 +1,61 @@
using BootstrapAdmin.DataAccess.Models;
using BootstrapBlazor.Components;
using Microsoft.AspNetCore.Components.Routing;
namespace BootstrapClient.Web.Shared.Extensions;
/// <summary>
///
/// </summary>
public static class MenuExtensions
{
/// <summary>
///
/// </summary>
/// <param name="menu"></param>
/// <returns></returns>
public static MenuItem Parse(this Navigation menu) => new()
{
Text = menu.Name,
Url = menu.Url.Replace("~", ""),
Icon = menu.Icon,
Match = NavLinkMatch.All,
Target = menu.Target,
Id = menu.Id,
ParentId = menu.ParentId
};
/// <summary>
/// 获取前台菜单
/// </summary>
/// <returns></returns>
public static IEnumerable<MenuItem> ToClientMenus(this List<Navigation> navigations)
{
var menus = navigations.Where(m => m.Category == EnumNavigationCategory.Customer && m.IsResource == 0);
return CascadeMenus(menus);
}
/// <summary>
/// 获得带层次关系的菜单集合
/// </summary>
/// <param name="navigations">未层次化菜单集合</param>
/// <returns>带层次化的菜单集合</returns>
public static IEnumerable<MenuItem> CascadeMenus(IEnumerable<Navigation> navigations)
{
var root = navigations.Where(m => m.ParentId == "0")
.OrderBy(m => m.Category).ThenBy(m => m.Application).ThenBy(m => m.Order)
.Select(m => m.Parse())
.ToList();
CascadeMenus(navigations, root);
return root;
}
private static void CascadeMenus(IEnumerable<Navigation> navigations, List<MenuItem> level)
{
level.ForEach(m =>
{
m.Items = navigations.Where(sub => sub.ParentId == m.Id).OrderBy(sub => sub.Order).Select(sub => sub.Parse()).ToList();
CascadeMenus(navigations, m.Items.ToList());
});
}
}

View File

@ -1,7 +1,7 @@
using Bootstrap.Security.Blazor;
using BootstrapAdmin.Extensions;
using BootstrapAdmin.Web.Core;
using BootstrapBlazor.Components;
using BootstrapClient.Web.Shared.Extensions;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;