完善头像中

This commit is contained in:
lzw
2021-11-02 00:25:23 +08:00
parent eaf64f0873
commit 4349582c69
9 changed files with 355 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
@@ -40,6 +41,10 @@ namespace Yi.Framework.ApiMicroservice.Controllers
public async Task<Result> Login(user _user)
{
var user_data = await _userService.Login(_user);
if (user_data == null)
{
return Result.Error("该用户不存在");
}
var menuList = await _menuService.GetTopMenuByUserId(user_data.id);
if ( user_data!=null)
{
@@ -152,6 +157,16 @@ namespace Yi.Framework.ApiMicroservice.Controllers
return Result.Success(msg);
}
[HttpGet]
public async Task<Result> EditIcon(int userId,IFormFile file)
{
var user_data = await _userService.GetUserById(userId);
var fileController = new FileController();
var type = Common.Const.FileConst.Image;
var filename= fileController.Upload(type,file);
user_data.icon = filename.ToString();
await _userService.UpdateAsync(user_data);
return Result.Success();
}
}
}

View File

@@ -0,0 +1,67 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting;
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]")]
[ApiController]
public class FileController : ControllerBase
{
private IUserService _userService;
private readonly IHostEnvironment _env;
public FileController(IUserService userService, IHostEnvironment env)
{
_userService = userService;
_env = env;
}
public FileController()
{
}
[HttpGet]
[Route("{type}/{imageNmae}")]
public IActionResult Get(string type, string imageNmae)
{
var path = Path.Combine(@"wwwroot/file", imageNmae);
var stream = System.IO.File.OpenRead(path);
var MimeType = Common.Helper.MimeMapping.GetMimeMapping(imageNmae);
return new FileStreamResult(stream, MimeType);
}
[HttpPost]
[Route("{type}/{imageNmae}")]
public async Task<Result> Upload(string type,IFormFile file)
{
if (type != Common.Const.FileConst.Image) { return Result.Error(); }
string filename = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);
string filepath = Path.Combine(@"wwwroot/image", filename);
using (var stream = new FileStream(Path.Combine(_env.ContentRootPath, filepath), FileMode.CreateNew, FileAccess.Write))
{
await file.CopyToAsync(stream);
}
return Result.Success().SetData(filename);
}
[HttpGet]
public async Task<IActionResult> GetFile()
{
var userdata = await _userService.GetAllEntitiesTrueAsync();
var userList = userdata.ToList();
Dictionary<string, string> dt = new();
dt.Add("sc", "user");
var bt = Excel.ExportExcel(userList, dt);
MemoryStream ms = new(bt);
return new FileStreamResult(ms, "application/vnd.ms-excel");
}
}
}

View File

@@ -107,13 +107,13 @@ namespace Yi.Framework.ApiMicroservice.Controllers
/// <summary>
/// 用于给角色设置菜单的时候,点击一个角色,显示这个角色拥有的并列的菜单
/// </summary>
/// <param name="role"></param>
/// <param name="roleId"></param>
/// <returns></returns>
[HttpGet]
public async Task<Result> GetTopMenusByRoleId(role role)
public async Task<Result> GetTopMenusByRoleId(int roleId)
{
return Result.Success().SetData(await _roleService.GetTopMenusByRoleId(role.id) ); ;
return Result.Success().SetData(await _roleService.GetTopMenusByRoleId(roleId) ); ;
}
}
}

View File

@@ -120,7 +120,12 @@ namespace Yi.Framework.ApiMicroservice.Controllers
[HttpGet]
public async Task<Result> GetAxiosByRouter(string router)
{
var _user = HttpContext.GetCurrentUserInfo(out List<int> menuIds);
if (menuIds == null)
{
return Result.Error();
}
var menuList= await _userService.GetAxiosByRouter(router, _user.id, menuIds);
AxiosUrlsModel urlsModel = new();
menuList.ForEach(u =>