获取菜单包含不可见菜单
This commit is contained in:
parent
1165904bf0
commit
e43b1bd34c
|
@ -221,7 +221,7 @@ namespace NewLife.Cube.Admin.Controllers
|
|||
[EntityAuthorize()]
|
||||
public ActionResult GetMenuTree() => Ok(data: GetMenu());
|
||||
|
||||
private List<MenuTree> GetMenu()
|
||||
private IList<MenuTree> GetMenu()
|
||||
{
|
||||
var user = _provider.Current as IUser ?? XCode.Membership.User.FindAll().FirstOrDefault();
|
||||
|
||||
|
@ -229,17 +229,16 @@ namespace NewLife.Cube.Admin.Controllers
|
|||
var menus = fact.Root.Childs;
|
||||
if (user?.Role != null)
|
||||
{
|
||||
menus = fact.GetMySubMenus(fact.Root.ID, user);
|
||||
menus = fact.GetMySubMenus(fact.Root.ID, user, true);
|
||||
}
|
||||
|
||||
// 如果顶级只有一层,并且至少有三级目录,则提升一级
|
||||
if (menus.Count == 1 && menus[0].Childs.All(m => m.Childs.Count > 0)) { menus = menus[0].Childs; }
|
||||
|
||||
menus = menus.Where(m => m.Visible).ToList();
|
||||
|
||||
var menuTree = MenuTree.GetMenuTree(pMenuTree =>
|
||||
{
|
||||
return fact.GetMySubMenus(pMenuTree.ID, user).Where(m => m.Visible).ToList();
|
||||
var subMenus = fact.GetMySubMenus(pMenuTree.ID, user, true);
|
||||
return subMenus;
|
||||
}, list =>
|
||||
{
|
||||
|
||||
|
@ -251,12 +250,11 @@ namespace NewLife.Cube.Admin.Controllers
|
|||
Name = menu.DisplayName,
|
||||
Url = Url.Content(menu.Url),
|
||||
Icon = menu.Icon,
|
||||
Class = ""
|
||||
Visible = menu.Visible
|
||||
}).ToList();
|
||||
return menuList.Count > 0 ? menuList : null;
|
||||
}, menus.ToList());
|
||||
}, menus);
|
||||
|
||||
//var childs = menuTree[0].Children;
|
||||
return menuTree;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
@{
|
||||
String[] icos = new String[] { "fa-tachometer", "fa-desktop", "fa-list", "fa-pencil-square-o", "fa-list-alt", "fa-calendar", "fa-picture-o", "fa-tag", "fa-file-o" };
|
||||
Int32 _idx = 0;
|
||||
var menus = ViewBag.Menus as List<MenuTree> ?? new List<MenuTree>();
|
||||
var menus = ViewBag.Menus as IList<MenuTree> ?? new List<MenuTree>();
|
||||
}
|
||||
<ul class="nav nav-list">
|
||||
@foreach (var menu in menus)
|
||||
@foreach (var menu in menus.Where(w=>w.Visible))
|
||||
{
|
||||
var childs = menu.Children ?? new List<MenuTree>();
|
||||
if (_idx >= icos.Length) { _idx = 0; }
|
||||
|
@ -22,7 +22,7 @@
|
|||
<b class="arrow"></b>
|
||||
|
||||
<ul @Html.Raw(menu == menus[0] ? "class=\"submenu nav-show\" style=\"display:block;\"" : "class=\"submenu nav-hide\" style=\"display:none;\"")>
|
||||
@foreach (var menu2 in childs)
|
||||
@foreach (var menu2 in childs.Where(w=>w.Visible))
|
||||
{
|
||||
@await Html.PartialAsync("_Left_Item", menu2);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
<b class="arrow"></b>
|
||||
<ul class="submenu">
|
||||
@foreach (var menu in childs)
|
||||
@foreach (var menu in childs.Where(w=>w.Visible))
|
||||
{
|
||||
@await Html.PartialAsync("_Left_Item", menu);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace NewLife.Cube.Extensions
|
|||
if (key == "output") return null;
|
||||
|
||||
var entityBody = request.GetRequestBody<NullableDictionary<String, Object>>();
|
||||
return entityBody?[key].ToString();
|
||||
return !entityBody.TryGetValue(key, out var v) ? null : v?.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NewLife.Cube.ViewModels
|
||||
|
@ -30,20 +30,20 @@ namespace NewLife.Cube.ViewModels
|
|||
/// <value></value>
|
||||
public String Icon { get; set; }
|
||||
/// <summary>
|
||||
/// 自定义样式类
|
||||
/// 是否可见
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public String Class { get; set; }
|
||||
public Boolean Visible { get; set; }
|
||||
/// <summary>
|
||||
/// 子菜单
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public List<MenuTree> Children { get => GetChildren?.Invoke(this) ?? null; set { } }
|
||||
public IList<MenuTree> Children { get => GetChildren?.Invoke(this) ?? null; set { } }
|
||||
|
||||
/// <summary>
|
||||
/// 获取子菜单的方法
|
||||
/// </summary>
|
||||
private static Func<MenuTree, List<MenuTree>> GetChildren;
|
||||
private static Func<MenuTree, IList<MenuTree>> GetChildren;
|
||||
|
||||
/// <summary>
|
||||
/// 获取菜单树
|
||||
|
@ -52,12 +52,14 @@ namespace NewLife.Cube.ViewModels
|
|||
/// <param name="getMenuList">获取菜单列表的方法</param>
|
||||
/// <param name="src">获取菜单列表的初始数据来源</param>
|
||||
/// <returns></returns>
|
||||
public static List<MenuTree> GetMenuTree<T>(Func<MenuTree, T> getChildrenSrc,
|
||||
Func<T, List<MenuTree>> getMenuList, T src) where T : class, new()
|
||||
public static IList<MenuTree> GetMenuTree<T>(Func<MenuTree, T> getChildrenSrc,
|
||||
Func<T, IList<MenuTree>> getMenuList, T src) where T : class
|
||||
{
|
||||
GetChildren = m =>getMenuList?.Invoke(getChildrenSrc(m));
|
||||
GetChildren = m => getMenuList?.Invoke(getChildrenSrc(m));
|
||||
|
||||
return getMenuList?.Invoke(src);
|
||||
}
|
||||
|
||||
public override String ToString() => Name;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue