2021-10-26 15:09:07 +08:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2021-10-13 23:08:42 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Yi.Framework.Common.Models;
|
2021-10-14 13:15:00 +08:00
|
|
|
|
using Yi.Framework.DTOModel;
|
2021-10-13 23:08:42 +08:00
|
|
|
|
using Yi.Framework.Interface;
|
|
|
|
|
|
using Yi.Framework.Model.Models;
|
2021-10-15 17:50:56 +08:00
|
|
|
|
using Yi.Framework.WebCore;
|
2021-10-13 23:08:42 +08:00
|
|
|
|
|
|
|
|
|
|
namespace Yi.Framework.ApiMicroservice.Controllers
|
|
|
|
|
|
{
|
2021-10-14 13:15:00 +08:00
|
|
|
|
[Route("api/[controller]/[action]")]
|
2021-10-13 23:08:42 +08:00
|
|
|
|
[ApiController]
|
2021-10-26 00:59:06 +08:00
|
|
|
|
[Authorize]
|
2021-10-13 23:08:42 +08:00
|
|
|
|
public class MenuController : ControllerBase
|
|
|
|
|
|
{
|
|
|
|
|
|
private IMenuService _menuService;
|
2021-10-15 17:50:56 +08:00
|
|
|
|
private IUserService _userService;
|
|
|
|
|
|
public MenuController(IMenuService menuService, IUserService userService)
|
2021-10-13 23:08:42 +08:00
|
|
|
|
{
|
|
|
|
|
|
_menuService = menuService;
|
2021-10-15 17:50:56 +08:00
|
|
|
|
_userService =userService;
|
2021-10-13 23:08:42 +08:00
|
|
|
|
}
|
2021-10-27 18:01:09 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 这个是要递归的,但是要过滤掉删除的,所以,可以写一个通用过滤掉删除的方法
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
2021-10-13 23:08:42 +08:00
|
|
|
|
[HttpGet]
|
2021-10-27 18:01:09 +08:00
|
|
|
|
public async Task<Result> GetMenuInMould()
|
2021-10-29 23:23:32 +08:00
|
|
|
|
{
|
|
|
|
|
|
return Result.Success().SetData(await _menuService.GetMenuInMould());
|
2021-10-13 23:08:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="_menu"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPut]
|
|
|
|
|
|
public async Task<Result> UpdateMenu(menu _menu)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _menuService.UpdateAsync(_menu);
|
|
|
|
|
|
return Result.Success();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 删
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="_ids"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpDelete]
|
|
|
|
|
|
public async Task<Result> DelListMenu(List<int> _ids)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _menuService.DelListByUpdateAsync(_ids);
|
|
|
|
|
|
return Result.Success();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 增
|
2021-10-27 18:01:09 +08:00
|
|
|
|
/// 现在,top菜单只允许为一个
|
2021-10-13 23:08:42 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="_menu"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
2021-10-27 18:01:09 +08:00
|
|
|
|
public async Task<Result> AddTopMenu(menu _menu)
|
2021-10-13 23:08:42 +08:00
|
|
|
|
{
|
2021-10-29 23:23:32 +08:00
|
|
|
|
await _menuService.AddTopMenu(_menu);
|
|
|
|
|
|
return Result.Success();
|
2021-10-13 23:08:42 +08:00
|
|
|
|
}
|
2021-10-14 13:15:00 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 给一个菜单设置一个接口,Id1为菜单id,Id2为接口id
|
2021-10-27 18:01:09 +08:00
|
|
|
|
/// 用于给菜单设置接口
|
2021-10-14 13:15:00 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="idDto"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
public async Task<Result> SetMouldByMenu(IdDto<int> idDto)
|
2021-10-15 17:50:56 +08:00
|
|
|
|
{
|
2021-10-29 23:23:32 +08:00
|
|
|
|
await _menuService.SetMouldByMenu(idDto.id1, idDto.id2);
|
|
|
|
|
|
return Result.Success();
|
2021-10-15 17:50:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-10-15 20:33:08 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 给一个菜单添加子节点(注意:添加,不是覆盖)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="childrenDto"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
public async Task<Result> AddChildrenMenu(ChildrenDto<menu> childrenDto)
|
2021-10-15 21:50:42 +08:00
|
|
|
|
{
|
2021-10-29 23:23:32 +08:00
|
|
|
|
await _menuService.AddChildrenMenu(childrenDto.parentId, childrenDto.data);
|
|
|
|
|
|
return Result.Success();
|
2021-10-17 17:35:18 +08:00
|
|
|
|
}
|
2021-10-27 18:01:09 +08:00
|
|
|
|
|
2021-10-17 17:35:18 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取用户的目录菜单,不包含接口
|
2021-10-27 18:01:09 +08:00
|
|
|
|
/// 用于账户信息页面,显示这个用户有哪些菜单,需要并列
|
2021-10-17 17:35:18 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet]
|
2021-10-27 18:01:09 +08:00
|
|
|
|
public async Task<Result> GetTopMenusByHttpUser()
|
2021-10-17 17:35:18 +08:00
|
|
|
|
{
|
2021-10-29 23:23:32 +08:00
|
|
|
|
HttpContext.GetCurrentUserInfo(out List<int> menuIds);
|
|
|
|
|
|
|
|
|
|
|
|
return Result.Success().SetData(await _menuService.GetTopMenusByTopMenuIds(menuIds));
|
2021-10-17 17:35:18 +08:00
|
|
|
|
}
|
2021-10-13 23:08:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|