diff --git a/DncZeus.Api/Auth/AppAuthenticationSettings.cs b/DncZeus.Api/Auth/AppAuthenticationSettings.cs index 05dfa17..b475ff2 100644 --- a/DncZeus.Api/Auth/AppAuthenticationSettings.cs +++ b/DncZeus.Api/Auth/AppAuthenticationSettings.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Auth/JwtBearerAuthenticationExtension.cs b/DncZeus.Api/Auth/JwtBearerAuthenticationExtension.cs index dd75339..31666b1 100644 --- a/DncZeus.Api/Auth/JwtBearerAuthenticationExtension.cs +++ b/DncZeus.Api/Auth/JwtBearerAuthenticationExtension.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Configurations/MappingProfile.cs b/DncZeus.Api/Configurations/MappingProfile.cs index 21fc60b..dfd0f72 100644 --- a/DncZeus.Api/Configurations/MappingProfile.cs +++ b/DncZeus.Api/Configurations/MappingProfile.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Controllers/AccountController.cs b/DncZeus.Api/Controllers/AccountController.cs index 4bc62d6..edf904c 100644 --- a/DncZeus.Api/Controllers/AccountController.cs +++ b/DncZeus.Api/Controllers/AccountController.cs @@ -1,14 +1,14 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ using DncZeus.Api.Entities; using DncZeus.Api.Extensions; using DncZeus.Api.Extensions.AuthContext; -using DncZeus.Api.Extensions.DataAccess; +using DncZeus.Api.ViewModels.Rbac.DncMenu; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -56,7 +56,7 @@ public IActionResult Profile() LEFT JOIN DncPermission AS P ON P.Code = RPM.PermissionCode INNER JOIN DncMenu AS M ON M.Guid = P.MenuGuid WHERE P.IsDeleted=0 AND P.Status=1 AND EXISTS (SELECT 1 FROM DncUserRoleMapping AS URM WHERE URM.UserGuid={0} AND URM.RoleCode=RPM.RoleCode)"; - if (user.UserType == UserType.SuperAdministator) + if (user.UserType == UserType.SuperAdministrator) { //如果是超级管理员 sqlPermission = @"SELECT P.Code AS PermissionCode,P.ActionCode AS PermissionActionCode,P.Name AS PermissionName,P.Type AS PermissionType,M.Name AS MenuName,M.Guid AS MenuGuid,M.Alias AS MenuAlias,M.IsDefaultRouter FROM DncPermission AS P @@ -64,24 +64,8 @@ public IActionResult Profile() WHERE P.IsDeleted=0 AND P.Status=1"; } var permissions = _dbContext.DncPermissionWithMenu.FromSql(sqlPermission, user.Guid).ToList(); - var allowPages = new List { }; - - if (user.UserType == UserType.SuperAdministator) - { - allowPages.AddRange(menus.Select(x => x.Alias)); - } - else - { - allowPages.AddRange(menus.Where(x => x.IsDefaultRouter == YesOrNo.Yes).Select(x => x.Alias)); - foreach (var permission in permissions.Where(x => x.PermissionType == PermissionType.Menu)) - { - allowPages.AddRange(FindParentMenuAlias(menus, permission.MenuGuid)); - } - } - - //var allowPages = FindParentMenuAlias(menus); - var pages = allowPages.Distinct().ToList(); - var pagePermissions = permissions.GroupBy(x => x.MenuAlias).ToDictionary(g=>g.Key,g=>g.Select(x=>x.PermissionActionCode)); + + var pagePermissions = permissions.GroupBy(x => x.MenuAlias).ToDictionary(g => g.Key, g => g.Select(x => x.PermissionActionCode).Distinct()); response.SetData(new { access = new string[] { }, @@ -89,7 +73,6 @@ public IActionResult Profile() user_guid = user.Guid, user_name = user.DisplayName, user_type = user.UserType, - pages, // =new[] { "rbac", "rbac_user_page", "rbac_menu_page", "rbac_role_page", "rbac_permission_page", "rbac_role_permission_page" }, permissions = pagePermissions }); @@ -120,5 +103,101 @@ private List FindParentMenuAlias(List menus, Guid? parentGuid) return pages.Distinct().ToList(); } + + /// + /// + /// + /// + [HttpGet] + public IActionResult Menu() + { + var strSql = @"SELECT M.* FROM DncRolePermissionMapping AS RPM +LEFT JOIN DncPermission AS P ON P.Code = RPM.PermissionCode +INNER JOIN DncMenu AS M ON M.Guid = P.MenuGuid +WHERE P.IsDeleted=0 AND P.Status=1 AND P.Type=0 AND M.IsDeleted=0 AND M.Status=1 AND EXISTS (SELECT 1 FROM DncUserRoleMapping AS URM WHERE URM.UserGuid={0} AND URM.RoleCode=RPM.RoleCode)"; + + if (AuthContextService.CurrentUser.UserType == UserType.SuperAdministrator) + { + //如果是超级管理员 + strSql = @"SELECT * FROM DncMenu WHERE IsDeleted=0 AND Status=1"; + } + var menus = _dbContext.DncMenu.FromSql(strSql, AuthContextService.CurrentUser.Guid).ToList(); + var rootMenus = _dbContext.DncMenu.Where(x => x.IsDeleted == IsDeleted.No && x.Status == Status.Normal && x.ParentGuid == Guid.Empty).ToList(); + foreach (var root in rootMenus) + { + if (menus.Exists(x => x.Guid == root.Guid)) + { + continue; + } + menus.Add(root); + } + var menu = MenuItemHelper.LoadMenuTree(menus, "0"); + return Ok(menu); + } + } + + /// + /// + /// + public static class MenuItemHelper + { + /// + /// + /// + /// + /// + /// + public static List BuildTree(this List menus, string selectedGuid = null) + { + var lookup = menus.ToLookup(x => x.ParentId); + + List Build(string pid) + { + return lookup[pid] + .Select(x => new MenuItem() + { + Guid = x.Guid, + ParentId = x.ParentId, + Children = Build(x.Guid), + Component = x.Component ?? "Main", + Name = x.Name, + Path = x.Path, + Meta = new MenuMeta + { + BeforeCloseFun = x.Meta.BeforeCloseFun, + HideInMenu = x.Meta.HideInMenu, + Icon = x.Meta.Icon, + NotCache = x.Meta.NotCache, + Title = x.Meta.Title, + Permission = x.Meta.Permission + } + }).ToList(); + } + + var result = Build(selectedGuid); + return result; + } + + public static List LoadMenuTree(List menus, string selectedGuid = null) + { + var temp = menus.Select(x => new MenuItem + { + Guid = x.Guid.ToString(), + ParentId = x.ParentGuid != null && ((Guid)x.ParentGuid) == Guid.Empty ? "0" : x.ParentGuid?.ToString(), + Name = x.Alias, + Path = $"/{x.Url}", + Component = x.Component, + Meta = new MenuMeta + { + BeforeCloseFun = x.BeforeCloseFun ?? "", + HideInMenu = x.HideInMenu == YesOrNo.Yes, + Icon = x.Icon, + NotCache = x.NotCache == YesOrNo.Yes, + Title = x.Name + } + }).ToList(); + var tree = temp.BuildTree(selectedGuid); + return tree; + } } } \ No newline at end of file diff --git a/DncZeus.Api/Controllers/Api/V1/MessageController.cs b/DncZeus.Api/Controllers/Api/V1/MessageController.cs index 190501f..f1cd614 100644 --- a/DncZeus.Api/Controllers/Api/V1/MessageController.cs +++ b/DncZeus.Api/Controllers/Api/V1/MessageController.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Controllers/Api/V1/Rbac/IconController.cs b/DncZeus.Api/Controllers/Api/V1/Rbac/IconController.cs index 14eef36..e30267a 100644 --- a/DncZeus.Api/Controllers/Api/V1/Rbac/IconController.cs +++ b/DncZeus.Api/Controllers/Api/V1/Rbac/IconController.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Controllers/Api/V1/Rbac/MenuController.cs b/DncZeus.Api/Controllers/Api/V1/Rbac/MenuController.cs index 7d763ea..e5233f2 100644 --- a/DncZeus.Api/Controllers/Api/V1/Rbac/MenuController.cs +++ b/DncZeus.Api/Controllers/Api/V1/Rbac/MenuController.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ @@ -155,7 +155,10 @@ public IActionResult Edit(MenuEditViewModel model) entity.ModifiedOn = DateTime.Now; entity.Description = model.Description; entity.ParentName = model.ParentName; - + entity.Component = model.Component; + entity.HideInMenu = model.HideInMenu; + entity.NotCache = model.NotCache; + entity.BeforeCloseFun = model.BeforeCloseFun; if (!ConfigurationManager.AppSettings.IsTrialVersion) { entity.Alias = model.Alias; diff --git a/DncZeus.Api/Controllers/Api/V1/Rbac/PermissionController.cs b/DncZeus.Api/Controllers/Api/V1/Rbac/PermissionController.cs index d792db8..6e610a2 100644 --- a/DncZeus.Api/Controllers/Api/V1/Rbac/PermissionController.cs +++ b/DncZeus.Api/Controllers/Api/V1/Rbac/PermissionController.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Controllers/Api/V1/Rbac/RoleController.cs b/DncZeus.Api/Controllers/Api/V1/Rbac/RoleController.cs index e75d6c8..3cd974f 100644 --- a/DncZeus.Api/Controllers/Api/V1/Rbac/RoleController.cs +++ b/DncZeus.Api/Controllers/Api/V1/Rbac/RoleController.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Controllers/Api/V1/Rbac/UserController.cs b/DncZeus.Api/Controllers/Api/V1/Rbac/UserController.cs index 276d0cb..0ee2500 100644 --- a/DncZeus.Api/Controllers/Api/V1/Rbac/UserController.cs +++ b/DncZeus.Api/Controllers/Api/V1/Rbac/UserController.cs @@ -28,7 +28,7 @@ namespace DncZeus.Api.Controllers.Api.V1.Rbac //[CustomAuthorize] [Route("api/v1/rbac/[controller]/[action]")] [ApiController] - [CustomAuthorize] + //[CustomAuthorize] public class UserController : ControllerBase { private readonly DncZeusDbContext _dbContext; diff --git a/DncZeus.Api/Controllers/ErrorController.cs b/DncZeus.Api/Controllers/ErrorController.cs index f9ef3fd..26b8218 100644 --- a/DncZeus.Api/Controllers/ErrorController.cs +++ b/DncZeus.Api/Controllers/ErrorController.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Controllers/OauthController.cs b/DncZeus.Api/Controllers/OauthController.cs index e389b7d..14118e1 100644 --- a/DncZeus.Api/Controllers/OauthController.cs +++ b/DncZeus.Api/Controllers/OauthController.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/DncZeus.Api.csproj b/DncZeus.Api/DncZeus.Api.csproj index 8f89210..150ceb8 100644 --- a/DncZeus.Api/DncZeus.Api.csproj +++ b/DncZeus.Api/DncZeus.Api.csproj @@ -15,6 +15,13 @@ 1701;1702;1591 + + + + + + + @@ -29,7 +36,6 @@ - diff --git a/DncZeus.Api/Entities/AuditEntity.cs b/DncZeus.Api/Entities/AuditEntity.cs index ad540f4..b7b676d 100644 --- a/DncZeus.Api/Entities/AuditEntity.cs +++ b/DncZeus.Api/Entities/AuditEntity.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Entities/DncAuthDbContext.cs b/DncZeus.Api/Entities/DncAuthDbContext.cs index 6f9ad78..243d0e5 100644 --- a/DncZeus.Api/Entities/DncAuthDbContext.cs +++ b/DncZeus.Api/Entities/DncAuthDbContext.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ @@ -81,6 +81,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.HasIndex(x => x.Code).IsUnique(); }); + modelBuilder.Entity(entity => + { + //entity.haso + }); + modelBuilder.Entity(entity => { diff --git a/DncZeus.Api/Entities/DncIcon.cs b/DncZeus.Api/Entities/DncIcon.cs index 333585e..4a3ebbe 100644 --- a/DncZeus.Api/Entities/DncIcon.cs +++ b/DncZeus.Api/Entities/DncIcon.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-11-14 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * DESCRIPTION: 图标实体类 ******************************************/ using System; diff --git a/DncZeus.Api/Entities/DncMenu.cs b/DncZeus.Api/Entities/DncMenu.cs index 40aa7df..7449977 100644 --- a/DncZeus.Api/Entities/DncMenu.cs +++ b/DncZeus.Api/Entities/DncMenu.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-11-13 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * DESCRIPTION: 菜单实体类 ******************************************/ @@ -103,6 +103,25 @@ public class DncMenu /// 最近修改者姓名 /// public string ModifiedByUserName { get; set; } + /// + /// 前端组件(.vue) + /// + [StringLength(255)] + public string Component { get; set; } + + /// + /// 在菜单中隐藏 + /// + public YesOrNo? HideInMenu { get; set; } + /// + /// 不缓存页面 + /// + public YesOrNo? NotCache { get; set; } + /// + /// 页面关闭前的回调函数 + /// + [StringLength(255)] + public string BeforeCloseFun { get; set; } /// /// 菜单拥有的权限列表 diff --git a/DncZeus.Api/Entities/DncPermission.cs b/DncZeus.Api/Entities/DncPermission.cs index 03b30ec..8ae84ad 100644 --- a/DncZeus.Api/Entities/DncPermission.cs +++ b/DncZeus.Api/Entities/DncPermission.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Entities/DncRole.cs b/DncZeus.Api/Entities/DncRole.cs index 4ec4ca5..530adbe 100644 --- a/DncZeus.Api/Entities/DncRole.cs +++ b/DncZeus.Api/Entities/DncRole.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-11-06 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * DESCRIPTION: 角色实体类 ******************************************/ using System; diff --git a/DncZeus.Api/Entities/DncRolePermissionMapping.cs b/DncZeus.Api/Entities/DncRolePermissionMapping.cs index 7cc9b8e..bf99bfb 100644 --- a/DncZeus.Api/Entities/DncRolePermissionMapping.cs +++ b/DncZeus.Api/Entities/DncRolePermissionMapping.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Entities/DncUser.cs b/DncZeus.Api/Entities/DncUser.cs index 6b4a26b..0f966a5 100644 --- a/DncZeus.Api/Entities/DncUser.cs +++ b/DncZeus.Api/Entities/DncUser.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core ******************************************/ using System; using System.Collections.Generic; @@ -81,7 +81,7 @@ public enum UserType /// /// 超级管理员 /// - SuperAdministator = 0, + SuperAdministrator = 0, /// /// 管理员 /// diff --git a/DncZeus.Api/Entities/DncUserRoleMapping.cs b/DncZeus.Api/Entities/DncUserRoleMapping.cs index 127d61b..cbf761e 100644 --- a/DncZeus.Api/Entities/DncUserRoleMapping.cs +++ b/DncZeus.Api/Entities/DncUserRoleMapping.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Entities/Entity.cs b/DncZeus.Api/Entities/Entity.cs index 552ad6f..688bbde 100644 --- a/DncZeus.Api/Entities/Entity.cs +++ b/DncZeus.Api/Entities/Entity.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Entities/Enums/CommonEnum.cs b/DncZeus.Api/Entities/Enums/CommonEnum.cs index 5240528..0ed9559 100644 --- a/DncZeus.Api/Entities/Enums/CommonEnum.cs +++ b/DncZeus.Api/Entities/Enums/CommonEnum.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Entities/QueryModels/DncPermission/DncPermissionWithAssignProperty.cs b/DncZeus.Api/Entities/QueryModels/DncPermission/DncPermissionWithAssignProperty.cs index 8a4bdc7..33480dc 100644 --- a/DncZeus.Api/Entities/QueryModels/DncPermission/DncPermissionWithAssignProperty.cs +++ b/DncZeus.Api/Entities/QueryModels/DncPermission/DncPermissionWithAssignProperty.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Entities/QueryModels/DncPermission/DncPermissionWithMenu.cs b/DncZeus.Api/Entities/QueryModels/DncPermission/DncPermissionWithMenu.cs index d19501d..d29ee7f 100644 --- a/DncZeus.Api/Entities/QueryModels/DncPermission/DncPermissionWithMenu.cs +++ b/DncZeus.Api/Entities/QueryModels/DncPermission/DncPermissionWithMenu.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Extensions/AuthContext/AuthContextService.cs b/DncZeus.Api/Extensions/AuthContext/AuthContextService.cs index 9adf636..7f075c4 100644 --- a/DncZeus.Api/Extensions/AuthContext/AuthContextService.cs +++ b/DncZeus.Api/Extensions/AuthContext/AuthContextService.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ @@ -68,7 +68,7 @@ public static bool IsSupperAdministator { get { - return ((UserType)Convert.ToInt32(Current.User.FindFirstValue("userType"))== UserType.SuperAdministator); + return ((UserType)Convert.ToInt32(Current.User.FindFirstValue("userType"))== UserType.SuperAdministrator); } } } diff --git a/DncZeus.Api/Extensions/AuthContext/AuthContextUser.cs b/DncZeus.Api/Extensions/AuthContext/AuthContextUser.cs index 2b7bf29..d4d6bde 100644 --- a/DncZeus.Api/Extensions/AuthContext/AuthContextUser.cs +++ b/DncZeus.Api/Extensions/AuthContext/AuthContextUser.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Extensions/CustomException/CanAccess.cs b/DncZeus.Api/Extensions/CustomException/CanAccess.cs new file mode 100644 index 0000000..9423c0c --- /dev/null +++ b/DncZeus.Api/Extensions/CustomException/CanAccess.cs @@ -0,0 +1,67 @@ +/****************************************** + * AUTHOR: Rector + * CREATEDON: 2019-01-08 + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * 版权所有,请勿删除 + ******************************************/ + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace DncZeus.Api.Extensions.CustomException +{ + /// + /// 用户可以访问的控制器及操作权限 + /// + public class CanAccess + { + /// + /// 控制器 + /// + public string Controller { get; set; } + /// + /// Action集合 + /// + public List Actions { get; set; } + } + + /// + /// 用户拥有的API操作权限 + /// + public class OwnedApiPermission + { + /// + /// + /// + public OwnedApiPermission() + { + CanAccesses = new List(); + } + /// + /// 可以访问的API控制器集合 + /// + public List CanAccesses { get; set; } + + /// + /// 是否可以访问 + /// + /// + /// + /// + public bool Can(string controller, string action) + { + if (string.IsNullOrEmpty(controller) || string.IsNullOrEmpty(action)) + { + return false; + } + var ctrl = CanAccesses.Where(x => string.Equals(controller, x.Controller,StringComparison.OrdinalIgnoreCase)).FirstOrDefault(x => x.Controller == controller); + if (ctrl == null) + { + return false; + } + + return ctrl.Actions.Contains(action, StringComparer.OrdinalIgnoreCase); + } + } +} diff --git a/DncZeus.Api/Extensions/CustomException/CustomAuthorize.cs b/DncZeus.Api/Extensions/CustomException/CustomAuthorize.cs index a31cd79..2dc5123 100644 --- a/DncZeus.Api/Extensions/CustomException/CustomAuthorize.cs +++ b/DncZeus.Api/Extensions/CustomException/CustomAuthorize.cs @@ -1,12 +1,15 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ +using DncZeus.Api.Extensions.AuthContext; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.Extensions.Caching.Memory; using System; namespace DncZeus.Api.Extensions.CustomException @@ -17,42 +20,53 @@ namespace DncZeus.Api.Extensions.CustomException [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] public class CustomAuthorizeAttribute : AuthorizeAttribute, IAuthorizationFilter { - //private readonly string _someFilterParameter; + // https://tpodolak.com/blog/2017/12/13/asp-net-core-memorycache-getorcreate-calls-factory-method-multiple-times/ + private IMemoryCache _memoryCache; /// /// /// public CustomAuthorizeAttribute() { - //_someFilterParameter = someFilterParameter; } + /// + /// 操作的别名 + /// + public string ActionAlias { get; set; } + /// /// /// /// public void OnAuthorization(AuthorizationFilterContext context) { + return; var user = context.HttpContext.User; if (!user.Identity.IsAuthenticated) { - // it isn't needed to set unauthorized result - // as the base class already requires the user to be authenticated - // this also makes redirect to a login page work properly - //context.Result = new UnauthorizedResult(); - //return; throw new UnauthorizeException(); } - - // you can also use registered services - //var someService = context.HttpContext.RequestServices.GetService(); - - //var isAuthorized = someService.IsUserAuthorized(user.Identity.Name, _someFilterParameter); - //if (!isAuthorized) - //{ - // context.Result = new StatusCodeResult(System.Net.HttpStatusCode.Forbidden); - // return; - //} + OwnedApiPermission entry = new OwnedApiPermission(); + _memoryCache = (IMemoryCache)context.HttpContext.RequestServices.GetService(typeof(IMemoryCache)); + _memoryCache.GetOrCreate("CK_PERMISSION_" + AuthContextService.CurrentUser.LoginName, (cache) => + { + //TODO: load real permission list from db + //entry = new OwnedApiPermission(); + cache.SlidingExpiration = TimeSpan.FromMinutes(30); + return entry; + }); + var controllerActionDescriptor = context.ActionDescriptor as ControllerActionDescriptor; + string controllerName = controllerActionDescriptor?.ControllerName; + string actionName = controllerActionDescriptor?.ActionName; + if (!string.IsNullOrEmpty(ActionAlias)) + { + actionName = ActionAlias; + } + if (!entry.Can(controllerName, actionName)) + { + throw new UnauthorizeException(); + } } } } diff --git a/DncZeus.Api/Extensions/CustomException/ErrorDetails.cs b/DncZeus.Api/Extensions/CustomException/ErrorDetails.cs index 87dc13d..b796380 100644 --- a/DncZeus.Api/Extensions/CustomException/ErrorDetails.cs +++ b/DncZeus.Api/Extensions/CustomException/ErrorDetails.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Extensions/CustomException/ExceptionMiddleware.cs b/DncZeus.Api/Extensions/CustomException/ExceptionMiddleware.cs index 1a3e4c6..5a24463 100644 --- a/DncZeus.Api/Extensions/CustomException/ExceptionMiddleware.cs +++ b/DncZeus.Api/Extensions/CustomException/ExceptionMiddleware.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Extensions/CustomException/ExceptionMiddlewareExtensions.cs b/DncZeus.Api/Extensions/CustomException/ExceptionMiddlewareExtensions.cs index 9012c2d..0eecf6a 100644 --- a/DncZeus.Api/Extensions/CustomException/ExceptionMiddlewareExtensions.cs +++ b/DncZeus.Api/Extensions/CustomException/ExceptionMiddlewareExtensions.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Extensions/CustomException/HttpException.cs b/DncZeus.Api/Extensions/CustomException/HttpException.cs index 94a3cc8..d9294c1 100644 --- a/DncZeus.Api/Extensions/CustomException/HttpException.cs +++ b/DncZeus.Api/Extensions/CustomException/HttpException.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Extensions/CustomException/UnauthorizeException.cs b/DncZeus.Api/Extensions/CustomException/UnauthorizeException.cs index 0b1d9d4..792f16c 100644 --- a/DncZeus.Api/Extensions/CustomException/UnauthorizeException.cs +++ b/DncZeus.Api/Extensions/CustomException/UnauthorizeException.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ @@ -9,8 +9,14 @@ namespace DncZeus.Api.Extensions.CustomException { + /// + /// 未授权的异常类 + /// public class UnauthorizeException : Exception { + /// + /// + /// public UnauthorizeException() { diff --git a/DncZeus.Api/Extensions/CustomException/ValidateModelAttribute.cs b/DncZeus.Api/Extensions/CustomException/ValidateModelAttribute.cs index 4be17fc..4509b17 100644 --- a/DncZeus.Api/Extensions/CustomException/ValidateModelAttribute.cs +++ b/DncZeus.Api/Extensions/CustomException/ValidateModelAttribute.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Extensions/DataAccess/EntityFrameworkExtension.cs b/DncZeus.Api/Extensions/DataAccess/EntityFrameworkExtension.cs index 69ce616..bfa136e 100644 --- a/DncZeus.Api/Extensions/DataAccess/EntityFrameworkExtension.cs +++ b/DncZeus.Api/Extensions/DataAccess/EntityFrameworkExtension.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Extensions/DataAccess/SqlParameterHelper.cs b/DncZeus.Api/Extensions/DataAccess/SqlParameterHelper.cs index c841fa9..6903d02 100644 --- a/DncZeus.Api/Extensions/DataAccess/SqlParameterHelper.cs +++ b/DncZeus.Api/Extensions/DataAccess/SqlParameterHelper.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Extensions/DataTableConvert.cs b/DncZeus.Api/Extensions/DataTableConvert.cs index 70100ab..47d7e14 100644 --- a/DncZeus.Api/Extensions/DataTableConvert.cs +++ b/DncZeus.Api/Extensions/DataTableConvert.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Extensions/QueryableExtension.cs b/DncZeus.Api/Extensions/QueryableExtension.cs index 2ce1e93..2d2763d 100644 --- a/DncZeus.Api/Extensions/QueryableExtension.cs +++ b/DncZeus.Api/Extensions/QueryableExtension.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Extensions/ResponseModelFactory.cs b/DncZeus.Api/Extensions/ResponseModelFactory.cs index bf53fe1..3bef4b9 100644 --- a/DncZeus.Api/Extensions/ResponseModelFactory.cs +++ b/DncZeus.Api/Extensions/ResponseModelFactory.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Migrations/20181219071659_Init.Designer.cs b/DncZeus.Api/Migrations/20181219071659_Init.Designer.cs deleted file mode 100644 index ac795a9..0000000 --- a/DncZeus.Api/Migrations/20181219071659_Init.Designer.cs +++ /dev/null @@ -1,337 +0,0 @@ -// -using System; -using DncZeus.Api.Entities; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -namespace DncZeus.Api.Migrations -{ - [DbContext(typeof(DncZeusDbContext))] - [Migration("20181219071659_Init")] - partial class Init - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "2.1.4-rtm-31024") - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("DncZeus.Api.Entities.DncIcon", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - b.Property("Code") - .IsRequired() - .HasColumnType("nvarchar(50)"); - - b.Property("Color") - .HasColumnType("nvarchar(50)"); - - b.Property("CreatedByUserId"); - - b.Property("CreatedByUserName"); - - b.Property("CreatedOn"); - - b.Property("Custom") - .HasColumnType("nvarchar(60)"); - - b.Property("Description") - .HasColumnType("nvarchar(max)"); - - b.Property("IsDeleted"); - - b.Property("ModifiedByUserId"); - - b.Property("ModifiedByUserName"); - - b.Property("ModifiedOn"); - - b.Property("Size") - .HasColumnType("nvarchar(20)"); - - b.Property("Status"); - - b.HasKey("Id"); - - b.ToTable("DncIcon"); - }); - - modelBuilder.Entity("DncZeus.Api.Entities.DncMenu", b => - { - b.Property("Guid"); - - b.Property("Alias") - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedByUserId"); - - b.Property("CreatedByUserName"); - - b.Property("CreatedOn"); - - b.Property("Description") - .HasColumnType("nvarchar(800)"); - - b.Property("Icon") - .HasColumnType("nvarchar(128)"); - - b.Property("Id") - .ValueGeneratedOnAdd() - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - b.Property("IsDefaultRouter"); - - b.Property("IsDeleted"); - - b.Property("Level"); - - b.Property("ModifiedByUserId"); - - b.Property("ModifiedByUserName"); - - b.Property("ModifiedOn"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(50)"); - - b.Property("ParentGuid"); - - b.Property("ParentName"); - - b.Property("Sort"); - - b.Property("Status"); - - b.Property("Url") - .HasColumnType("nvarchar(255)"); - - b.HasKey("Guid"); - - b.ToTable("DncMenu"); - }); - - modelBuilder.Entity("DncZeus.Api.Entities.DncPermission", b => - { - b.Property("Code") - .ValueGeneratedOnAdd() - .HasColumnType("nvarchar(20)"); - - b.Property("ActionCode") - .IsRequired() - .HasColumnType("nvarchar(80)"); - - b.Property("CreatedByUserId"); - - b.Property("CreatedByUserName"); - - b.Property("CreatedOn"); - - b.Property("Description") - .HasColumnType("nvarchar(max)"); - - b.Property("Icon"); - - b.Property("Id") - .ValueGeneratedOnAdd() - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - b.Property("IsDeleted"); - - b.Property("MenuGuid"); - - b.Property("ModifiedByUserId"); - - b.Property("ModifiedByUserName"); - - b.Property("ModifiedOn"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(50)"); - - b.Property("Status"); - - b.Property("Type"); - - b.HasKey("Code"); - - b.HasIndex("Code") - .IsUnique(); - - b.HasIndex("MenuGuid"); - - b.ToTable("DncPermission"); - }); - - modelBuilder.Entity("DncZeus.Api.Entities.DncRole", b => - { - b.Property("Code") - .ValueGeneratedOnAdd() - .HasColumnType("nvarchar(50)"); - - b.Property("CreatedByUserId"); - - b.Property("CreatedByUserName"); - - b.Property("CreatedOn"); - - b.Property("Description") - .HasColumnType("nvarchar(max)"); - - b.Property("Id") - .ValueGeneratedOnAdd() - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - b.Property("IsBuiltin"); - - b.Property("IsDeleted"); - - b.Property("IsSuperAdministrator"); - - b.Property("ModifiedByUserId"); - - b.Property("ModifiedByUserName"); - - b.Property("ModifiedOn"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(50)"); - - b.Property("Status"); - - b.HasKey("Code"); - - b.HasIndex("Code") - .IsUnique(); - - b.ToTable("DncRole"); - }); - - modelBuilder.Entity("DncZeus.Api.Entities.DncRolePermissionMapping", b => - { - b.Property("RoleCode") - .HasColumnType("nvarchar(50)"); - - b.Property("PermissionCode") - .HasColumnType("nvarchar(20)"); - - b.Property("CreatedOn"); - - b.HasKey("RoleCode", "PermissionCode"); - - b.HasIndex("PermissionCode"); - - b.ToTable("DncRolePermissionMapping"); - }); - - modelBuilder.Entity("DncZeus.Api.Entities.DncUser", b => - { - b.Property("Guid"); - - b.Property("Avatar") - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedByUserId"); - - b.Property("CreatedByUserName"); - - b.Property("CreatedOn"); - - b.Property("Description") - .HasColumnType("nvarchar(800)"); - - b.Property("DisplayName") - .HasColumnType("nvarchar(50)"); - - b.Property("Id") - .ValueGeneratedOnAdd() - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - b.Property("IsDeleted"); - - b.Property("IsLocked"); - - b.Property("LoginName") - .IsRequired() - .HasColumnType("nvarchar(50)"); - - b.Property("ModifiedByUserId"); - - b.Property("ModifiedByUserName"); - - b.Property("ModifiedOn"); - - b.Property("Password") - .HasColumnType("nvarchar(255)"); - - b.Property("Status"); - - b.Property("UserType"); - - b.HasKey("Guid"); - - b.ToTable("DncUser"); - }); - - modelBuilder.Entity("DncZeus.Api.Entities.DncUserRoleMapping", b => - { - b.Property("UserGuid"); - - b.Property("RoleCode"); - - b.Property("CreatedOn"); - - b.HasKey("UserGuid", "RoleCode"); - - b.HasIndex("RoleCode"); - - b.ToTable("DncUserRoleMapping"); - }); - - modelBuilder.Entity("DncZeus.Api.Entities.DncPermission", b => - { - b.HasOne("DncZeus.Api.Entities.DncMenu", "Menu") - .WithMany("Permissions") - .HasForeignKey("MenuGuid") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("DncZeus.Api.Entities.DncRolePermissionMapping", b => - { - b.HasOne("DncZeus.Api.Entities.DncPermission", "DncPermission") - .WithMany("Roles") - .HasForeignKey("PermissionCode") - .OnDelete(DeleteBehavior.Restrict); - - b.HasOne("DncZeus.Api.Entities.DncRole", "DncRole") - .WithMany("Permissions") - .HasForeignKey("RoleCode") - .OnDelete(DeleteBehavior.Restrict); - }); - - modelBuilder.Entity("DncZeus.Api.Entities.DncUserRoleMapping", b => - { - b.HasOne("DncZeus.Api.Entities.DncRole", "DncRole") - .WithMany("UserRoles") - .HasForeignKey("RoleCode") - .OnDelete(DeleteBehavior.Restrict); - - b.HasOne("DncZeus.Api.Entities.DncUser", "DncUser") - .WithMany("UserRoles") - .HasForeignKey("UserGuid") - .OnDelete(DeleteBehavior.Restrict); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/DncZeus.Api/Migrations/20181222084512_Mt_Remove_Identity_Column.cs b/DncZeus.Api/Migrations/20181222084512_Mt_Remove_Identity_Column.cs deleted file mode 100644 index 0d8663e..0000000 --- a/DncZeus.Api/Migrations/20181222084512_Mt_Remove_Identity_Column.cs +++ /dev/null @@ -1,254 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace DncZeus.Api.Migrations -{ - public partial class Mt_Remove_Identity_Column : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "CreatedByUserId", - table: "DncUser"); - - migrationBuilder.DropColumn( - name: "Id", - table: "DncUser"); - - migrationBuilder.DropColumn( - name: "ModifiedByUserId", - table: "DncUser"); - - migrationBuilder.DropColumn( - name: "CreatedByUserId", - table: "DncRole"); - - migrationBuilder.DropColumn( - name: "Id", - table: "DncRole"); - - migrationBuilder.DropColumn( - name: "ModifiedByUserId", - table: "DncRole"); - - migrationBuilder.DropColumn( - name: "CreatedByUserId", - table: "DncPermission"); - - migrationBuilder.DropColumn( - name: "Id", - table: "DncPermission"); - - migrationBuilder.DropColumn( - name: "ModifiedByUserId", - table: "DncPermission"); - - migrationBuilder.DropColumn( - name: "CreatedByUserId", - table: "DncMenu"); - - migrationBuilder.DropColumn( - name: "Id", - table: "DncMenu"); - - migrationBuilder.DropColumn( - name: "ModifiedByUserId", - table: "DncMenu"); - - migrationBuilder.DropColumn( - name: "CreatedByUserId", - table: "DncIcon"); - - migrationBuilder.DropColumn( - name: "ModifiedByUserId", - table: "DncIcon"); - - migrationBuilder.AddColumn( - name: "CreatedByUserGuid", - table: "DncUser", - nullable: false, - defaultValue: new Guid("00000000-0000-0000-0000-000000000000")); - - migrationBuilder.AddColumn( - name: "ModifiedByUserGuid", - table: "DncUser", - nullable: true); - - migrationBuilder.AddColumn( - name: "CreatedByUserGuid", - table: "DncRole", - nullable: false, - defaultValue: new Guid("00000000-0000-0000-0000-000000000000")); - - migrationBuilder.AddColumn( - name: "ModifiedByUserGuid", - table: "DncRole", - nullable: true); - - migrationBuilder.AddColumn( - name: "CreatedByUserGuid", - table: "DncPermission", - nullable: false, - defaultValue: new Guid("00000000-0000-0000-0000-000000000000")); - - migrationBuilder.AddColumn( - name: "ModifiedByUserGuid", - table: "DncPermission", - nullable: true); - - migrationBuilder.AddColumn( - name: "CreatedByUserGuid", - table: "DncMenu", - nullable: false, - defaultValue: new Guid("00000000-0000-0000-0000-000000000000")); - - migrationBuilder.AddColumn( - name: "ModifiedByUserGuid", - table: "DncMenu", - nullable: true); - - migrationBuilder.AddColumn( - name: "CreatedByUserGuid", - table: "DncIcon", - nullable: false, - defaultValue: new Guid("00000000-0000-0000-0000-000000000000")); - - migrationBuilder.AddColumn( - name: "ModifiedByUserGuid", - table: "DncIcon", - nullable: true); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "CreatedByUserGuid", - table: "DncUser"); - - migrationBuilder.DropColumn( - name: "ModifiedByUserGuid", - table: "DncUser"); - - migrationBuilder.DropColumn( - name: "CreatedByUserGuid", - table: "DncRole"); - - migrationBuilder.DropColumn( - name: "ModifiedByUserGuid", - table: "DncRole"); - - migrationBuilder.DropColumn( - name: "CreatedByUserGuid", - table: "DncPermission"); - - migrationBuilder.DropColumn( - name: "ModifiedByUserGuid", - table: "DncPermission"); - - migrationBuilder.DropColumn( - name: "CreatedByUserGuid", - table: "DncMenu"); - - migrationBuilder.DropColumn( - name: "ModifiedByUserGuid", - table: "DncMenu"); - - migrationBuilder.DropColumn( - name: "CreatedByUserGuid", - table: "DncIcon"); - - migrationBuilder.DropColumn( - name: "ModifiedByUserGuid", - table: "DncIcon"); - - migrationBuilder.AddColumn( - name: "CreatedByUserId", - table: "DncUser", - nullable: false, - defaultValue: 0); - - migrationBuilder.AddColumn( - name: "Id", - table: "DncUser", - nullable: false, - defaultValue: 0) - .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - migrationBuilder.AddColumn( - name: "ModifiedByUserId", - table: "DncUser", - nullable: false, - defaultValue: 0); - - migrationBuilder.AddColumn( - name: "CreatedByUserId", - table: "DncRole", - nullable: false, - defaultValue: 0); - - migrationBuilder.AddColumn( - name: "Id", - table: "DncRole", - nullable: false, - defaultValue: 0) - .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - migrationBuilder.AddColumn( - name: "ModifiedByUserId", - table: "DncRole", - nullable: false, - defaultValue: 0); - - migrationBuilder.AddColumn( - name: "CreatedByUserId", - table: "DncPermission", - nullable: false, - defaultValue: 0); - - migrationBuilder.AddColumn( - name: "Id", - table: "DncPermission", - nullable: false, - defaultValue: 0) - .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - migrationBuilder.AddColumn( - name: "ModifiedByUserId", - table: "DncPermission", - nullable: false, - defaultValue: 0); - - migrationBuilder.AddColumn( - name: "CreatedByUserId", - table: "DncMenu", - nullable: false, - defaultValue: 0); - - migrationBuilder.AddColumn( - name: "Id", - table: "DncMenu", - nullable: false, - defaultValue: 0) - .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - migrationBuilder.AddColumn( - name: "ModifiedByUserId", - table: "DncMenu", - nullable: false, - defaultValue: 0); - - migrationBuilder.AddColumn( - name: "CreatedByUserId", - table: "DncIcon", - nullable: false, - defaultValue: 0); - - migrationBuilder.AddColumn( - name: "ModifiedByUserId", - table: "DncIcon", - nullable: false, - defaultValue: 0); - } - } -} diff --git a/DncZeus.Api/Migrations/20181222084512_Mt_Remove_Identity_Column.Designer.cs b/DncZeus.Api/Migrations/20190504085011_Init.Designer.cs similarity index 95% rename from DncZeus.Api/Migrations/20181222084512_Mt_Remove_Identity_Column.Designer.cs rename to DncZeus.Api/Migrations/20190504085011_Init.Designer.cs index c160838..8c41ffe 100644 --- a/DncZeus.Api/Migrations/20181222084512_Mt_Remove_Identity_Column.Designer.cs +++ b/DncZeus.Api/Migrations/20190504085011_Init.Designer.cs @@ -10,14 +10,14 @@ namespace DncZeus.Api.Migrations { [DbContext(typeof(DncZeusDbContext))] - [Migration("20181222084512_Mt_Remove_Identity_Column")] - partial class Mt_Remove_Identity_Column + [Migration("20190504085011_Init")] + partial class Init { protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "2.1.4-rtm-31024") + .HasAnnotation("ProductVersion", "2.1.8-servicing-32085") .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); @@ -71,6 +71,12 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Property("Alias") .HasColumnType("nvarchar(255)"); + b.Property("BeforeCloseFun") + .HasMaxLength(255); + + b.Property("Component") + .HasMaxLength(255); + b.Property("CreatedByUserGuid"); b.Property("CreatedByUserName"); @@ -80,6 +86,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Property("Description") .HasColumnType("nvarchar(800)"); + b.Property("HideInMenu"); + b.Property("Icon") .HasColumnType("nvarchar(128)"); @@ -99,6 +107,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .IsRequired() .HasColumnType("nvarchar(50)"); + b.Property("NotCache"); + b.Property("ParentGuid"); b.Property("ParentName"); diff --git a/DncZeus.Api/Migrations/20181219071659_Init.cs b/DncZeus.Api/Migrations/20190504085011_Init.cs similarity index 88% rename from DncZeus.Api/Migrations/20181219071659_Init.cs rename to DncZeus.Api/Migrations/20190504085011_Init.cs index 5ac3a34..c8ea6d5 100644 --- a/DncZeus.Api/Migrations/20181219071659_Init.cs +++ b/DncZeus.Api/Migrations/20190504085011_Init.cs @@ -22,10 +22,10 @@ protected override void Up(MigrationBuilder migrationBuilder) Status = table.Column(nullable: false), IsDeleted = table.Column(nullable: false), CreatedOn = table.Column(nullable: false), - CreatedByUserId = table.Column(nullable: false), + CreatedByUserGuid = table.Column(nullable: false), CreatedByUserName = table.Column(nullable: true), ModifiedOn = table.Column(nullable: true), - ModifiedByUserId = table.Column(nullable: false), + ModifiedByUserGuid = table.Column(nullable: true), ModifiedByUserName = table.Column(nullable: true) }, constraints: table => @@ -37,8 +37,6 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "DncMenu", columns: table => new { - Id = table.Column(nullable: false) - .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), Guid = table.Column(nullable: false), Name = table.Column(type: "nvarchar(50)", nullable: false), Url = table.Column(type: "nvarchar(255)", nullable: true), @@ -53,11 +51,15 @@ protected override void Up(MigrationBuilder migrationBuilder) IsDeleted = table.Column(nullable: false), IsDefaultRouter = table.Column(nullable: false), CreatedOn = table.Column(nullable: false), - CreatedByUserId = table.Column(nullable: false), + CreatedByUserGuid = table.Column(nullable: false), CreatedByUserName = table.Column(nullable: true), ModifiedOn = table.Column(nullable: true), - ModifiedByUserId = table.Column(nullable: false), - ModifiedByUserName = table.Column(nullable: true) + ModifiedByUserGuid = table.Column(nullable: true), + ModifiedByUserName = table.Column(nullable: true), + Component = table.Column(maxLength: 255, nullable: true), + HideInMenu = table.Column(nullable: true), + NotCache = table.Column(nullable: true), + BeforeCloseFun = table.Column(maxLength: 255, nullable: true) }, constraints: table => { @@ -68,18 +70,16 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "DncRole", columns: table => new { - Id = table.Column(nullable: false) - .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), Code = table.Column(type: "nvarchar(50)", nullable: false), Name = table.Column(type: "nvarchar(50)", nullable: false), Description = table.Column(type: "nvarchar(max)", nullable: true), Status = table.Column(nullable: false), IsDeleted = table.Column(nullable: false), CreatedOn = table.Column(nullable: false), - CreatedByUserId = table.Column(nullable: false), + CreatedByUserGuid = table.Column(nullable: false), CreatedByUserName = table.Column(nullable: true), ModifiedOn = table.Column(nullable: true), - ModifiedByUserId = table.Column(nullable: false), + ModifiedByUserGuid = table.Column(nullable: true), ModifiedByUserName = table.Column(nullable: true), IsSuperAdministrator = table.Column(nullable: false), IsBuiltin = table.Column(nullable: false) @@ -93,8 +93,6 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "DncUser", columns: table => new { - Id = table.Column(nullable: false) - .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), Guid = table.Column(nullable: false), LoginName = table.Column(type: "nvarchar(50)", nullable: false), DisplayName = table.Column(type: "nvarchar(50)", nullable: true), @@ -105,10 +103,10 @@ protected override void Up(MigrationBuilder migrationBuilder) Status = table.Column(nullable: false), IsDeleted = table.Column(nullable: false), CreatedOn = table.Column(nullable: false), - CreatedByUserId = table.Column(nullable: false), + CreatedByUserGuid = table.Column(nullable: false), CreatedByUserName = table.Column(nullable: true), ModifiedOn = table.Column(nullable: true), - ModifiedByUserId = table.Column(nullable: false), + ModifiedByUserGuid = table.Column(nullable: true), ModifiedByUserName = table.Column(nullable: true), Description = table.Column(type: "nvarchar(800)", nullable: true) }, @@ -121,8 +119,6 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "DncPermission", columns: table => new { - Id = table.Column(nullable: false) - .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), Code = table.Column(type: "nvarchar(20)", nullable: false), MenuGuid = table.Column(nullable: false), Name = table.Column(type: "nvarchar(50)", nullable: false), @@ -132,11 +128,11 @@ protected override void Up(MigrationBuilder migrationBuilder) Status = table.Column(nullable: false), IsDeleted = table.Column(nullable: false), Type = table.Column(nullable: false), + CreatedByUserGuid = table.Column(nullable: false), CreatedOn = table.Column(nullable: false), - CreatedByUserId = table.Column(nullable: false), CreatedByUserName = table.Column(nullable: true), ModifiedOn = table.Column(nullable: true), - ModifiedByUserId = table.Column(nullable: false), + ModifiedByUserGuid = table.Column(nullable: true), ModifiedByUserName = table.Column(nullable: true) }, constraints: table => diff --git a/DncZeus.Api/Migrations/DncZeusDbContextModelSnapshot.cs b/DncZeus.Api/Migrations/DncZeusDbContextModelSnapshot.cs index 31537cd..8bbd5fe 100644 --- a/DncZeus.Api/Migrations/DncZeusDbContextModelSnapshot.cs +++ b/DncZeus.Api/Migrations/DncZeusDbContextModelSnapshot.cs @@ -15,7 +15,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "2.1.4-rtm-31024") + .HasAnnotation("ProductVersion", "2.1.8-servicing-32085") .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); @@ -69,6 +69,12 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("Alias") .HasColumnType("nvarchar(255)"); + b.Property("BeforeCloseFun") + .HasMaxLength(255); + + b.Property("Component") + .HasMaxLength(255); + b.Property("CreatedByUserGuid"); b.Property("CreatedByUserName"); @@ -78,6 +84,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("Description") .HasColumnType("nvarchar(800)"); + b.Property("HideInMenu"); + b.Property("Icon") .HasColumnType("nvarchar(128)"); @@ -97,6 +105,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired() .HasColumnType("nvarchar(50)"); + b.Property("NotCache"); + b.Property("ParentGuid"); b.Property("ParentName"); diff --git a/DncZeus.Api/Models/Menu/MenuJsonModel.cs b/DncZeus.Api/Models/Menu/MenuJsonModel.cs index 2a78f0d..084ed04 100644 --- a/DncZeus.Api/Models/Menu/MenuJsonModel.cs +++ b/DncZeus.Api/Models/Menu/MenuJsonModel.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Models/Menu/Router.cs b/DncZeus.Api/Models/Menu/Router.cs index 797f422..37a224b 100644 --- a/DncZeus.Api/Models/Menu/Router.cs +++ b/DncZeus.Api/Models/Menu/Router.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Models/Response/ResponseModel.cs b/DncZeus.Api/Models/Response/ResponseModel.cs index 2bd2cb8..b7d927a 100644 --- a/DncZeus.Api/Models/Response/ResponseModel.cs +++ b/DncZeus.Api/Models/Response/ResponseModel.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Models/Response/ResponseResultModel.cs b/DncZeus.Api/Models/Response/ResponseResultModel.cs index 6e9dee9..7ebaa5f 100644 --- a/DncZeus.Api/Models/Response/ResponseResultModel.cs +++ b/DncZeus.Api/Models/Response/ResponseResultModel.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Program.cs b/DncZeus.Api/Program.cs index 735412e..486846b 100644 --- a/DncZeus.Api/Program.cs +++ b/DncZeus.Api/Program.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/RequestPayload/Rbac/Icon/IconRequestPayload.cs b/DncZeus.Api/RequestPayload/Rbac/Icon/IconRequestPayload.cs index 2c66528..8ce73fa 100644 --- a/DncZeus.Api/RequestPayload/Rbac/Icon/IconRequestPayload.cs +++ b/DncZeus.Api/RequestPayload/Rbac/Icon/IconRequestPayload.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/RequestPayload/Rbac/Menu/MenuRequestPayload.cs b/DncZeus.Api/RequestPayload/Rbac/Menu/MenuRequestPayload.cs index 7d5f2e5..b69d573 100644 --- a/DncZeus.Api/RequestPayload/Rbac/Menu/MenuRequestPayload.cs +++ b/DncZeus.Api/RequestPayload/Rbac/Menu/MenuRequestPayload.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/RequestPayload/Rbac/Permission/PermissionRequestPayload.cs b/DncZeus.Api/RequestPayload/Rbac/Permission/PermissionRequestPayload.cs index 3053eec..2298179 100644 --- a/DncZeus.Api/RequestPayload/Rbac/Permission/PermissionRequestPayload.cs +++ b/DncZeus.Api/RequestPayload/Rbac/Permission/PermissionRequestPayload.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/RequestPayload/Rbac/Role/RoleAssignPermissionPayload.cs b/DncZeus.Api/RequestPayload/Rbac/Role/RoleAssignPermissionPayload.cs index a061eef..7b303e8 100644 --- a/DncZeus.Api/RequestPayload/Rbac/Role/RoleAssignPermissionPayload.cs +++ b/DncZeus.Api/RequestPayload/Rbac/Role/RoleAssignPermissionPayload.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/RequestPayload/Rbac/Role/RoleRequestPayload.cs b/DncZeus.Api/RequestPayload/Rbac/Role/RoleRequestPayload.cs index 9382254..b56c9e5 100644 --- a/DncZeus.Api/RequestPayload/Rbac/Role/RoleRequestPayload.cs +++ b/DncZeus.Api/RequestPayload/Rbac/Role/RoleRequestPayload.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/RequestPayload/Rbac/User/UserRequestPayload.cs b/DncZeus.Api/RequestPayload/Rbac/User/UserRequestPayload.cs index b9f6c72..4a72079 100644 --- a/DncZeus.Api/RequestPayload/Rbac/User/UserRequestPayload.cs +++ b/DncZeus.Api/RequestPayload/Rbac/User/UserRequestPayload.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/RequestPayload/RequestPayload.cs b/DncZeus.Api/RequestPayload/RequestPayload.cs index 18dadd4..14a552c 100644 --- a/DncZeus.Api/RequestPayload/RequestPayload.cs +++ b/DncZeus.Api/RequestPayload/RequestPayload.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/Startup.cs b/DncZeus.Api/Startup.cs index ce5cf1d..5ceae39 100644 --- a/DncZeus.Api/Startup.cs +++ b/DncZeus.Api/Startup.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ @@ -55,6 +55,7 @@ public void ConfigureServices(IServiceCollection services) .AllowAnyOrigin() .AllowCredentials() )); + services.AddMemoryCache(); services.AddHttpContextAccessor(); services.AddSingleton(); var appSettingsSection = Configuration.GetSection("AppSettings"); diff --git a/DncZeus.Api/Utils/RandomHelper.cs b/DncZeus.Api/Utils/RandomHelper.cs index 63cfdcb..75d7689 100644 --- a/DncZeus.Api/Utils/RandomHelper.cs +++ b/DncZeus.Api/Utils/RandomHelper.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/ViewModels/Rbac/DncIcon/IconCreateViewModel.cs b/DncZeus.Api/ViewModels/Rbac/DncIcon/IconCreateViewModel.cs index 943917e..2603463 100644 --- a/DncZeus.Api/ViewModels/Rbac/DncIcon/IconCreateViewModel.cs +++ b/DncZeus.Api/ViewModels/Rbac/DncIcon/IconCreateViewModel.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/ViewModels/Rbac/DncIcon/IconImportViewModel.cs b/DncZeus.Api/ViewModels/Rbac/DncIcon/IconImportViewModel.cs index 10a0b62..298b150 100644 --- a/DncZeus.Api/ViewModels/Rbac/DncIcon/IconImportViewModel.cs +++ b/DncZeus.Api/ViewModels/Rbac/DncIcon/IconImportViewModel.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/ViewModels/Rbac/DncIcon/IconJsonModel.cs b/DncZeus.Api/ViewModels/Rbac/DncIcon/IconJsonModel.cs index 9b94eca..0a5f222 100644 --- a/DncZeus.Api/ViewModels/Rbac/DncIcon/IconJsonModel.cs +++ b/DncZeus.Api/ViewModels/Rbac/DncIcon/IconJsonModel.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-11-14 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * DESCRIPTION: 图标信息实体类 ******************************************/ diff --git a/DncZeus.Api/ViewModels/Rbac/DncMenu/MenuCreateViewModel.cs b/DncZeus.Api/ViewModels/Rbac/DncMenu/MenuCreateViewModel.cs index 41098b3..65df811 100644 --- a/DncZeus.Api/ViewModels/Rbac/DncMenu/MenuCreateViewModel.cs +++ b/DncZeus.Api/ViewModels/Rbac/DncMenu/MenuCreateViewModel.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ @@ -63,5 +63,21 @@ public class MenuCreateViewModel /// 是否为默认路由 /// public YesOrNo IsDefaultRouter { get; set; } + /// + /// 前端组件(.vue) + /// + public string Component { get; set; } + /// + /// 在菜单中隐藏 + /// + public YesOrNo HideInMenu { get; set; } + /// + /// 不缓存页面 + /// + public YesOrNo NotCache { get; set; } + /// + /// 页面关闭前的回调函数 + /// + public string BeforeCloseFun { get; set; } } } diff --git a/DncZeus.Api/ViewModels/Rbac/DncMenu/MenuEditViewModel.cs b/DncZeus.Api/ViewModels/Rbac/DncMenu/MenuEditViewModel.cs index 7b66ab6..e7c8ba3 100644 --- a/DncZeus.Api/ViewModels/Rbac/DncMenu/MenuEditViewModel.cs +++ b/DncZeus.Api/ViewModels/Rbac/DncMenu/MenuEditViewModel.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ @@ -67,5 +67,21 @@ public class MenuEditViewModel /// 是否为默认路由 /// public YesOrNo IsDefaultRouter { get; set; } + /// + /// 前端组件(.vue) + /// + public string Component { get; set; } + /// + /// 在菜单中隐藏 + /// + public YesOrNo HideInMenu { get; set; } + /// + /// 不缓存页面 + /// + public YesOrNo NotCache { get; set; } + /// + /// 页面关闭前的回调函数 + /// + public string BeforeCloseFun { get; set; } } } diff --git a/DncZeus.Api/ViewModels/Rbac/DncMenu/MenuItem.cs b/DncZeus.Api/ViewModels/Rbac/DncMenu/MenuItem.cs new file mode 100644 index 0000000..e5c3b61 --- /dev/null +++ b/DncZeus.Api/ViewModels/Rbac/DncMenu/MenuItem.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; + +namespace DncZeus.Api.ViewModels.Rbac.DncMenu +{ + public class MenuItem + { + public MenuItem() + { + Meta = new MenuMeta(); + Children = new List(); + } + public string Guid { get; set; } + public string Name { get; set; } + public string Path { get; set; } + public string Component { get; set; } + public string ParentId { get; set; } + + public MenuMeta Meta { get; set; } + public List Children { get; set; } + } + + public class MenuMeta + { + public MenuMeta() + { + Permission = new List(); + BeforeCloseFun = ""; + } + public bool HideInMenu { get; set; } + public string Icon { get; set; } + public bool NotCache { get; set; } + public string Title { get; set; } + public List Permission { get; set; } + public string BeforeCloseFun { get; set; } + } +} diff --git a/DncZeus.Api/ViewModels/Rbac/DncMenu/MenuJsonModel.cs b/DncZeus.Api/ViewModels/Rbac/DncMenu/MenuJsonModel.cs index a0039b0..04b1bce 100644 --- a/DncZeus.Api/ViewModels/Rbac/DncMenu/MenuJsonModel.cs +++ b/DncZeus.Api/ViewModels/Rbac/DncMenu/MenuJsonModel.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * DESCRIPTION: 菜单信息实体类 ******************************************/ using System; @@ -90,5 +90,21 @@ public class MenuJsonModel /// 最近修改者姓名 /// public string ModifiedByUserName { get; set; } + /// + /// 前端组件(.vue) + /// + public string Component { get; set; } + /// + /// 在菜单中隐藏 + /// + public YesOrNo HideInMenu { get; set; } + /// + /// 不缓存页面 + /// + public YesOrNo NotCache { get; set; } + /// + /// 页面关闭前的回调函数 + /// + public string BeforeCloseFun { get; set; } } } diff --git a/DncZeus.Api/ViewModels/Rbac/DncMenu/MenuTree.cs b/DncZeus.Api/ViewModels/Rbac/DncMenu/MenuTree.cs index d775883..899ae2a 100644 --- a/DncZeus.Api/ViewModels/Rbac/DncMenu/MenuTree.cs +++ b/DncZeus.Api/ViewModels/Rbac/DncMenu/MenuTree.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/ViewModels/Rbac/DncPermission/PermissionCreateViewModel.cs b/DncZeus.Api/ViewModels/Rbac/DncPermission/PermissionCreateViewModel.cs index 127bf93..4d39ee7 100644 --- a/DncZeus.Api/ViewModels/Rbac/DncPermission/PermissionCreateViewModel.cs +++ b/DncZeus.Api/ViewModels/Rbac/DncPermission/PermissionCreateViewModel.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/ViewModels/Rbac/DncPermission/PermissionEditViewModel.cs b/DncZeus.Api/ViewModels/Rbac/DncPermission/PermissionEditViewModel.cs index 14f86ce..c5525c9 100644 --- a/DncZeus.Api/ViewModels/Rbac/DncPermission/PermissionEditViewModel.cs +++ b/DncZeus.Api/ViewModels/Rbac/DncPermission/PermissionEditViewModel.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/ViewModels/Rbac/DncPermission/PermissionJsonModel.cs b/DncZeus.Api/ViewModels/Rbac/DncPermission/PermissionJsonModel.cs index faba58b..43476cf 100644 --- a/DncZeus.Api/ViewModels/Rbac/DncPermission/PermissionJsonModel.cs +++ b/DncZeus.Api/ViewModels/Rbac/DncPermission/PermissionJsonModel.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/ViewModels/Rbac/DncPermission/PermissionRoleTree.cs b/DncZeus.Api/ViewModels/Rbac/DncPermission/PermissionRoleTree.cs index f3cb14f..0f8d9b5 100644 --- a/DncZeus.Api/ViewModels/Rbac/DncPermission/PermissionRoleTree.cs +++ b/DncZeus.Api/ViewModels/Rbac/DncPermission/PermissionRoleTree.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/ViewModels/Rbac/DncRole/RoleCreateViewModel.cs b/DncZeus.Api/ViewModels/Rbac/DncRole/RoleCreateViewModel.cs index ba8a1b3..8a6714b 100644 --- a/DncZeus.Api/ViewModels/Rbac/DncRole/RoleCreateViewModel.cs +++ b/DncZeus.Api/ViewModels/Rbac/DncRole/RoleCreateViewModel.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/ViewModels/Rbac/DncRole/RoleJsonModel.cs b/DncZeus.Api/ViewModels/Rbac/DncRole/RoleJsonModel.cs index 3cdccae..bf73b90 100644 --- a/DncZeus.Api/ViewModels/Rbac/DncRole/RoleJsonModel.cs +++ b/DncZeus.Api/ViewModels/Rbac/DncRole/RoleJsonModel.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * DESCRIPTION: 角色信息实体类 ******************************************/ using System; diff --git a/DncZeus.Api/ViewModels/Rbac/DncUser/SaveUserRolesViewModel.cs b/DncZeus.Api/ViewModels/Rbac/DncUser/SaveUserRolesViewModel.cs index f79f5f7..4b1e33a 100644 --- a/DncZeus.Api/ViewModels/Rbac/DncUser/SaveUserRolesViewModel.cs +++ b/DncZeus.Api/ViewModels/Rbac/DncUser/SaveUserRolesViewModel.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/ViewModels/Rbac/DncUser/UserCreateViewModel.cs b/DncZeus.Api/ViewModels/Rbac/DncUser/UserCreateViewModel.cs index 3591345..327512c 100644 --- a/DncZeus.Api/ViewModels/Rbac/DncUser/UserCreateViewModel.cs +++ b/DncZeus.Api/ViewModels/Rbac/DncUser/UserCreateViewModel.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/ViewModels/Rbac/DncUser/UserEditViewModel.cs b/DncZeus.Api/ViewModels/Rbac/DncUser/UserEditViewModel.cs index a1608ef..189ec24 100644 --- a/DncZeus.Api/ViewModels/Rbac/DncUser/UserEditViewModel.cs +++ b/DncZeus.Api/ViewModels/Rbac/DncUser/UserEditViewModel.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * 版权所有,请勿删除 ******************************************/ diff --git a/DncZeus.Api/ViewModels/Rbac/DncUser/UserJsonModel.cs b/DncZeus.Api/ViewModels/Rbac/DncUser/UserJsonModel.cs index 12d371a..54b87ec 100644 --- a/DncZeus.Api/ViewModels/Rbac/DncUser/UserJsonModel.cs +++ b/DncZeus.Api/ViewModels/Rbac/DncUser/UserJsonModel.cs @@ -1,7 +1,7 @@ /****************************************** * AUTHOR: Rector * CREATEDON: 2018-09-26 - * OFFICAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core + * OFFICIAL_SITE: 码友网(https://codedefault.com)--专注.NET/.NET Core * DESCRIPTION: 用户信息实体类 ******************************************/ using DncZeus.Api.Entities; diff --git a/DncZeus.App/src/components/common-icon/common-icon.vue b/DncZeus.App/src/components/common-icon/common-icon.vue index 768fa1b..c1ee813 100644 --- a/DncZeus.App/src/components/common-icon/common-icon.vue +++ b/DncZeus.App/src/components/common-icon/common-icon.vue @@ -10,14 +10,23 @@ export default { props: { type: { type: String, - required: true + required: true, + default () { + return "Icon" + } }, color: String, size: Number }, computed: { iconType () { - return this.type.indexOf('_') === 0 ? 'Icons' : 'Icon' + if(this.type) + { + return this.type.indexOf('_') === 0 ? 'Icons' : 'Icon' + } + else{ + return "Icon" + } }, iconName () { return this.iconType === 'Icons' ? this.getCustomIconName(this.type) : this.type diff --git a/DncZeus.App/src/components/main/components/user/user.vue b/DncZeus.App/src/components/main/components/user/user.vue index b607f0e..4385a0f 100644 --- a/DncZeus.App/src/components/main/components/user/user.vue +++ b/DncZeus.App/src/components/main/components/user/user.vue @@ -36,11 +36,25 @@ export default { 'handleLogOut' ]), logout () { - this.handleLogOut().then(() => { - this.$router.push({ - name: 'login' - }) - }) + var $this = this; + this.$Modal.confirm({ + title:"退出确认", + content:"确定要退出系统吗?", + okText:"确定退出", + cancelText:"再想想", + loading:true, + onOk(){ + + setTimeout(function(){ + $this.handleLogOut().then(() => { + $this.$Modal.remove(); + $this.$router.push({ + name: 'login' + }) + }) + },1500); + } + }); }, message () { this.$router.push({ diff --git a/DncZeus.App/src/components/main/main.vue b/DncZeus.App/src/components/main/main.vue index 09ad64f..d8bfbb2 100644 --- a/DncZeus.App/src/components/main/main.vue +++ b/DncZeus.App/src/components/main/main.vue @@ -94,7 +94,7 @@ export default { }, data() { return { - collapsed: true, + collapsed: false, minLogo, maxLogo, isFullscreen: false @@ -122,7 +122,8 @@ export default { ]; }, menuList() { - return this.$store.getters.menuList; + let menus = this.$store.getters.menuList; + return menus; }, local() { return this.$store.state.app.local; diff --git a/DncZeus.App/src/libs/router-util.js b/DncZeus.App/src/libs/router-util.js new file mode 100644 index 0000000..097ba8f --- /dev/null +++ b/DncZeus.App/src/libs/router-util.js @@ -0,0 +1,75 @@ +import { getToken, hasChild, localSave, localRead } from '@/libs/util' +import Main from '@/components/main' +// import axios from 'axios' +import axios from '@/libs/api.request' +import config from '@/config' +import { forEach } from '@/libs/tools' +const baseUrl = process.env.NODE_ENV === 'development' ? config.baseUrl.dev : config.baseUrl.pro + +// 初始化路由 +export const initRouter = (vm) => { + // if (!getToken()) { + // return + // } + let list = [] + // 模拟异步请求,改为您实际的后端请求路径 + // axios.get(baseUrl + 'system/permission/userMenuList', { + // headers: { 'Authorization': 'Bearer ' + getToken() } + // }) + + axios.request({ + url: 'account/menu', + method: 'get' + }).then(res => { + var menuData = res.data + // 格式化菜单 + list = formatMenu(menuData) + // 刷新界面菜单 + //vm.$store.commit('setMenuList', list) + vm.$store.commit('refreshMenuList', list) + }); + + return list +} + +// 加载菜单,在创建路由时使用 +export const loadMenu = () => { + let list = [] + axios.request({ + url: 'account/menu', + method: 'get' + }).then(res => { + var menuData = res.data + // 这是后端回传给前端的数据,如上面所说的 + // 格式化菜单 + list = formatMenu(menuData) + }); + + return list +} + +// 格式化菜单 +export const formatMenu = (list) => { + let res = [] + forEach(list, item => { + let obj = { + path: item.path, + name: item.name + } + obj.meta = item.meta + // 惰性递归 **** + if (item.parentId === "0") { + obj.component = Main + } else { + // 惰性递归 **** + let data = item.component + // 这里需要改成自己定义的 .vue 夜间路径 + obj.component = () => import('@/view' + data) + } + if (hasChild(item)) { + obj.children = formatMenu(item.children) + } + res.push(obj) + }) + return res +} diff --git a/DncZeus.App/src/libs/util.js b/DncZeus.App/src/libs/util.js index 9e8b077..d2a42be 100644 --- a/DncZeus.App/src/libs/util.js +++ b/DncZeus.App/src/libs/util.js @@ -62,12 +62,64 @@ export const getMenuByRouter = (list, access, pages) => { return res } +/** + * @param {Array} routes 通过路由列表得到菜单列表 + * @returns {Array} + */ +export const getMenuListByRoutes = (routes) => { + let res = [] + // res = [ + // { + // icon: "md-contacts", + // name: "rbac", + // meta: { + // hideInMenu: false, + // title:"用户权限管理" + // }, + // children: [ + // { + // icon: "md-contacts", + // name: "rbac_user_page", + // meta: { + // hideInMenu: false, + // title:"用户管理" + // } + // }, + // { + // icon: "md-contacts", + // name: "rbac_role_page", + // meta: { + // hideInMenu: false, + // title:"权限管理" + // } + // } + // ] + // }]; + // return res; + forEach(routes, item => { + if (!item.meta || (item.meta && !item.meta.hideInMenu)) { + let obj = { + icon: (item.meta && item.meta.icon) || '', + name: item.name, + meta: item.meta + } + if ((hasChild(item) || (item.meta && item.meta.showAlways))) { + obj.children = getMenuListByRoutes(item.children) + } + if (item.meta && item.meta.href) obj.href = item.meta.href + res.push(obj); + } + }) + return res +} + /** * @param {Array} routeMetched 当前路由metched * @returns {Array} */ export const getBreadCrumbList = (route, homeRoute) => { - let homeItem = { ...homeRoute, + let homeItem = { + ...homeRoute, icon: homeRoute.meta.icon } let routeMetched = route.matched @@ -75,7 +127,8 @@ export const getBreadCrumbList = (route, homeRoute) => { let res = routeMetched.filter(item => { return item.meta === undefined || !item.meta.hideInBread }).map(item => { - let meta = { ...item.meta + let meta = { + ...item.meta } if (meta.title && typeof meta.title === 'function') { meta.__titleIsFunction__ = true @@ -91,15 +144,18 @@ export const getBreadCrumbList = (route, homeRoute) => { res = res.filter(item => { return !item.meta.hideInMenu }) - return [{ ...homeItem, + return [{ + ...homeItem, to: homeRoute.path }, ...res] } export const getRouteTitleHandled = (route) => { - let router = { ...route + let router = { + ...route } - let meta = { ...route.meta + let meta = { + ...route.meta } let title = '' if (meta.title) { @@ -428,3 +484,11 @@ export const setTitle = (routeItem, vm) => { const resTitle = pageTitle ? `${title} - ${pageTitle}` : title window.document.title = resTitle } + + +export const getTagNavByRouteName = (routeName) => { + let tagNavList = getTagNavListFromLocalstorage(); + let temp = tagNavList.filter((x) => x.name === routeName); + let tagNav = (temp && temp.length > 0) ? temp[0] : null; + return tagNav; +} diff --git a/DncZeus.App/src/main.js b/DncZeus.App/src/main.js index 76078c2..f7ffa1e 100644 --- a/DncZeus.App/src/main.js +++ b/DncZeus.App/src/main.js @@ -14,6 +14,10 @@ import 'iview/dist/styles/iview.css' import './index.less' import '@/assets/icons/iconfont.css' import TreeTable from 'tree-table-vue' + +import { initRouter } from '@/libs/router-util' + + // 实际打包时应该不引入mock /* eslint-disable */ // if (process.env.NODE_ENV !== 'production') require('@/mock') @@ -48,5 +52,16 @@ new Vue({ router, i18n, store, + created(){ + + }, + mounted() { + var target = this; + //initRouter(target); + // 调用方法,动态生成路由 + setTimeout(function(){ + //initRouter(target); + },1500); + }, render: h => h(App) }) diff --git a/DncZeus.App/src/router/index.js b/DncZeus.App/src/router/index.js index 4bf3990..9b8ff41 100644 --- a/DncZeus.App/src/router/index.js +++ b/DncZeus.App/src/router/index.js @@ -13,23 +13,44 @@ import { getUnion } from '@/libs/tools' import staticRouters from '@/router/static-routers' +import axios from '@/libs/api.request' import config from "@/config"; +// 引入加载菜单 +import { formatMenu, loadMenu } from '@/libs/router-util' + const { homeName } = config; const baseUrl = process.env.NODE_ENV === "development" ? - config.baseUrl.dev : - config.baseUrl.pro; + config.baseUrl.dev : + config.baseUrl.pro; Vue.use(Router); const router = new Router({ - routes, + routes: [...routes], // , ...loadMenu() mode: "history" }); const LOGIN_PAGE_NAME = "login"; -const turnTo = (to, pages, checkPermission, permissions, next) => { +const initRouter = () => { + let list = [] + axios.request({ + url: 'account/menu', + method: 'get' + }).then(res => { + var menuData = res.data + // 格式化菜单 + list = formatMenu(menuData) + // 刷新界面菜单 + store.dispatch('refreshMenuList', list) + + }); + + return list +} + +const turnTo = (to, checkPermission, permissions, next) => { // if (canTurnTo(to.name, access, routes)) next(); // // 有权限,可访问 // else @@ -39,22 +60,22 @@ const turnTo = (to, pages, checkPermission, permissions, next) => { // }); // 无权限,重定向到401页面 // 有权限,可访问 - if (pages.includes(to.name)) { - to.meta.checkPermission = checkPermission; - permissions = permissions || []; - if (permissions && permissions[to.name]) { - to.meta.permissions = permissions[to.name]; - } - next(); - } else { - next({ - replace: true, - name: "error_401" - }); // 无权限,重定向到401页面 + to.meta.checkPermission = checkPermission; + permissions = permissions || []; + if (permissions && permissions[to.name]) { + to.meta.permissions = permissions[to.name]; } + next(); }; router.beforeEach((to, from, next) => { + if (!to.matched || to.matched.length <= 0) { + if (store.state.user.hasGetInfo) { + store.dispatch("closeTag", to.name); + next({ path: "/404", replace: true }); + } + } + iView.LoadingBar.start(); const token = getToken(); if (!token && to.name !== LOGIN_PAGE_NAME) { @@ -74,12 +95,15 @@ router.beforeEach((to, from, next) => { let checkPermission = true; if (store.state.user.hasGetInfo) { checkPermission = store.state.user.user_type != 0; - turnTo(to, store.state.user.pages, checkPermission, store.state.user.permissions, next) + next() + turnTo(to, checkPermission, store.state.user.permissions, next) } else { store.dispatch('getUserInfo').then(user => { // 拉取用户信息,通过用户权限和跳转的页面的name来判断是否有权限访问;access必须是一个数组,如:['super_admin'] checkPermission = user.user_type != 0; - turnTo(to, getUnion(user.pages, staticRouters), checkPermission, user.permissions, next) + initRouter(); + next() + turnTo(to, checkPermission, user.permissions, next) }).catch(() => { setToken('') next({ @@ -97,3 +121,13 @@ router.afterEach(to => { }); export default router; + +const createRouter = () => new Router({ + mode: 'history', + routes: [...routes] +}) + +export function resetRouter() { + const newRouter = createRouter() + router.matcher = newRouter.matcher +} diff --git a/DncZeus.App/src/router/routers.js b/DncZeus.App/src/router/routers.js index 0088e81..142b358 100644 --- a/DncZeus.App/src/router/routers.js +++ b/DncZeus.App/src/router/routers.js @@ -16,7 +16,7 @@ import Main from '@/components/main' * } */ -export default [{ +export const mainRouter = [{ path: '/login', name: 'login', meta: { @@ -46,41 +46,6 @@ export default [{ component: () => import('@/view/single-page/home') }] }, - { - path: '/join', - name: 'join', - component: Main, - meta: { - hideInBread: true - }, - children: [{ - path: 'join_page', - name: 'join_page', - meta: { - icon: '_qq', - title: 'QQ群' - }, - component: () => import('@/view/join-page.vue') - }] - }, - { - path: '/demo', - name: 'demo', - component: Main, - meta: { - icon:"logo-buffer", - title:"示例菜单" - }, - children: [{ - path: 'demo-page', - name: 'demo_page', - meta: { - title: '示例页面', - icon: 'md-home' - }, - component: () => import('@/view/demo/demo-page') - }] - }, { path: '/message', name: 'message', @@ -99,82 +64,6 @@ export default [{ component: () => import('@/view/single-page/message/index.vue') }] }, - { - path: '/rbac', - name: 'rbac', - meta: { - icon: 'logo-buffer', - title: '用户及授权' - }, - component: Main, - children: [{ - path: 'user', - name: 'rbac_user_page', - meta: { - icon: 'md-contact', - title: '用户管理' - }, - component: () => import( /* webpackChunkName: "rbac" */ '@/view/rbac/user.vue') - }, { - path: 'role', - name: 'rbac_role_page', - meta: { - icon: 'md-contacts', - title: '角色管理' - }, - component: () => import( /* webpackChunkName: "rbac" */ '@/view/rbac/role.vue') - }, { - path: 'permission', - name: 'rbac_permission_page', - meta: { - icon: 'md-contacts', - title: '权限管理' - }, - component: () => import( /* webpackChunkName: "rbac" */ '@/view/rbac/permission.vue') - }, { - path: 'menu', - name: 'rbac_menu_page', - meta: { - icon: 'md-menu', - title: '菜单管理' - }, - component: () => import( /* webpackChunkName: "rbac" */ '@/view/rbac/menu.vue') - }, { - path: 'icon', - name: 'rbac_icon_page', - meta: { - icon: 'md-aperture', - title: '图标管理' - }, - component: () => import( /* webpackChunkName: "rbac" */ '@/view/rbac/icon.vue') - }, { - path: 'role-permission', - name: 'rbac_role_permission_page', - meta: { - icon: 'md-aperture', - title: '角色权限分配' - }, - component: () => import( /* webpackChunkName: "rbac" */ '@/view/rbac/role-permission.vue') - }] - }, - { - path: '/tools_methods', - name: 'tools_methods', - meta: { - hideInBread: true - }, - component: Main, - children: [{ - path: 'tools_methods_page', - name: 'tools_methods_page', - meta: { - icon: 'ios-hammer', - title: '工具方法', - beforeCloseName: 'before_close_normal' - }, - component: () => import('@/view/tools-methods/tools-methods.vue') - }] - }, { path: '/error_store', name: 'error_store', @@ -257,7 +146,7 @@ export default [{ component: () => import('@/view/error-page/500.vue') }, { - path: '*', + path: '/404', name: 'error_404', meta: { hideInMenu: true @@ -265,3 +154,10 @@ export default [{ component: () => import('@/view/error-page/404.vue') } ] + +export const appRouter = [] + +export default [ + ...mainRouter, + ...appRouter +] diff --git a/DncZeus.App/src/store/module/app.js b/DncZeus.App/src/store/module/app.js index 45e7138..af938f5 100644 --- a/DncZeus.App/src/store/module/app.js +++ b/DncZeus.App/src/store/module/app.js @@ -9,14 +9,16 @@ import { routeEqual, getRouteTitleHandled, localSave, - localRead + localRead, + getMenuListByRoutes, + getTagNavByRouteName } from '@/libs/util' import beforeClose from '@/router/before-close' import { saveErrorLogger } from '@/api/data' import router from '@/router' -import routers from '@/router/routers' +import {resetRouter} from '@/router' import config from '@/config' const { homeName @@ -27,6 +29,7 @@ const closePage = (state, route) => { state.tagNavList = state.tagNavList.filter(item => { return !routeEqual(item, route) }) + setTagNavListInLocalstorage(state.tagNavList); router.push(nextRoute) } @@ -37,13 +40,18 @@ export default { homeRoute: {}, local: localRead('local'), errorList: [], - hasReadErrorPage: false + hasReadErrorPage: false, + // 定义菜单变量 + menuList: [] }, getters: { - menuList: (state, getters, rootState) => { - return getMenuByRouter(routers, rootState.user.access, rootState.user.pages); - }, - errorCount: state => state.errorList.length + // menuList: (state, getters, rootState) => { + // return getMenuByRouter(routers, rootState.user.access, rootState.user.pages); + // }, + errorCount: state => state.errorList.length, + menuList: state => state.menuList + // 通过路由列表得到菜单列表 + //menuList: (state, getters, rootState) => getMenuListByRoutes(routes) }, mutations: { setBreadCrumb(state, route) { @@ -103,6 +111,18 @@ export default { }, setHasReadErrorLoggerStatus(state, status = true) { state.hasReadErrorPage = status + }, + setMenuList(state, routes) { + state.menuList = getMenuListByRoutes(routes); + }, + // 接受前台数组,刷新菜单 + refreshMenuList(state, routes) { + resetRouter(); + router.addRoutes(routes.concat([{ + path: '*', + redirect: '/404' + }]), { replace: true }) + state.menuList = routes } }, actions: { @@ -128,6 +148,21 @@ export default { saveErrorLogger(info).then(() => { commit('addError', data) }) + }, + refreshMenuList({ state, commit }, list) { + return new Promise((resolve, reject) => { + try { + commit("setMenuList", list) + commit("refreshMenuList", list) + resolve() + + } catch (error) { + reject(error) + } + }) + }, + closeTag({ state, commit }, routeName) { + commit("closeTag", { name: routeName }) } } } diff --git a/DncZeus.App/src/store/module/user.js b/DncZeus.App/src/store/module/user.js index 7941bd4..e7334b6 100644 --- a/DncZeus.App/src/store/module/user.js +++ b/DncZeus.App/src/store/module/user.js @@ -12,7 +12,7 @@ import { import { setToken, getToken, - setTagNavListInLocalstorage, + setTagNavListInLocalstorage } from '@/libs/util' import { getUnion @@ -33,7 +33,6 @@ export default { messageReadedList: [], messageTrashList: [], messageContentStore: {}, - pages: [], permissions: {}, profile: {} }, @@ -55,7 +54,7 @@ export default { }, //设置用户可以访问的页面编码列表 setPages(state, pages) { - state.pages = pages; + //state.pages = pages; }, //设置用户可以访问页面的权限集合 setPermissions(state, permissions) { @@ -149,10 +148,11 @@ export default { // 如果你的退出登录无需请求接口,则可以直接使用下面三行代码而无需使用logout调用接口 commit('setToken', '') commit('setAccess', []) - commit('setPages', []) + //commit('setPages', []) commit('setPermissions', {}) setTagNavListInLocalstorage([]); resolve() + //location.reload(); }) }, // 获取用户相关信息 @@ -168,7 +168,7 @@ export default { commit('setUserName', data.user_name) commit('setUserGuid', data.user_guid) commit('setAccess', data.access) - commit('setPages', getUnion(data.pages, staticRouters)) + //commit('setPages', getUnion(data.pages, staticRouters)) commit('setPermissions', data.permissions) commit("setUserType", data.user_type); commit('setHasGetInfo', true) diff --git a/DncZeus.App/src/view/login/login.vue b/DncZeus.App/src/view/login/login.vue index 2de7049..9cf5ea6 100644 --- a/DncZeus.App/src/view/login/login.vue +++ b/DncZeus.App/src/view/login/login.vue @@ -26,11 +26,15 @@