73 lines
2.3 KiB
C#
73 lines
2.3 KiB
C#
using Microsoft.AspNetCore.Html;
|
|
using System.Text;
|
|
|
|
namespace YLErp.Web
|
|
{
|
|
public class MenuRender : BasicViewModel
|
|
{
|
|
public MenuRender(UserInfo userInfo) : base(userInfo)
|
|
{
|
|
}
|
|
|
|
public IHtmlContent ShowMenu(IHtmlHelper helper, List<MenuItem> menus)
|
|
{
|
|
var currentMenu = Array.Empty<string>();
|
|
|
|
if (helper.ViewBag.Menu != null)
|
|
{
|
|
currentMenu = helper.ViewBag.Menu.ToString().Split('-');
|
|
}
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
foreach (var item in menus)
|
|
{
|
|
RentItemV2(sb, item, currentMenu);
|
|
}
|
|
|
|
return new HtmlString(sb.ToString());
|
|
}
|
|
|
|
private void RentItemV2(StringBuilder sb, MenuItem item, string[] currentMenu)
|
|
{
|
|
if (!string.IsNullOrEmpty(item.Rights[0]) && !CurUser.HasRight(item.Rights[0]))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var css = string.Empty;
|
|
if (currentMenu.Length > item.Level)
|
|
{
|
|
if (currentMenu[item.Level] == item.Name)
|
|
{
|
|
css = item.SubItems != null ? "active-page open" : "active";
|
|
}
|
|
}
|
|
|
|
sb.Append("<li class='").Append(css).Append("'>");
|
|
if (item.SubItems != null)
|
|
{
|
|
sb.AppendFormat(@"
|
|
<a href=""javascript:void(0);"">
|
|
<i class=""menu-icon {0}""></i><span class='menu-text'>{1}</span><i class=""accordion-icon fa fa-angle-left""></i>
|
|
</a>
|
|
<ul class='sub-menu'>", item.Icon, item.Name).AppendLine();
|
|
foreach (var subitem in item.SubItems)
|
|
{
|
|
RentItemV2(sb, subitem, currentMenu);
|
|
}
|
|
sb.AppendLine("</ul>");
|
|
}
|
|
else
|
|
{
|
|
var target = item.Target.TrimToNull();
|
|
if (target == null && (item.Url.StartsWith("http:") || item.Url.StartsWith("/RiskHedging/Index2", StringComparison.OrdinalIgnoreCase)))
|
|
{
|
|
target = " target='_blank' ";
|
|
}
|
|
sb.AppendFormat(@"<a href='{0}' {1}>{2}</a>", item.Url, target, item.Name).AppendLine();
|
|
}
|
|
sb.AppendLine("</li>");
|
|
}
|
|
}
|
|
} |