From b59a1522244d4c1df2cbeb6c7f692b1c04d3674b Mon Sep 17 00:00:00 2001 From: lzw <605106923@qq.com> Date: Mon, 1 Nov 2021 22:00:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=99=BB=E5=BD=95bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/AccountController.cs | 15 ++++-- .../Controllers/FileController.cs | 49 +++++++++++++++++++ .../Controllers/RoleController.cs | 23 ++------- .../Controllers/UserController.cs | 19 +++++-- .../Yi.Framework.ApiMicroservice.csproj | 5 ++ Yi.Framework/Yi.Framework.Core/MakeJwt.cs | 18 +++---- Yi.Vue/src/views/login.vue | 4 +- 7 files changed, 96 insertions(+), 37 deletions(-) create mode 100644 Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/FileController.cs diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs index b2ca8438..f2a45efe 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs @@ -40,10 +40,11 @@ namespace Yi.Framework.ApiMicroservice.Controllers public async Task Login(user _user) { var user_data = await _userService.Login(_user); - var menuList = await _menuService.GetTopMenuByUserId(user_data.id); + //var menuList = await _menuService.GetTopMenuByUserId(user_data.id); + if ( user_data!=null) - { - var token = MakeJwt.app(new jwtUser() {user=user_data,menuIds= menuList}); + { + var token = MakeJwt.app(new jwtUser() {user=user_data}); return Result.Success().SetData(new { user = new { _user.id, _user.username, _user.introduction, _user.icon, _user.nick }, token }); } return Result.Error(); @@ -148,10 +149,16 @@ namespace Yi.Framework.ApiMicroservice.Controllers user_data.nick = pwdDto.user.nick; await _userService.UpdateAsync(user_data); - + return Result.Success(msg); } + [HttpPost] + public async Task UpdataIcon() + { + return Result.Success(); + + } } } \ No newline at end of file diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/FileController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/FileController.cs new file mode 100644 index 00000000..33df3c66 --- /dev/null +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/FileController.cs @@ -0,0 +1,49 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Yi.Framework.Common.Models; +using Yi.Framework.Interface; +using Yi.Framework.WebCore; + +namespace Yi.Framework.ApiMicroservice.Controllers +{ + + [Route("api/[controller]/[action]")] + public class FileController : Controller + { + private IUserService _userService; + public FileController(IUserService userService) + { + _userService = userService; + } + //[HttpGet] + //[Route("{type}/{imageNmae}")] + //public IActionResult Get(string type, string imageNmae) + //{ + // return new FileStreamResult(); + //} + + //[HttpPost] + //[Route("{type}/{imageNmae}")] + //public IActionResult Upload(string type,List files ) + //{ + // HttpContext.Request[""]; + // return new FileStreamResult(); + //} + [HttpGet] + public async Task GetFile() + { + var userdata = await _userService.GetAllEntitiesTrueAsync(); + var userList = userdata.ToList(); + Dictionary dt = new (); + dt.Add("sc", "user"); + var bt = Excel.ExportExcel(userList, dt); + MemoryStream ms = new(bt); + return new FileStreamResult(ms, "application/vnd.ms-excel"); + } + } +} diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs index c7fb0744..619596a3 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs @@ -28,22 +28,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers public async Task GetRole() { return Result.Success().SetData(await _roleService.GetAllEntitiesTrueAsync()); - } - [HttpPost] - public async Task GetRoleFlie() - { - var roleList = await _roleService.GetAllEntitiesTrueAsync(); - Dictionary dt = new(); - dt.Add("输出", "文件"); - var byteStream = Excel.ExportExcel(roleList.ToList(), dt).ToString(); - MemoryStream s = new MemoryStream(); - StreamWriter writer = new StreamWriter(s); - writer.Write(byteStream); - writer.Flush(); - //stream.Read(byteStream, 0, byteStream.Length); - return new FileStreamResult(s, "application/vnd.ms-excel"); - } - + } /// /// 更 /// @@ -107,13 +92,13 @@ namespace Yi.Framework.ApiMicroservice.Controllers /// /// 用于给角色设置菜单的时候,点击一个角色,显示这个角色拥有的并列的菜单 /// - /// + /// /// [HttpGet] - public async Task GetTopMenusByRoleId(role role) + public async Task GetTopMenusByRoleId(int roleId) { - return Result.Success().SetData(await _roleService.GetTopMenusByRoleId(role.id) ); ; + return Result.Success().SetData(await _roleService.GetTopMenusByRoleId(roleId) ); ; } } } diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs index f8eb206a..86cbed15 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Controllers/UserController.cs @@ -21,10 +21,12 @@ namespace Yi.Framework.ApiMicroservice.Controllers private readonly ILogger _logger; private IUserService _userService; - public UserController(ILogger logger, IUserService userService) + private IMenuService _menuService; + public UserController(ILogger logger, IUserService userService, IMenuService menuService) { _logger = logger; _userService = userService; + _menuService = menuService; } /// @@ -120,8 +122,19 @@ namespace Yi.Framework.ApiMicroservice.Controllers [HttpGet] public async Task GetAxiosByRouter(string router) { - var _user = HttpContext.GetCurrentUserInfo(out List menuIds); - var menuList= await _userService.GetAxiosByRouter(router, _user.id, menuIds); + var _user = HttpContext.GetCurrentUserInfo(); + var menuList = await _menuService.GetTopMenuByUserId(_user.id); + if (menuList == null) + { + return Result.Error(); + } + List menuIds = new(); + menuList.ForEach(u => + { + var id = u.id; + menuIds.Add(id); + }); + var childrenList = await _userService.GetAxiosByRouter(router, _user.id, menuIds); AxiosUrlsModel urlsModel = new(); menuList.ForEach(u => { diff --git a/Yi.Framework/Yi.Framework.ApiMicroservice/Yi.Framework.ApiMicroservice.csproj b/Yi.Framework/Yi.Framework.ApiMicroservice/Yi.Framework.ApiMicroservice.csproj index b4833ceb..a0bec50e 100644 --- a/Yi.Framework/Yi.Framework.ApiMicroservice/Yi.Framework.ApiMicroservice.csproj +++ b/Yi.Framework/Yi.Framework.ApiMicroservice/Yi.Framework.ApiMicroservice.csproj @@ -24,4 +24,9 @@ + + + + + diff --git a/Yi.Framework/Yi.Framework.Core/MakeJwt.cs b/Yi.Framework/Yi.Framework.Core/MakeJwt.cs index f1ad675c..11e9ad7b 100644 --- a/Yi.Framework/Yi.Framework.Core/MakeJwt.cs +++ b/Yi.Framework/Yi.Framework.Core/MakeJwt.cs @@ -17,7 +17,7 @@ namespace Yi.Framework.Core public class jwtUser { public user user { get; set; } - public List menuIds { get; set; } + //public List menuIds { get; set; } } @@ -37,14 +37,14 @@ namespace Yi.Framework.Core claims.Add(new Claim(JwtRegisteredClaimNames.Exp, $"{new DateTimeOffset(DateTime.Now.AddMinutes(30)).ToUnixTimeSeconds()}")); claims.Add(new Claim(ClaimTypes.Name, _user.user.username)); claims.Add(new Claim(ClaimTypes.Sid, _user.user.id.ToString())); - foreach (var k in _user.menuIds) - { - claims.Add(new Claim("menuIds",k.id.ToString())); - } - foreach (var k in _user.user.roles) - { - claims.Add(new Claim(ClaimTypes.Role, k.role_name)); - } + //foreach (var k in _user.menuIds) + //{ + // claims.Add(new Claim("menuIds",k.id.ToString())); + //} + //foreach (var k in _user.user.roles) + //{ + // claims.Add(new Claim(ClaimTypes.Role, k.role_name)); + //} var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(JwtConst.SecurityKey)); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); diff --git a/Yi.Vue/src/views/login.vue b/Yi.Vue/src/views/login.vue index 30b91141..045caee5 100644 --- a/Yi.Vue/src/views/login.vue +++ b/Yi.Vue/src/views/login.vue @@ -112,8 +112,8 @@ export default { isPasswordVisible: false, form: { - username: "", - password: "", + username: "admin", + password: "123", }, }), methods: {