refactor: 初始化控制器
This commit is contained in:
parent
8f479da90a
commit
a1736215e6
|
@ -2,10 +2,7 @@
|
||||||
// Licensed under the LGPL License, Version 3.0. See License.txt in the project root for license information.
|
// Licensed under the LGPL License, Version 3.0. See License.txt in the project root for license information.
|
||||||
// Website: https://admin.blazor.zone
|
// Website: https://admin.blazor.zone
|
||||||
|
|
||||||
using Bootstrap.Admin.Query;
|
|
||||||
using Bootstrap.DataAccess;
|
|
||||||
using Bootstrap.Security;
|
using Bootstrap.Security;
|
||||||
using Longbow.Web.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
|
@ -21,72 +18,6 @@ namespace Bootstrap.Admin.Controllers.Api
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class MenusController : ControllerBase
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,6 @@
|
||||||
// Licensed under the LGPL License, Version 3.0. See License.txt in the project root for license information.
|
// Licensed under the LGPL License, Version 3.0. See License.txt in the project root for license information.
|
||||||
// Website: https://admin.blazor.zone
|
// Website: https://admin.blazor.zone
|
||||||
|
|
||||||
using Bootstrap.Admin.Query;
|
|
||||||
using Bootstrap.DataAccess;
|
|
||||||
using Longbow.Web.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
|
@ -22,70 +19,5 @@ namespace Bootstrap.Admin.Controllers.Api
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class RolesController : ControllerBase
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,9 @@ namespace BootstrapAdmin.Api.Controllers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public ActionResult<List<User>> Get()
|
public IActionResult Get()
|
||||||
{
|
{
|
||||||
return UserService.GetAll();
|
return new JsonResult(new { Code = "0", Message = "login successed!", Result = new { roles = Array.Empty<string>() } }) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue