From d4c55620f18c65c0416e45a901de0a277b3c67e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B7=B3?= Date: Fri, 9 Sep 2022 19:22:14 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8F=9C=E5=8D=95=E5=88=B0=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Config/SwaggerDoc.xml | 8 ++- .../Controllers/AccountController.cs | 29 +++++++-- .../Controllers/MenuController.cs | 4 +- .../yi-sqlsugar-dev.db | Bin 118784 -> 118784 bytes .../Models/VueRouterModel.cs | 2 +- .../Yi.Framework.Interface/IUserService.cs | 7 +++ .../Yi.Framework.Service/UserService.cs | 58 +++++++++++++++--- .../src/views/system/menu/index.vue | 14 ++--- 8 files changed, 97 insertions(+), 25 deletions(-) diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml index 0861a9b6..78efbe24 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml @@ -31,7 +31,13 @@ - 通过已登录的用户获取用户信息及菜单 + 通过已登录的用户获取用户信息 + + + + + + 获取当前登录用户的前端路由 diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs index d02188a3..e6eacd32 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Yi.Framework.Common.Enum; using Yi.Framework.Common.Helper; using Yi.Framework.Common.Models; using Yi.Framework.Core; @@ -27,12 +28,12 @@ namespace Yi.Framework.ApiMicroservice.Controllers { private IUserService _iUserService; private JwtInvoker _jwtInvoker; - private ILogger _logger; + private ILogger _logger; public AccountController(ILogger logger, IUserService iUserService, JwtInvoker jwtInvoker) { _iUserService = iUserService; _jwtInvoker = jwtInvoker; - _logger = logger; + _logger = logger; } /// @@ -51,12 +52,14 @@ namespace Yi.Framework.ApiMicroservice.Controllers UserEntity user = new(); if (await _iUserService.Login(loginDto.UserName, loginDto.Password, o => user = o)) { - var userRoleMenu= await _iUserService.GetUserAllInfo(user.Id); - return Result.Success("登录成功!").SetData(new { token = _jwtInvoker.GetAccessToken(userRoleMenu.User,userRoleMenu.Menus) }); + var userRoleMenu = await _iUserService.GetUserAllInfo(user.Id); + return Result.Success("登录成功!").SetData(new { token = _jwtInvoker.GetAccessToken(userRoleMenu.User, userRoleMenu.Menus) }); } return Result.Error("登录失败!用户名或者密码错误!"); } + + /// /// 没啥说,注册 /// @@ -79,13 +82,13 @@ namespace Yi.Framework.ApiMicroservice.Controllers /// /// [HttpPost] - public Result Logout() + public Result Logout() { return Result.Success("安全登出成功!"); } /// - /// 通过已登录的用户获取用户信息及菜单 + /// 通过已登录的用户获取用户信息 /// /// [HttpGet] @@ -99,6 +102,20 @@ namespace Yi.Framework.ApiMicroservice.Controllers return Result.Success().SetData(data); } + /// + /// 获取当前登录用户的前端路由 + /// + /// + [HttpGet] + public async Task GetRouterInfo() + { + var userId = HttpContext.GetCurrentUserEntityInfo(out _).Id; + var data = await _iUserService.GetUserAllInfo(userId); + + //将后端菜单转换成前端路由,组件级别需要过滤 + List routers = _iUserService.RouterBuild(data.Menus.ToList()); + return Result.Success().SetData(routers); + } /// diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs index 119554e9..8d82e8c6 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs @@ -37,9 +37,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers [HttpGet] public async Task GetList([FromQuery] MenuEntity menu) { - var p= await _iMenuService.SelctGetList(menu); - p.ForEach(m => m.Children = new List()); - return Result.Success().SetData(p); + return Result.Success().SetData(await _iMenuService.SelctGetList(menu)); } /// diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db index c254745dbe83a11bc09a9aab825eaf36db00878f..8aab07be1718d3ebb097e10a4c5118f26a20622d 100644 GIT binary patch delta 1264 zcmb7^&1=(O9LJNkOB>hi$)(fL>E=Oi%X^wOcqs0q=%s9+C#UVhjI>Q{(_uwORptv! z-F#sah0Vd72u^THg)va;P5cKucDa?=Sfo5Y)?Y ze}sq-BLsR8dyml(8hwdabL_GhV2IOtYjxhic@(QTmVWSwA?$}QHg7dH z7nZkPF9j;KiU|u^wF1l9#VRb zA3olJ|2}XO;aBc&-G1Z4myJAZr)~W$Z$XnKR*_U$l!X#BN_kkpJ{}uyUG`+i$L^@P z+b*}MKDN`-j*?qDdn#zW$|ht*5>yEv#>)fatqabO2)sSC{r#xfq%*W`IqkJ|dwszL z`)5YxHBn_#yrA%^gmf)5Xs&$lWY8z-WJ9~6H?O1Na79~<<q0&9W(Qap>}6)uavH({f6X%0t%g2eKooKS?^ ze9knc0~?;!($-@fY!9ExJo3<}R(@Msd{*6jxwpP7aDvduNu7ck=Qxc^mbUVkDR7F$ z^Q`I;nio)OhyOf*x>2_u!NbHxe9TuGRj2$d#Gx6OBoC(FyxUt}tu3uppH~KQ#_ZJ@ zGi}am*9?M7GWo-T2gb1^!wfo?_o z?F150FNsj3G&zfV3h8JI;rzYh3lR(s5~$a53ZWoL`biWFGuwR=Iyj=|Qo1LV(;>cK zJarvXJ2^GZCpBKuB#~8AnG+HcWV!EeLvwA&I<{=vv-fakh{-`VZ462KUK5#@r3M4u;nCj%O4|+nxSrUw}-H5aU*y=EsVK-^*b$R#m@*&xZ zCMPr@$#Ohc!K-6)rkR=P0z0fPm74&@jSd&whfp}|NIpcYH^1!z07Xqy*@Ti16%tZB5LJLGrh6AG*$r-|pof8*c(Q@O?xFjf0M3d=UMHv@e}f&^j(T9Nw;2XRTLY>z(fDs$#Y^M; Fwts2!0g(Uz diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Models/VueRouterModel.cs b/Yi.Framework.Net6/Yi.Framework.Common/Models/VueRouterModel.cs index ed1fb350..cfe24942 100644 --- a/Yi.Framework.Net6/Yi.Framework.Common/Models/VueRouterModel.cs +++ b/Yi.Framework.Net6/Yi.Framework.Common/Models/VueRouterModel.cs @@ -27,7 +27,7 @@ namespace Yi.Framework.Common.Models { public string Title { get; set; } public string Icon { get; set; } - public string NoCache { get; set; } + public bool NoCache { get; set; } public string link { get; set; } } } diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/IUserService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/IUserService.cs index 488490e8..887d398a 100644 --- a/Yi.Framework.Net6/Yi.Framework.Interface/IUserService.cs +++ b/Yi.Framework.Net6/Yi.Framework.Interface/IUserService.cs @@ -84,5 +84,12 @@ namespace Yi.Framework.Interface /// /// Task>> SelctPageList(UserEntity user, PageParModel page); + + /// + /// 菜单构建前端路由 + /// + /// + /// + List RouterBuild(List menus); } } diff --git a/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs b/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs index cde1d7aa..4799fc57 100644 --- a/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs +++ b/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using Yi.Framework.Common.Enum; using Yi.Framework.Common.Helper; using Yi.Framework.Common.Models; using Yi.Framework.DTOModel; @@ -129,13 +130,13 @@ namespace Yi.Framework.Service foreach (var menu in role.Menus) { - - if (!string.IsNullOrEmpty(menu.PermissionCode)) - { - userRoleMenu.PermissionCodes.Add(menu.PermissionCode); - userRoleMenu.Menus.Add(menu); - } - + + if (!string.IsNullOrEmpty(menu.PermissionCode)) + { + userRoleMenu.PermissionCodes.Add(menu.PermissionCode); + userRoleMenu.Menus.Add(menu); + } + } } @@ -178,5 +179,48 @@ namespace Yi.Framework.Service return new PageModel>(data, total); } + + + public List RouterBuild(List menus) + { + menus = menus.Where(m => m.MenuType != null && m.MenuType != MenuTypeEnum.Component.GetHashCode()).ToList(); + List routers = new(); + foreach (var m in menus) + { + var r = new VueRouterModel(); + var routerName = m.Router.Split("/").LastOrDefault(); + //开头大写 + r.Name = routerName.First().ToString().ToUpper() + routerName.Substring(1); + r.Path = m.Router; + r.Hidden = (bool)!m.IsShow; + + + if (m.MenuType == MenuTypeEnum.Catalogue.GetHashCode()) + { + r.Redirect = "noRedirect"; + r.AlwaysShow = true; + r.Component = "Layout"; + } + if (m.MenuType == MenuTypeEnum.Menu.GetHashCode()) + { + r.Component = m.Component; + } + + + r.Meta = new Meta + { + Title = m.MenuName, + Icon = m.MenuIcon, + NoCache = (bool)!m.IsCache + }; + if ((bool)m.IsLink) + { + r.Meta.link = m.Router; + } + + routers.Add(r); + } + return routers; + } } } diff --git a/Yi.Vue3.X.RuoYi/src/views/system/menu/index.vue b/Yi.Vue3.X.RuoYi/src/views/system/menu/index.vue index fc2c7220..47de969f 100644 --- a/Yi.Vue3.X.RuoYi/src/views/system/menu/index.vue +++ b/Yi.Vue3.X.RuoYi/src/views/system/menu/index.vue @@ -158,7 +158,7 @@ - +