feat: 菜单表更改成枚举类型

This commit is contained in:
Argo-Tianyi 2021-12-12 20:07:04 +08:00
parent 513dce940f
commit b0651c755e
7 changed files with 65 additions and 7 deletions

View File

@ -0,0 +1,22 @@
using System.ComponentModel;
namespace BootstrapAdmin.DataAccess.Models
{
/// <summary>
/// 菜单分类 0 表示系统菜单 1 表示用户自定义菜单
/// </summary>
public enum EnumNavigationCategory
{
/// <summary>
/// 系统使用
/// </summary>
[Description("系统使用")]
System,
/// <summary>
/// 用户自定义
/// </summary>
[Description("自定义")]
Customer
}
}

View File

@ -0,0 +1,26 @@
using System.ComponentModel;
namespace BootstrapAdmin.DataAccess.Models
{
/// <summary>
/// 资源类型枚举 0 表示菜单 1 表示资源 2 表示按钮
/// </summary>
public enum EnumResource
{
/// <summary>
///
/// </summary>
[Description("菜单")]
Navigation,
/// <summary>
///
/// </summary>
[Description("资源")]
Resource,
/// <summary>
///
/// </summary>
[Description("块")]
Block
}
}

View File

@ -45,7 +45,7 @@ namespace BootstrapAdmin.DataAccess.Models
/// <summary>
/// 获得/设置 菜单分类, 0 表示系统菜单 1 表示用户自定义菜单
/// </summary>
public string Category { get; set; } = "0";
public EnumNavigationCategory Category { get; set; }
/// <summary>
/// 获得 菜单分类名称取字典表中的Name category="菜单"
@ -65,7 +65,7 @@ namespace BootstrapAdmin.DataAccess.Models
/// <summary>
/// 获得/设置 是否为资源文件, 0 表示菜单 1 表示资源 2 表示按钮
/// </summary>
public int IsResource { get; set; }
public EnumResource IsResource { get; set; }
/// <summary>
/// 获得/设置 所属应用程序此属性由BA后台字典表分配

View File

@ -25,7 +25,7 @@ namespace BootstrapAdmin.DataAccess.PetaPoco.Services
public List<Navigation> RetrieveAllMenus(string userName)
{
var order = Database.Provider.EscapeSqlIdentifier("Order");
return Database.Fetch<Models.Navigation>($"select n.ID, n.ParentId, n.Name, n.{order}, n.Icon, n.Url, n.Category, n.Target, n.IsResource, n.Application, d.Name as CategoryName, ln.Name as ParentName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = @Category and d.Define = 0 left join Navigations ln on n.ParentId = ln.ID inner join (select nr.NavigationID from Users u inner join UserRole ur on ur.UserID = u.ID inner join NavigationRole nr on nr.RoleID = ur.RoleID where u.UserName = @UserName union select nr.NavigationID from Users u inner join UserGroup ug on u.ID = ug.UserID inner join RoleGroup rg on rg.GroupID = ug.GroupID inner join NavigationRole nr on nr.RoleID = rg.RoleID where u.UserName = @UserName union select n.ID from Navigations n where EXISTS (select UserName from Users u inner join UserRole ur on u.ID = ur.UserID inner join Roles r on ur.RoleID = r.ID where u.UserName = @UserName and r.RoleName = @RoleName)) nav on n.ID = nav.NavigationID", new { UserName = userName, Category = "菜单", RoleName = "Administrators" });
return Database.Fetch<Models.Navigation>($"select n.ID, n.ParentId, n.Name, n.{order}, n.Icon, n.Url, n.Category, n.Target, n.IsResource, n.Application, d.Name as CategoryName, ln.Name as ParentName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = @Category and d.Define = 'System' left join Navigations ln on n.ParentId = ln.ID inner join (select nr.NavigationID from Users u inner join UserRole ur on ur.UserID = u.ID inner join NavigationRole nr on nr.RoleID = ur.RoleID where u.UserName = @UserName union select nr.NavigationID from Users u inner join UserGroup ug on u.ID = ug.UserID inner join RoleGroup rg on rg.GroupID = ug.GroupID inner join NavigationRole nr on nr.RoleID = rg.RoleID where u.UserName = @UserName union select n.ID from Navigations n where EXISTS (select UserName from Users u inner join UserRole ur on u.ID = ur.UserID inner join Roles r on ur.RoleID = r.ID where u.UserName = @UserName and r.RoleName = @RoleName)) nav on n.ID = nav.NavigationID", new { UserName = userName, Category = "菜单", RoleName = "Administrators" });
}
}
}

View File

@ -25,12 +25,22 @@ namespace BootstrapAdmin.Web.Extensions
};
/// <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>
/// <returns></returns>
public static IEnumerable<MenuItem> ToAdminMenus(this List<Navigation> navigations)
{
var menus = navigations.Where(m => m.Category == "0" && m.IsResource == 0);
var menus = navigations.Where(m => m.Category == EnumNavigationCategory.System && m.IsResource == 0);
return CascadeMenus(menus);
}

View File

@ -65,10 +65,10 @@ namespace Microsoft.Extensions.DependencyInjection
services.AddSingleton<BootstrapAppContext>();
// 增加 PetaPoco 数据服务
//services.AddPetaPocoDataAccessServices();
services.AddPetaPocoDataAccessServices();
// 增加 EFCore 数据服务
services.AddEFCoreDataAccessServices();
//services.AddEFCoreDataAccessServices();
return services;
}