v7.3.2018.0614   重构高性能资源池,减少GC压力,增加线程池,让异步任务得到平等竞争CPU的机会
大石头 authored at 2018-06-14 17:56:44
1.94 KiB
X
@using NewLife.Model;
@{
    var user = ViewBag.User as IUser ?? User.Identity as IUser;

    var fact = ObjectContainer.Current.Resolve<IMenuFactory>();

    var Menus = fact.Root.Childs;
    if (user != null && user.Role != null)
    {
        Menus = fact.GetMySubMenus(fact.Root.ID, user);
    }

    // 如果顶级只有一层,并且至少有三级目录,则提升一级
    if (Menus.Count == 1 && Menus[0].Childs.All(m => m.Childs.Count > 0)) { Menus = Menus[0].Childs; }

    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;
}
<ul class="nav nav-list">
    @foreach (IMenu menu in Menus.Where(m => m.Visible))
    {
        var childs = fact.GetMySubMenus(menu.ID, user).Where(m => m.Visible);
        if (_idx >= icos.Length) { _idx = 0; }
        <li @Html.Raw(menu == Menus[0] ? "class=\"active open\"" : "")>
            <a href="#" class="dropdown-toggle">
                <i class="menu-icon fa @icos[_idx++]"></i>
                <span class="menu-text">@menu.DisplayName</span>

                <b class="arrow fa fa-angle-down"></b>
            </a>
            @if (childs.Any())
            {
                <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 (IMenu menu2 in childs)
                    {
                        @Html.Partial("_Left_Item", menu2);
                    }
                </ul>

                @*<ul class="submenu">
                        @foreach (IMenu menu2 in childs)
                        {
                            @Html.Partial("_Left_Item", menu2);
                        }
                    </ul>*@
            }
        </li>
    }
</ul>
<!-- /.nav-list -->