feat: 添加 字典 菜单 角色 用户 控制器
This commit is contained in:
parent
75716a9444
commit
fa7fae9575
|
@ -0,0 +1,58 @@
|
|||
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
|
||||
// Licensed under the LGPL License, Version 3.0. See License.txt in the project root for license information.
|
||||
// Website: https://admin.blazor.zone
|
||||
|
||||
using BootstrapAdmin.DataAccess.Models;
|
||||
using BootstrapAdmin.Web.Core;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace BootstrapAdmin.Api.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 字典表维护控制器
|
||||
/// </summary>
|
||||
[Route("api/[controller]")]
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
public class DictsController : ControllerBase
|
||||
{
|
||||
private IDict DictService { get; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="dictService"></param>
|
||||
public DictsController(IDict dictService) => DictService = dictService;
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有字典表数据方法
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public ActionResult<List<Dict>> Get()
|
||||
{
|
||||
return DictService.GetAll();
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存字典方法
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
[HttpPost]
|
||||
public bool Post([FromBody] Dict value)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除字典项方法
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
[HttpDelete]
|
||||
[Authorize(Roles = "Administrators")]
|
||||
public bool Delete([FromBody] IEnumerable<string> value)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
|
||||
// Licensed under the LGPL License, Version 3.0. See License.txt in the project root for license information.
|
||||
// Website: https://admin.blazor.zone
|
||||
|
||||
using Bootstrap.Admin.Query;
|
||||
using Bootstrap.DataAccess;
|
||||
using Bootstrap.Security;
|
||||
using Longbow.Web.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Bootstrap.Admin.Controllers.Api
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Route("api/[controller]")]
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
public class MenusController : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 获得所有菜单列表调用
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public QueryData<object> Get([FromQuery]QueryMenuOption value)
|
||||
{
|
||||
return value.RetrieveData(User.Identity!.Name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存菜单调用
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
[HttpPost]
|
||||
[ButtonAuthorize(Url = "~/Admin/Menus", Auth = "add,edit")]
|
||||
public bool Post([FromBody]BootstrapMenu value)
|
||||
{
|
||||
return MenuHelper.Save(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除菜单调用
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
[HttpDelete]
|
||||
[ButtonAuthorize(Url = "~/Admin/Menus", Auth = "del")]
|
||||
public bool Delete([FromBody]IEnumerable<string> value)
|
||||
{
|
||||
return MenuHelper.Delete(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 角色管理菜单授权按钮调用
|
||||
/// </summary>
|
||||
/// <param name="id">角色ID</param>
|
||||
/// <param name="type">type=role时,角色管理菜单授权调用;type=user时,菜单管理编辑页面父类菜单按钮调用</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("{id}")]
|
||||
public IEnumerable<object> Post(string id, [FromQuery]string type)
|
||||
{
|
||||
IEnumerable<object> ret = new List<object>();
|
||||
switch (type)
|
||||
{
|
||||
case "role":
|
||||
ret = MenuHelper.RetrieveMenusByRoleId(id);
|
||||
break;
|
||||
case "user":
|
||||
ret = MenuHelper.RetrieveMenus(User.Identity!.Name);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 角色管理菜单授权保存按钮调用
|
||||
/// </summary>
|
||||
/// <param name="id">菜单ID</param>
|
||||
/// <param name="roleIds">角色ID集合</param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("{id}")]
|
||||
[ButtonAuthorize(Url = "~/Admin/Menus", Auth = "assignRole")]
|
||||
public bool Put(string id, [FromBody]IEnumerable<string> roleIds)
|
||||
{
|
||||
return RoleHelper.SavaByMenuId(id, roleIds);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
|
||||
// Licensed under the LGPL License, Version 3.0. See License.txt in the project root for license information.
|
||||
// Website: https://admin.blazor.zone
|
||||
|
||||
using Bootstrap.Admin.Query;
|
||||
using Bootstrap.DataAccess;
|
||||
using Longbow.Web.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
namespace Bootstrap.Admin.Controllers.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// 角色维护控制器
|
||||
/// </summary>
|
||||
[Route("api/[controller]")]
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
public class RolesController : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取所有角色数据
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public QueryData<object> Get([FromQuery]QueryRoleOption value)
|
||||
{
|
||||
return value.RetrieveData();
|
||||
}
|
||||
/// <summary>
|
||||
/// 通过指定用户ID/部门ID/菜单ID获得所有角色集合,已经授权的有checked标记
|
||||
/// </summary>
|
||||
/// <param name="id">用户ID/部门ID/菜单ID</param>
|
||||
/// <param name="type">类型</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("{id}")]
|
||||
public IEnumerable<object> Post(string id, [FromQuery]string type)
|
||||
{
|
||||
var ret = type switch
|
||||
{
|
||||
"user" => RoleHelper.RetrievesByUserId(id),
|
||||
"group" => RoleHelper.RetrievesByGroupId(id),
|
||||
"menu" => RoleHelper.RetrievesByMenuId(id),
|
||||
_ => new Role[0]
|
||||
};
|
||||
return ret.Select(m => new { m.Id, m.Checked, m.RoleName, m.Description });
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存角色授权方法
|
||||
/// </summary>
|
||||
/// <param name="id">角色ID</param>
|
||||
/// <param name="values">选中的ID集合</param>
|
||||
/// <param name="type">type=menu时,菜单维护页面对角色授权弹框保存按钮调用</param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("{id}")]
|
||||
[ButtonAuthorize(Url = "~/Admin/Roles", Auth = "assignUser,assignGroup,assignMenu,assignApp")]
|
||||
public bool Put(string id, [FromBody]IEnumerable<string> values, [FromQuery]string type) => type switch
|
||||
{
|
||||
"user" => UserHelper.SaveByRoleId(id, values),
|
||||
"group" => GroupHelper.SaveByRoleId(id, values),
|
||||
"menu" => MenuHelper.SaveMenusByRoleId(id, values),
|
||||
"app" => AppHelper.SaveByRoleId(id, values),
|
||||
_ => false
|
||||
};
|
||||
/// <summary>
|
||||
/// 保存角色方法
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
[HttpPost]
|
||||
[ButtonAuthorize(Url = "~/Admin/Roles", Auth = "add,edit")]
|
||||
public bool Post([FromBody]Role value)
|
||||
{
|
||||
return RoleHelper.Save(value);
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除角色方法
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
[HttpDelete]
|
||||
[ButtonAuthorize(Url = "~/Admin/Roles", Auth = "del")]
|
||||
public bool Delete([FromBody]IEnumerable<string> value)
|
||||
{
|
||||
return RoleHelper.Delete(value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
|
||||
// Licensed under the LGPL License, Version 3.0. See License.txt in the project root for license information.
|
||||
// Website: https://admin.blazor.zone
|
||||
|
||||
using BootstrapAdmin.DataAccess.Models;
|
||||
using BootstrapAdmin.Web.Core;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace BootstrapAdmin.Api.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户控制器
|
||||
/// </summary>
|
||||
[Route("api/[controller]")]
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
public class UsersController : ControllerBase
|
||||
{
|
||||
private IUser UserService { get; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="userService"></param>
|
||||
public UsersController(IUser userService) => UserService = userService;
|
||||
|
||||
/// <summary>
|
||||
/// 调用获取所有用户信息 用户管理查询按钮
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public ActionResult<List<User>> Get()
|
||||
{
|
||||
return UserService.GetAll();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// api 握手协议
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpOptions]
|
||||
public string? Options()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue