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 @@ <PackageReference Include="Longbow.Web" Version="2.2.15" /> <PackageReference Include="Microsoft.AspNetCore.App" /> <PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.6" /> + <PackageReference Include="Longbow.Cache" Version="2.2.14" /> </ItemGroup> </Project> 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<SignalRHub>("/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 { /// <summary> - /// + /// 菜单实体类 /// </summary> public class Menu : DataAccess.Menu { /// <summary> - /// + /// 获取指定用户的所有菜单 /// </summary> /// <param name="userName"></param> /// <returns></returns> @@ -29,7 +29,7 @@ namespace Bootstrap.DataAccess.MongoDB } /// <summary> - /// + /// 保存菜单 /// </summary> /// <param name="p"></param> /// <returns></returns> @@ -58,7 +58,7 @@ namespace Bootstrap.DataAccess.MongoDB } /// <summary> - /// + /// 删除菜单 /// </summary> /// <param name="value"></param> /// <returns></returns> @@ -74,14 +74,14 @@ namespace Bootstrap.DataAccess.MongoDB } /// <summary> - /// + /// 获取指定角色相关菜单 /// </summary> /// <param name="roleId"></param> /// <returns></returns> - public override IEnumerable<object> RetrieveMenusByRoleId(string roleId) => DbManager.Roles.Find(md => md.Id == roleId).FirstOrDefault().Menus.Select(m => new { Id = m }); + public override IEnumerable<string> RetrieveMenusByRoleId(string roleId) => DbManager.Roles.Find(md => md.Id == roleId).FirstOrDefault().Menus; /// <summary> - /// + /// 保存指定角色相关菜单 /// </summary> /// <param name="roleId"></param> /// <param name="menuIds"></param> 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 @@ <PackageReference Include="Longbow.PetaPoco" Version="1.0.2" /> <PackageReference Include="Longbow.Security.Cryptography" Version="1.3.0" /> <PackageReference Include="Longbow.Web" Version="2.2.15" /> - <PackageReference Include="Longbow.Cache" Version="2.2.13" /> + <PackageReference Include="Longbow.Cache" Version="2.2.14" /> <PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.6" /> <PackageReference Include="PetaPoco.Extensions" Version="1.0.9" /> </ItemGroup> 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 { /// <summary> - /// + /// 缓存清理操作类 /// </summary> public static class CacheCleanUtility { private const string RetrieveAllRolesDataKey = "BootstrapAdminRoleMiddleware-RetrieveRoles"; /// <summary> - /// + /// 清理缓存 /// </summary> /// <param name="roleIds"></param> /// <param name="userIds"></param> @@ -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 { /// <summary> - /// + /// 菜单操作类 /// </summary> public static class MenuHelper { /// <summary> - /// + /// 通过指定角色ID相关菜单缓存键值 /// </summary> public const string RetrieveMenusByRoleIdDataKey = "MenuHelper-RetrieveMenusByRoleId"; /// <summary> - /// + /// 通过当前用户获取所有菜单数据缓存键名称 "BootstrapMenu-RetrieveMenus" /// </summary> public const string RetrieveMenusAll = DbHelper.RetrieveMenusAll; /// <summary> - /// + /// 保存菜单 /// </summary> /// <param name="p"></param> /// <returns></returns> @@ -38,7 +38,7 @@ namespace Bootstrap.DataAccess } /// <summary> - /// + /// 删除菜单 /// </summary> /// <param name="value"></param> /// <returns></returns> @@ -64,14 +64,14 @@ namespace Bootstrap.DataAccess public static IEnumerable<BootstrapMenu> RetrieveMenusByUserName(string userName) => RetrieveAllMenus(userName); /// <summary> - /// + /// 通过角色获取相关菜单集合 /// </summary> /// <param name="roleId"></param> /// <returns></returns> - public static IEnumerable<object> RetrieveMenusByRoleId(string roleId) => CacheManager.GetOrAdd($"{RetrieveMenusByRoleIdDataKey}-{roleId}", k => DbContextManager.Create<Menu>().RetrieveMenusByRoleId(roleId), RetrieveMenusByRoleIdDataKey); + public static IEnumerable<string> RetrieveMenusByRoleId(string roleId) => CacheManager.GetOrAdd($"{RetrieveMenusByRoleIdDataKey}-{roleId}", k => DbContextManager.Create<Menu>().RetrieveMenusByRoleId(roleId), RetrieveMenusByRoleIdDataKey); /// <summary> - /// + /// 保存指定角色的所有菜单 /// </summary> /// <param name="roleId"></param> /// <param name="menuIds"></param> @@ -84,7 +84,7 @@ namespace Bootstrap.DataAccess } /// <summary> - /// + /// 获取指定用户的应用程序菜单 /// </summary> /// <param name="appId"></param> /// <param name="userName"></param> 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 { /// <summary> - /// + /// 菜单实体类 /// </summary> [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<Menu>($"where ID in ({ids})"); + db.Execute($"delete from NavigationRole where NavigationID in @value", new { value }); + db.Delete<Menu>($"where ID in @value", new { value }); db.CompleteTransaction(); ret = true; } @@ -38,6 +37,7 @@ namespace Bootstrap.DataAccess } return ret; } + /// <summary> /// 保存新建/更新的菜单信息 /// </summary> @@ -53,16 +53,18 @@ namespace Bootstrap.DataAccess DbManager.Create().Save(p); return true; } + /// <summary> /// 查询某个角色所配置的菜单 /// </summary> /// <param name="roleId"></param> /// <returns></returns> - public virtual IEnumerable<object> RetrieveMenusByRoleId(string roleId) + public virtual IEnumerable<string> RetrieveMenusByRoleId(string roleId) { var menus = DbManager.Create().Fetch<BootstrapMenu>("select NavigationID as Id from NavigationRole where RoleID = @0", roleId); - return menus.Select(m => new { m.Id }); + return menus.Select(m => m.Id); } + /// <summary> /// 通过角色ID保存当前授权菜单 /// </summary> @@ -88,6 +90,7 @@ namespace Bootstrap.DataAccess } return ret; } + /// <summary> /// 通过当前用户名获得所有菜单 /// </summary>