menuFind
This commit is contained in:
parent
c6bb6d6dd3
commit
1368e68b1b
@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using static asg_form.Controllers.InviteReferee;
|
using static asg_form.Controllers.InviteReferee;
|
||||||
|
using static asg_form.Controllers.menuAssignController;
|
||||||
|
|
||||||
namespace asg_form.Controllers
|
namespace asg_form.Controllers
|
||||||
{
|
{
|
||||||
@ -118,5 +119,66 @@ namespace asg_form.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public class menuFront
|
||||||
|
{
|
||||||
|
public string id { get; set; }
|
||||||
|
public string path { get; set; }
|
||||||
|
public string iconClass { get; set; }
|
||||||
|
public string title { get; set; }
|
||||||
|
public string parentId { get; set; }
|
||||||
|
public string auth { get; set; }
|
||||||
|
public string component { get; set; }
|
||||||
|
public string allowOperate { get; set; }
|
||||||
|
public string show { get; set; }
|
||||||
|
public List<menuFront> children { get; set; } = new List<menuFront>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<menuFront> BuildTree(IEnumerable<menuDB> nodes, string? parentId)
|
||||||
|
{
|
||||||
|
return nodes.Where(x => x.parent_id == parentId)
|
||||||
|
.Select(x => new menuFront
|
||||||
|
{
|
||||||
|
id = x.id,
|
||||||
|
path = x.path,
|
||||||
|
iconClass = x.icon_class,
|
||||||
|
title = x.title,
|
||||||
|
parentId = x.parent_id,
|
||||||
|
auth = x.auth,
|
||||||
|
component = x.component,
|
||||||
|
allowOperate = x.allow_operate,
|
||||||
|
show = x.show,
|
||||||
|
children = BuildTree(nodes, x.id)
|
||||||
|
}).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查询菜单
|
||||||
|
/// </summary>
|
||||||
|
[Route("api/v1/admin/menuFind")]
|
||||||
|
[HttpGet]
|
||||||
|
[Authorize]
|
||||||
|
public async Task<ActionResult<object>> menuFind()
|
||||||
|
{
|
||||||
|
if (!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "nbadmin"))
|
||||||
|
{
|
||||||
|
return BadRequest(new error_mb { code = 400, message = "无权访问" });
|
||||||
|
}
|
||||||
|
using (var db = new TestDbContext())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var query = db.mainMenu.AsQueryable();
|
||||||
|
int total = query.Count();
|
||||||
|
var allData = query.ToList();
|
||||||
|
var rootNodes = allData.Where(x => x.parent_id == "-1").ToList();
|
||||||
|
var treeData = BuildTree(allData, "-1").ToList();
|
||||||
|
return Ok(new { code = 200, message = "" ,data=treeData,total});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Ok(new { code = 500, message = "服务器错误", ex });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user