abp(net core)+easyui+efcore实现仓储管理系统——ABP整体介绍(一)html
abp(net core)+easyui+efcore实现仓储管理系统——解决方案介绍(二)数据库
abp(net core)+easyui+efcore实现仓储管理系统——领域层建立实体(三)app
abp(net core)+easyui+efcore实现仓储管理系统——定义仓储并实现 (四)框架
abp(net core)+easyui+efcore实现仓储管理系统——建立应用服务(五)ide
abp(net core)+easyui+efcore实现仓储管理系统——展示层实现增删改查之控制器(六)函数
abp(net core)+easyui+efcore实现仓储管理系统——展示层实现增删改查之列表视图(七)post
abp(net core)+easyui+efcore实现仓储管理系统——展示层实现增删改查之增删改视图(八)测试
abp(net core)+easyui+efcore实现仓储管理系统——展示层实现增删改查之菜单与测试(九)ui
abp(net core)+easyui+efcore实现仓储管理系统——多语言(十)this
abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十一)
abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十二)
abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十三)
abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十四)
abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十五)
在前面的文章(abp(net core)+easyui+efcore实现仓储管理系统——展示层实现增删改查之菜单与测试(九) )中咱们学会了如何添加静态菜单,可是作为一个信息管理系统,总不能每次有新功能新菜单,都静态添加菜单,编译,再上线。咱们但愿的是有一个菜单管理界面,在此页面中输入相应的菜单,只要咱们从新登陆,菜单就自动显示在菜单栏中。而菜单的来源能够是多样的,能够从须要从数据库,xml等数据源中加载一些动态菜单来知足咱们的系统要求。
今天咱们就来实现这个功能,动态加载菜单。所要加载的菜单就是模块管理中的功能模块。
一个应用程序可能包含不一样的模块,而每一个模块均可能有它本身的菜单项。在Abp中,须要建立一个派生自NavigationProvider的类来定义一个菜单项。例如咱们这个项目中的TPLMSNavigationProvider类。代码以下。
using Abp.Application.Navigation; using Abp.Localization; using ABP.TPLMS.Authorization; namespace ABP.TPLMS.Web.Startup { /// <summary> /// This class defines menus for the application. /// </summary> public class TPLMSNavigationProvider : NavigationProvider { public override void SetNavigation(INavigationProviderContext context) { context.Manager.MainMenu .AddItem( new MenuItemDefinition( PageNames.Home, L("HomePage"), url: "", icon: "home", requiresAuthentication: true ) ).AddItem( new MenuItemDefinition( PageNames.Tenants, L("Tenants"), url: "Tenants", icon: "business", requiredPermissionName: PermissionNames.Pages_Tenants ) ).AddItem( new MenuItemDefinition( PageNames.Users, L("Users"), url: "Users", icon: "people", requiredPermissionName: PermissionNames.Pages_Users ) ).AddItem( new MenuItemDefinition( PageNames.Roles, L("Roles"), url: "Roles", icon: "local_offer", requiredPermissionName: PermissionNames.Pages_Roles ) ) .AddItem( new MenuItemDefinition( PageNames.Module, L("Module"), url: "Module", icon: "local_offer" ) ) .AddItem( new MenuItemDefinition( PageNames.Supplier, L("Supplier"), url: "Supplier", icon: "people" ) ) .AddItem( new MenuItemDefinition( PageNames.About, L("About"), url: "About", icon: "info" ) ).AddItem( // Menu items below is just for demonstration! new MenuItemDefinition( "MultiLevelMenu", L("MultiLevelMenu"), icon: "menu" ).AddItem( new MenuItemDefinition( "AspNetBoilerplate", new FixedLocalizableString("ASP.NET Boilerplate") ).AddItem( new MenuItemDefinition( "AspNetZero", new FixedLocalizableString("ASP.NET Zero") ).AddItem( new MenuItemDefinition( "AspNetZeroHome", new FixedLocalizableString("Home"), url: "https://aspnetzero.com?ref=abptmpl" ) ).AddItem( new MenuItemDefinition( "AspNetZeroDocuments", new FixedLocalizableString("Documents"), url: "https://aspnetzero.com/Documents?ref=abptmpl" ) ) ) ); } private static ILocalizableString L(string name) { return new LocalizableString(name, TPLMSConsts.LocalizationSourceName); } } }
2、abp菜单类
ABP框架中已经为咱们作了前期的准备工做。在ABP中有一个MenuDefinition类,这个类封装了导航栏上的主菜单的属性。
MenuDefinition:主菜单类,定义了一个List<MenuItemDefinition>,这个类存放了咱们定义的菜单,同时定义了AddItem方法
using System.Collections.Generic; using Abp.Localization; namespace Abp.Application.Navigation { // Represents a navigation menu for an application. public class MenuDefinition : IHasMenuItemDefinitions { // // 构造函数 // public MenuDefinition(string name, ILocalizableString displayName, object customData = null); // //菜单名称 // public string Name { get; } // //表示本地化字符串 // public ILocalizableString DisplayName { get; set; } // //自定义数据 // public object CustomData { get; set; } // 菜单集合 public List<MenuItemDefinition> Items { get; set; } // 添加菜单 // public MenuDefinition AddItem(MenuItemDefinition menuItem); // // 删除菜单 // public void RemoveItem(string name); } }
在ABP中还有一个MenuItemDefinition类,这个类中封装了子菜单的属性,子菜单能够添加其余子菜单构成一个菜单树。咱们首先来了解一下MenuItemDefinition类的属性与方法。MenuItemDefinition成员定义以下:
public class MenuItemDefinition : IHasMenuItemDefinitions { // // 构造函数: public MenuItemDefinition(string name, ILocalizableString displayName, string icon = null, string url = null,
bool requiresAuthentication = false, string requiredPermissionName = null, int order = 0, object customData = null,
IFeatureDependency featureDependency = null, string target = null, bool isEnabled = true, bool isVisible = true,
IPermissionDependency permissionDependency = null); // // 摘要: // Can be used to enable/disable a menu item. public bool IsEnabled { get; set; } // 自定义数据 public object CustomData { get; set; } // // 摘要: // Target of the menu item. Can be "_blank", "_self", "_parent", "_top" or a frame // name. public string Target { get; set; } // 是否有子菜单 public bool IsLeaf { get; } // 权限验证若是经过验证显示此菜单不然不可见 //即只有登录后才会显示该菜单 public bool RequiresAuthentication { get; set; } // 功能特性 public IFeatureDependency FeatureDependency { get; set; } // // 摘要: // A permission dependency. Only users that can satisfy this permission dependency // can see this menu item. Optional. public IPermissionDependency PermissionDependency { get; set; } //即用户具备指定的权限时才显示菜单 // 权限名称 [Obsolete("Use PermissionDependency instead.")] public string RequiredPermissionName { get; set; } // The URL to navigate when this menu item is selected. public string Url { get; set; } // 菜单图标 public string Icon { get; set; } // 排序 public int Order { get; set; } // 表示本地化字符串 public ILocalizableString DisplayName { get; set; } // 菜单名称 public string Name { get; } // 是否显示菜单 public bool IsVisible { get; set; } // 子菜单 public virtual List<MenuItemDefinition> Items { get; } // 添加子菜单 public MenuItemDefinition AddItem(MenuItemDefinition menuItem); // 删除菜单: public void RemoveItem(string name); } }
从上面的代码中,咱们能够看到作为一个菜单树的相关属性与相关方法,ABP都已经为咱们准备好了。有了以上对象咱们能够方便自定义任何菜单。