重构代码:使用BootstrapMenu操作类的内置参数acrtiveUrl精简代码

This commit is contained in:
Argo-Surface 2017-07-25 14:57:10 +08:00
parent 2531ab76b0
commit accabd7cc0
1 changed files with 1 additions and 14 deletions

View File

@ -1,8 +1,6 @@
using Bootstrap.DataAccess; using Bootstrap.DataAccess;
using Bootstrap.Security; using Bootstrap.Security;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace Bootstrap.Admin.Models namespace Bootstrap.Admin.Models
{ {
@ -10,21 +8,10 @@ namespace Bootstrap.Admin.Models
{ {
public NavigatorBarModel(string url) public NavigatorBarModel(string url)
{ {
Navigations = BootstrapMenu.RetrieveSystemMenus(UserName); Navigations = BootstrapMenu.RetrieveSystemMenus(UserName, url);
Applications = DictHelper.RetrieveApps(); Applications = DictHelper.RetrieveApps();
ActiveMenu(null, Navigations.ToList(), url);
HomeUrl = "~/Admin/Index"; HomeUrl = "~/Admin/Index";
} }
private void ActiveMenu(BootstrapMenu parent, List<BootstrapMenu> menus, string url)
{
menus.ForEach(m =>
{
m.Active = m.Url.Equals(url, StringComparison.OrdinalIgnoreCase) ? "active" : "";
ActiveMenu(m, m.Menus.ToList(), url);
if (parent != null && m.Active != "") parent.Active = m.Active;
});
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>