refactor: 移除字典表中菜单配置项
This commit is contained in:
parent
e14b053c72
commit
25fae681ae
|
@ -5,8 +5,6 @@ INSERT INTO Users (UserName, Password, PassSalt, DisplayName, RegisterTime, Appr
|
||||||
INSERT INTO Users (UserName, Password, PassSalt, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, [Description], [App]) values ('User', 'tXG/yNffpnm6cThrCH7wf6jN1ic3VHvLoY4OrzKtrZ4=', 'c5cIrRMn8XjB84M/D/X7Lg9uUqQFmYNEdxb/4HWH8OLa4pNZ', '测试账号', datetime(CURRENT_TIMESTAMP, 'localtime'), datetime(CURRENT_TIMESTAMP, 'localtime'), 'system', '系统默认创建', 'Demo');
|
INSERT INTO Users (UserName, Password, PassSalt, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, [Description], [App]) values ('User', 'tXG/yNffpnm6cThrCH7wf6jN1ic3VHvLoY4OrzKtrZ4=', 'c5cIrRMn8XjB84M/D/X7Lg9uUqQFmYNEdxb/4HWH8OLa4pNZ', '测试账号', datetime(CURRENT_TIMESTAMP, 'localtime'), datetime(CURRENT_TIMESTAMP, 'localtime'), 'system', '系统默认创建', 'Demo');
|
||||||
|
|
||||||
DELETE From Dicts Where Define = 0;
|
DELETE From Dicts Where Define = 0;
|
||||||
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('菜单', '系统菜单', '0', 0);
|
|
||||||
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('菜单', '外部菜单', '1', 0);
|
|
||||||
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('应用程序', '后台管理', 'BA', 0);
|
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('应用程序', '后台管理', 'BA', 0);
|
||||||
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('网站设置', '网站标题', '后台管理系统', 0);
|
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('网站设置', '网站标题', '后台管理系统', 0);
|
||||||
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('网站设置', '网站页脚', '2016 © 通用后台管理系统', 0);
|
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('网站设置', '网站页脚', '2016 © 通用后台管理系统', 0);
|
||||||
|
|
|
@ -10,12 +10,12 @@ public enum EnumNavigationCategory
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 系统使用
|
/// 系统使用
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Description("系统使用")]
|
[Description("后台菜单")]
|
||||||
System,
|
System,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 用户自定义
|
/// 用户自定义
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Description("自定义")]
|
[Description("前台菜单")]
|
||||||
Customer
|
Customer
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ class NavigationService : INavigation
|
||||||
return CacheManager.GetOrAdd($"{nameof(NavigationService)}-{nameof(GetAllMenus)}-{userName}", entry =>
|
return CacheManager.GetOrAdd($"{nameof(NavigationService)}-{nameof(GetAllMenus)}-{userName}", entry =>
|
||||||
{
|
{
|
||||||
var order = Database.Provider.EscapeSqlIdentifier("Order");
|
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, ln.Name as ParentName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = @Category and d.Define = @Define 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 ORDER BY n.Application, n.{order}", new { UserName = userName, Category = "菜单", RoleName = "Administrators", Define = EnumDictDefine.System });
|
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 from Navigations n 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 ORDER BY n.Application, n.{order}", new { UserName = userName, RoleName = "Administrators" });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -16,7 +16,7 @@ namespace BootstrapAdmin.Web.Extensions
|
||||||
public static MenuItem Parse(this DataAccess.Models.Navigation menu) => new()
|
public static MenuItem Parse(this DataAccess.Models.Navigation menu) => new()
|
||||||
{
|
{
|
||||||
Text = menu.Name,
|
Text = menu.Name,
|
||||||
Url = menu.Url.Replace("~", ""),
|
Url = menu.Url.Replace("~/", "/"),
|
||||||
Icon = menu.Icon,
|
Icon = menu.Icon,
|
||||||
Match = NavLinkMatch.All,
|
Match = NavLinkMatch.All,
|
||||||
Target = menu.Target,
|
Target = menu.Target,
|
||||||
|
@ -24,21 +24,11 @@ namespace BootstrapAdmin.Web.Extensions
|
||||||
ParentId = menu.ParentId
|
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>
|
||||||
/// 获取后台管理菜单
|
/// 获取后台管理菜单
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<MenuItem> ToAdminMenus(this List<Navigation> navigations)
|
public static IEnumerable<MenuItem> ToMenus(this IEnumerable<Navigation> navigations)
|
||||||
{
|
{
|
||||||
var menus = navigations.Where(m => m.Category == EnumNavigationCategory.System && m.IsResource == 0);
|
var menus = navigations.Where(m => m.Category == EnumNavigationCategory.System && m.IsResource == 0);
|
||||||
return CascadeMenus(menus);
|
return CascadeMenus(menus);
|
||||||
|
|
|
@ -133,7 +133,7 @@ namespace BootstrapAdmin.Web.Shared
|
||||||
Context.DisplayName = DisplayName;
|
Context.DisplayName = DisplayName;
|
||||||
Icon = string.IsNullOrEmpty(user?.Icon) ? "/images/uploader/default.jpg" : GetIcon(user.Icon);
|
Icon = string.IsNullOrEmpty(user?.Icon) ? "/images/uploader/default.jpg" : GetIcon(user.Icon);
|
||||||
|
|
||||||
MenuItems = NavigationsService.GetAllMenus(UserName).ToAdminMenus();
|
MenuItems = NavigationsService.GetAllMenus(UserName).ToMenus();
|
||||||
}
|
}
|
||||||
|
|
||||||
Title = DictsService.GetWebTitle();
|
Title = DictsService.GetWebTitle();
|
||||||
|
|
Loading…
Reference in New Issue