feat: 增加菜单默认排序规则

This commit is contained in:
Argo-Tianyi 2021-12-29 15:31:11 +08:00
parent 0a6317ec5c
commit 7e7b9d0ec0
3 changed files with 3 additions and 3 deletions

View File

@ -23,7 +23,7 @@ namespace BootstrapAdmin.DataAccess.PetaPoco.Services
public List<Navigation> GetAllMenus(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, 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" });
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 = '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 ORDER BY n.Application, n.{order}", new { UserName = userName, Category = "菜单", RoleName = "Administrators" });
}
/// <summary>

View File

@ -7,7 +7,7 @@ public static class TreeItemExtensions
public static List<TreeItem> ToTreeItemList(this IEnumerable<Navigation> navigations, List<string> selectedItems, RenderFragment<Navigation> render, string? parentId = "0")
{
var trees = new List<TreeItem>();
var roots = navigations.Where(i => i.ParentId == parentId).OrderBy(i => i.Order);
var roots = navigations.Where(i => i.ParentId == parentId).OrderBy(i => i.Application).ThenBy(i => i.Order);
foreach (var node in roots)
{
trees.Add(new TreeItem

View File

@ -64,7 +64,7 @@ public partial class Menus
private Task<QueryData<Navigation>> OnQueryAsync(QueryPageOptions options)
{
var navs = NavigationService.GetAllMenus(AppContext.UserName);
var menus = navs.Where(m => m.ParentId == "0").OrderBy(m => m.Application).ThenBy(m => m.Order);
var menus = navs.Where(m => m.ParentId == "0");
foreach (var item in menus)
{
item.HasChildren = navs.Any(i => i.ParentId == item.Id);