From 7c255f383a7e5055b2e25c9cdb2abfe9b45daad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Wed, 27 Oct 2021 18:01:09 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E6=8E=A7=E5=88=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/MenuController.cs | 43 ++++-------- .../Controllers/RoleController.cs | 12 ++-- .../Controllers/UserController.cs | 69 +++++-------------- .../Yi.Framework.Service/UserService.cs | 2 +- Yi.Vue/src/api/menuApi.js | 4 +- Yi.Vue/src/api/userApi.js | 14 ++-- 6 files changed, 48 insertions(+), 96 deletions(-) diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs index 8d464936..c377a2f7 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs @@ -25,11 +25,13 @@ namespace Yi.Framework.ApiMicroservice.Controllers _menuService = menuService; _userService =userService; } + /// + /// 这个是要递归的,但是要过滤掉删除的,所以,可以写一个通用过滤掉删除的方法 + /// + /// [HttpGet] - public async Task GetMenu() - { - - return Result.Success().SetData(await _menuService.GetTopMenu()); + public async Task GetMenuInMould() + { } /// @@ -59,44 +61,26 @@ namespace Yi.Framework.ApiMicroservice.Controllers /// /// 增 + /// 现在,top菜单只允许为一个 /// /// /// [HttpPost] - public async Task AddMenu(menu _menu) + public async Task AddTopMenu(menu _menu) { - _menu.is_top = (short)Common.Enum.TopFlagEnum.Top; - await _menuService.AddAsync(_menu); - return Result.Success(); } /// /// 给一个菜单设置一个接口,Id1为菜单id,Id2为接口id + /// 用于给菜单设置接口 /// /// /// [HttpPost] public async Task SetMouldByMenu(IdDto idDto) { - if (await _menuService.SetMouldByMenu(idDto.id2,idDto.id1)) - { - return Result.Success(); - } - return Result.Error(); } - /// - /// 得到该用户有哪些菜单,关联mould - /// - /// - [HttpGet] - public async Task GetMenuByUser() - { - var _user = this.HttpContext.GetCurrentUserInfo(); - var menuList= await _userService.GetMenusByUser(_user); - return Result.Success().SetData(menuList); - - } /// /// 给一个菜单添加子节点(注意:添加,不是覆盖) @@ -106,19 +90,16 @@ namespace Yi.Framework.ApiMicroservice.Controllers [HttpPost] public async Task AddChildrenMenu(ChildrenDto childrenDto) { - await _menuService.AddChildrenMenu(childrenDto.parentId, childrenDto.data); - return Result.Success(); } + /// /// 获取用户的目录菜单,不包含接口 + /// 用于账户信息页面,显示这个用户有哪些菜单,需要并列 /// /// [HttpGet] - public async Task GeTopMenuByUser() + public async Task GetTopMenusByHttpUser() { - var _user = this.HttpContext.GetCurrentUserInfo(); - var menuList =await _userService.GetMenuByUser(_user); - return Result.Success().SetData(menuList); } } } diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs index d912f097..a32de49f 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs @@ -67,20 +67,22 @@ namespace Yi.Framework.ApiMicroservice.Controllers /// /// 给角色设置菜单,多个角色与多个菜单,让每一个角色都设置,ids1为角色,ids2为菜单 + /// 用于设置角色 /// /// /// [HttpPost] public async Task SetMenuByRole(IdsListDto idsListDto) { - await _roleService.SetMenusByRolesId(idsListDto.ids2, idsListDto.ids1); - return Result.Success(); } + /// + /// 用于给角色设置菜单的时候,点击一个角色,显示这个角色拥有的并列的菜单 + /// + /// + /// [HttpGet] - public async Task GetMenuByRloe(int roleId) + public async Task GetTopMenusByRoleId(int roleId) { - var menuList =await _roleService.GetMenusByRoleId(roleId); - return Result.Success().SetData(menuList); } } } diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs index 383151cf..0ac1b921 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs @@ -74,86 +74,55 @@ namespace Yi.Framework.ApiMicroservice.Controllers return Result.Success(); } - /// - /// 通过上下文对象获取user(注意,_user下只有userId),返回值为该用户下所有的menu,(注意子类递归)并且需要关联mould - /// - /// - [HttpPost] - public async Task GetMenuMould() - { - var _user= this.HttpContext.GetCurrentUserInfo(); - var menu_data = await _userService.GetMenusByUser(_user); - return Result.Success().SetData(menu_data); - } /// /// 给多个用户设置多个角色,ids有用户id与 角色列表ids,多对多,ids1用户,ids2为角色 + /// 用户设置给用户设置角色 /// /// /// [HttpPost] public async Task SetRoleByUser(IdsListDto idsListDto) { - - await _userService.SetRolesByUser(idsListDto.ids2, idsListDto.ids1); - return Result.Success(); - } - /// - /// 根据http上下文的用户得到该用户有哪些角色 - /// - /// - [HttpGet] - public async Task GetRolesByUser() - { - var _user = HttpContext.GetCurrentUserInfo(); - var roleList = await _userService.GetRolesByUser(_user); - return Result.Success().SetData(roleList); } + /// /// 根据用户id得到该用户有哪些角色 + /// 用于显示用户详情中的角色说明 /// /// [HttpGet] public async Task GetRolesByUserId(int userId) { - var roleList = await _userService.GetRolesByUser(new user() { id=userId}); - return Result.Success().SetData(roleList); } /// /// 根据http上下文的用户得到该用户信息,关联角色 + /// 用于显示账号信息页中的用户信息和角色信息 /// /// - [HttpGet] - public async Task GetUserInfoById() + public async Task GetUserInRolesByHttpUser() { - var _user = HttpContext.GetCurrentUserInfo(); - return Result.Success().SetData(await _userService.GetUserInfoById(_user.id)); } + + /// + /// 得到登录用户的递归菜单,放到导航栏 + /// 用户放到导航栏中 + /// + /// [HttpGet] - public async Task GetMenuByUserId() + public async Task GetMenuByHttpUser() { - var _user = HttpContext.GetCurrentUserInfo(); - return Result.Success().SetData(await _userService.GetMenuById(_user.id)); } + + /// + /// 得到请求模型 + /// + /// + /// [HttpGet] - public async Task GetRouterByUserId(string router) + public async Task GetAxiosByRouter(string router) { - var _user = HttpContext.GetCurrentUserInfo(out List menuIds); - var menu_data = await _userService.GetMenuByUserId(router,_user.id, menuIds); - AxiosUrlsModel urlsModel = new(); - foreach (var _menu in menu_data) - { - var mould_name = _menu.mould.mould_name; - switch (mould_name) - { - case "get":urlsModel.get= _menu.mould.url;break; - case "add": urlsModel.add = _menu.mould.url; break; - case "del": urlsModel.del = _menu.mould.url; break; - case "update": urlsModel.update = _menu.mould.url; break; - } - } - return Result.Success().SetData(urlsModel); } } diff --git a/Yi.Framework/Yi.Framework.Service/UserService.cs b/Yi.Framework/Yi.Framework.Service/UserService.cs index d6975c47..d370044b 100644 --- a/Yi.Framework/Yi.Framework.Service/UserService.cs +++ b/Yi.Framework/Yi.Framework.Service/UserService.cs @@ -221,7 +221,7 @@ namespace Yi.Framework.Service { if (menu_data[i].children.Count() == 0) { - menu_data[i].children = null; + menu_data[i].children = null;f } else if (menu_data[i].children != null) { diff --git a/Yi.Vue/src/api/menuApi.js b/Yi.Vue/src/api/menuApi.js index 6143cfbd..3833fd1c 100644 --- a/Yi.Vue/src/api/menuApi.js +++ b/Yi.Vue/src/api/menuApi.js @@ -41,9 +41,9 @@ export default { data: { id1: menuId, id2: mouldId } }) }, - geTopMenuByUser() { + GetTopMenusByHttpUser() { return myaxios({ - url: '/Menu/geTopMenuByUser', + url: '/Menu/GetTopMenusByHttpUser', method: 'get' }) } diff --git a/Yi.Vue/src/api/userApi.js b/Yi.Vue/src/api/userApi.js index 9c1bd8d7..98b22715 100644 --- a/Yi.Vue/src/api/userApi.js +++ b/Yi.Vue/src/api/userApi.js @@ -8,9 +8,9 @@ export default { }) }, - GetRolesByUser() { + GetRolesByHttpUser() { return myaxios({ - url: '/User/GetRolesByUser', + url: '/User/GetRolesByHttpUser', method: 'get' }) }, @@ -20,19 +20,19 @@ export default { method: 'get' }) }, - GetUserInfoById() { + GetUserInRolesByHttpUser() { return myaxios({ - url: `/User/GetUserInfoById`, + url: `/User/GetUserInRolesByHttpUser`, method: 'get' }) }, - GetMenuByUserId() { + GetMenuByHttpUser() { return myaxios({ - url: `/User/GetMenuByUserId`, + url: `/User/GetMenuByHttpUser`, method: 'get' }) }, - GetRouterByUserId(router) { + GetAxiosByRouter(router) { return myaxios({ url: `/User/GetRouterByUserId?router=${router}`, method: 'get'