diff --git a/Bootstrap.Admin/wwwroot/js/roles.js b/Bootstrap.Admin/wwwroot/js/roles.js index 847a1e07..226f0ff1 100644 --- a/Bootstrap.Admin/wwwroot/js/roles.js +++ b/Bootstrap.Admin/wwwroot/js/roles.js @@ -66,7 +66,7 @@ $(function () { var menus = $nestMenu.find('input:checkbox'); menus.prop('checked', false); $.each(result, function (index, item) { - var selector = $.format('[value={0}]', item.Id); + var selector = $.format('[value={0}]', item); menus.filter(selector).prop('checked', true); }); $dialogSubMenu.show(); diff --git a/Bootstrap.Client/Bootstrap.Client.csproj b/Bootstrap.Client/Bootstrap.Client.csproj index 05216050..9d6d960e 100644 --- a/Bootstrap.Client/Bootstrap.Client.csproj +++ b/Bootstrap.Client/Bootstrap.Client.csproj @@ -13,6 +13,7 @@ + diff --git a/Bootstrap.Client/Startup.cs b/Bootstrap.Client/Startup.cs index e3681e4c..c558aa90 100644 --- a/Bootstrap.Client/Startup.cs +++ b/Bootstrap.Client/Startup.cs @@ -89,7 +89,7 @@ namespace Bootstrap.Client app.UseStaticFiles(); app.UseCookiePolicy(); app.UseBootstrapAdminAuthentication(); - app.UseCacheManagerCorsHandler(); + app.UseCacheManager(); app.UseSignalR(routes => { routes.MapHub("/NotiHub"); }); app.UseMvc(routes => { diff --git a/Bootstrap.DataAccess.MongoDB/Menu.cs b/Bootstrap.DataAccess.MongoDB/Menu.cs index f4f3f077..af546032 100644 --- a/Bootstrap.DataAccess.MongoDB/Menu.cs +++ b/Bootstrap.DataAccess.MongoDB/Menu.cs @@ -6,12 +6,12 @@ using System.Linq; namespace Bootstrap.DataAccess.MongoDB { /// - /// + /// 菜单实体类 /// public class Menu : DataAccess.Menu { /// - /// + /// 获取指定用户的所有菜单 /// /// /// @@ -29,7 +29,7 @@ namespace Bootstrap.DataAccess.MongoDB } /// - /// + /// 保存菜单 /// /// /// @@ -58,7 +58,7 @@ namespace Bootstrap.DataAccess.MongoDB } /// - /// + /// 删除菜单 /// /// /// @@ -74,14 +74,14 @@ namespace Bootstrap.DataAccess.MongoDB } /// - /// + /// 获取指定角色相关菜单 /// /// /// - public override IEnumerable RetrieveMenusByRoleId(string roleId) => DbManager.Roles.Find(md => md.Id == roleId).FirstOrDefault().Menus.Select(m => new { Id = m }); + public override IEnumerable RetrieveMenusByRoleId(string roleId) => DbManager.Roles.Find(md => md.Id == roleId).FirstOrDefault().Menus; /// - /// + /// 保存指定角色相关菜单 /// /// /// diff --git a/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj b/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj index 16a0289a..3919e9d7 100644 --- a/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj +++ b/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj @@ -11,7 +11,7 @@ - + diff --git a/Bootstrap.DataAccess/CacheCleanUtility.cs b/Bootstrap.DataAccess/CacheCleanUtility.cs index ef2f8421..3790696d 100644 --- a/Bootstrap.DataAccess/CacheCleanUtility.cs +++ b/Bootstrap.DataAccess/CacheCleanUtility.cs @@ -5,13 +5,13 @@ using System.Linq; namespace Bootstrap.DataAccess { /// - /// + /// 缓存清理操作类 /// public static class CacheCleanUtility { private const string RetrieveAllRolesDataKey = "BootstrapAdminRoleMiddleware-RetrieveRoles"; /// - /// + /// 清理缓存 /// /// /// @@ -44,11 +44,11 @@ namespace Bootstrap.DataAccess cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByUserIdDataKey, id)); cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByUserIdDataKey, id)); cacheKeys.Add(MenuHelper.RetrieveMenusAll + "*"); - corsKeys.Add(MenuHelper.RetrieveMenusAll + "*"); }); cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey + "*"); cacheKeys.Add(UserHelper.RetrieveUsersDataKey + "*"); corsKeys.Add(UserHelper.RetrieveUsersDataKey + "*"); + corsKeys.Add(MenuHelper.RetrieveMenusAll + "*"); } if (groupIds != null) { @@ -89,7 +89,7 @@ namespace Bootstrap.DataAccess corsKeys.Add(cacheKey); } CacheManager.Clear(cacheKeys); - CacheManager.CorsClear(corsKeys); + CacheManager.CorsClear(corsKeys.Distinct()); } } } diff --git a/Bootstrap.DataAccess/Helper/MenuHelper.cs b/Bootstrap.DataAccess/Helper/MenuHelper.cs index aca1d932..66728b59 100644 --- a/Bootstrap.DataAccess/Helper/MenuHelper.cs +++ b/Bootstrap.DataAccess/Helper/MenuHelper.cs @@ -8,22 +8,22 @@ using System.Linq; namespace Bootstrap.DataAccess { /// - /// + /// 菜单操作类 /// public static class MenuHelper { /// - /// + /// 通过指定角色ID相关菜单缓存键值 /// public const string RetrieveMenusByRoleIdDataKey = "MenuHelper-RetrieveMenusByRoleId"; /// - /// + /// 通过当前用户获取所有菜单数据缓存键名称 "BootstrapMenu-RetrieveMenus" /// public const string RetrieveMenusAll = DbHelper.RetrieveMenusAll; /// - /// + /// 保存菜单 /// /// /// @@ -38,7 +38,7 @@ namespace Bootstrap.DataAccess } /// - /// + /// 删除菜单 /// /// /// @@ -64,14 +64,14 @@ namespace Bootstrap.DataAccess public static IEnumerable RetrieveMenusByUserName(string userName) => RetrieveAllMenus(userName); /// - /// + /// 通过角色获取相关菜单集合 /// /// /// - public static IEnumerable RetrieveMenusByRoleId(string roleId) => CacheManager.GetOrAdd($"{RetrieveMenusByRoleIdDataKey}-{roleId}", k => DbContextManager.Create().RetrieveMenusByRoleId(roleId), RetrieveMenusByRoleIdDataKey); + public static IEnumerable RetrieveMenusByRoleId(string roleId) => CacheManager.GetOrAdd($"{RetrieveMenusByRoleIdDataKey}-{roleId}", k => DbContextManager.Create().RetrieveMenusByRoleId(roleId), RetrieveMenusByRoleIdDataKey); /// - /// + /// 保存指定角色的所有菜单 /// /// /// @@ -84,7 +84,7 @@ namespace Bootstrap.DataAccess } /// - /// + /// 获取指定用户的应用程序菜单 /// /// /// diff --git a/Bootstrap.DataAccess/Menu.cs b/Bootstrap.DataAccess/Menu.cs index e9f2d92d..865e3f3d 100644 --- a/Bootstrap.DataAccess/Menu.cs +++ b/Bootstrap.DataAccess/Menu.cs @@ -8,7 +8,7 @@ using System.Linq; namespace Bootstrap.DataAccess { /// - /// + /// 菜单实体类 /// [TableName("Navigations")] public class Menu : BootstrapMenu @@ -24,10 +24,9 @@ namespace Bootstrap.DataAccess var db = DbManager.Create(); try { - var ids = string.Join(",", value); db.BeginTransaction(); - db.Execute($"delete from NavigationRole where NavigationID in ({ids})"); - db.Delete($"where ID in ({ids})"); + db.Execute($"delete from NavigationRole where NavigationID in @value", new { value }); + db.Delete($"where ID in @value", new { value }); db.CompleteTransaction(); ret = true; } @@ -38,6 +37,7 @@ namespace Bootstrap.DataAccess } return ret; } + /// /// 保存新建/更新的菜单信息 /// @@ -53,16 +53,18 @@ namespace Bootstrap.DataAccess DbManager.Create().Save(p); return true; } + /// /// 查询某个角色所配置的菜单 /// /// /// - public virtual IEnumerable RetrieveMenusByRoleId(string roleId) + public virtual IEnumerable RetrieveMenusByRoleId(string roleId) { var menus = DbManager.Create().Fetch("select NavigationID as Id from NavigationRole where RoleID = @0", roleId); - return menus.Select(m => new { m.Id }); + return menus.Select(m => m.Id); } + /// /// 通过角色ID保存当前授权菜单 /// @@ -88,6 +90,7 @@ namespace Bootstrap.DataAccess } return ret; } + /// /// 通过当前用户名获得所有菜单 ///