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 c254745d..8aab07be 100644
Binary files a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db differ
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 @@
-
+
@@ -175,7 +175,7 @@
-
+
@@ -188,7 +188,7 @@
-
+
@@ -214,7 +214,7 @@
-
+
@@ -227,7 +227,7 @@
-
+
@@ -243,7 +243,7 @@
-
+
@@ -262,7 +262,7 @@
-
+