菜单页面增加父级菜单显示名称功能
This commit is contained in:
parent
95e39a1e2c
commit
dc96c34735
|
@ -1,49 +1,38 @@
|
|||
using Bootstrap.Admin.Models;
|
||||
using Bootstrap.DataAccess;
|
||||
using System.Linq;
|
||||
using System.Web.Http;
|
||||
|
||||
namespace Bootstrap.Admin.Controllers
|
||||
{
|
||||
public class MenusController : ApiController
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public QueryData<Menu> Get([FromUri]QueryMenuOption value)
|
||||
{
|
||||
return value.RetrieveData();
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public Menu Get(int id)
|
||||
{
|
||||
return MenuHelper.RetrieveMenus().FirstOrDefault(t => t.ID == id);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
[HttpPost]
|
||||
public bool Post([FromBody]Menu value)
|
||||
{
|
||||
return MenuHelper.SaveMenu(value);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
[HttpDelete]
|
||||
public bool Delete([FromBody]string value)
|
||||
{
|
||||
return MenuHelper.DeleteMenu(value);
|
||||
}
|
||||
}
|
||||
using Bootstrap.Admin.Models;
|
||||
using Bootstrap.DataAccess;
|
||||
using System.Web.Http;
|
||||
|
||||
namespace Bootstrap.Admin.Controllers
|
||||
{
|
||||
public class MenusController : ApiController
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public QueryData<Menu> Get([FromUri]QueryMenuOption value)
|
||||
{
|
||||
return value.RetrieveData();
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
[HttpPost]
|
||||
public bool Post([FromBody]Menu value)
|
||||
{
|
||||
return MenuHelper.SaveMenu(value);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
[HttpDelete]
|
||||
public bool Delete([FromBody]string value)
|
||||
{
|
||||
return MenuHelper.DeleteMenu(value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,11 +13,19 @@ namespace Bootstrap.Admin.Models
|
|||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string ParentName { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Category { get; set; }
|
||||
|
||||
public QueryData<Menu> RetrieveData()
|
||||
{
|
||||
var data = MenuHelper.RetrieveMenus();
|
||||
if (!string.IsNullOrEmpty(ParentName))
|
||||
{
|
||||
data = data.Where(t => t.ParentName.Contains(ParentName));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Name))
|
||||
{
|
||||
data = data.Where(t => t.Name.Contains(Name));
|
||||
|
@ -33,6 +41,9 @@ namespace Bootstrap.Admin.Models
|
|||
case "Name":
|
||||
data = Order == "asc" ? data.OrderBy(t => t.Name) : data.OrderByDescending(t => t.Name);
|
||||
break;
|
||||
case "ParentName":
|
||||
data = Order == "asc" ? data.OrderBy(t => t.ParentName) : data.OrderByDescending(t => t.ParentName);
|
||||
break;
|
||||
case "Order":
|
||||
data = Order == "asc" ? data.OrderBy(t => t.Order) : data.OrderByDescending(t => t.Order);
|
||||
break;
|
||||
|
|
|
@ -37,11 +37,11 @@
|
|||
|
||||
$('table').smartTable({
|
||||
url: '../api/Menus', //请求后台的URL(*)
|
||||
sortName: 'UserName',
|
||||
queryParams: function (params) { return $.extend(params, { name: $("#txt_menus_name").val(), category: $('#txt_menus_category').val() }); }, //传递参数(*)
|
||||
sortName: 'Order',
|
||||
queryParams: function (params) { return $.extend(params, { parentName: $('#txt_parent_menus_name').val(), name: $("#txt_menus_name").val(), category: $('#txt_menus_category').val() }); }, //传递参数(*)
|
||||
columns: [{ checkbox: true },
|
||||
{ title: "Id", field: "ID", events: bsa.idEvents(), formatter: BootstrapAdmin.idFormatter },
|
||||
{ title: "父级ID", field: "ParentId", sortable: false },
|
||||
{ title: "父级菜单", field: "ParentName", sortable: true },
|
||||
{ title: "菜单名称", field: "Name", sortable: true },
|
||||
{ title: "菜单序号", field: "Order", sortable: true },
|
||||
{ title: "菜单图标", field: "Icon", sortable: false },
|
||||
|
|
|
@ -20,11 +20,15 @@
|
|||
}
|
||||
@section query {
|
||||
<form class="form-inline" role="form">
|
||||
<div class="form-group col-lg-5">
|
||||
<div class="form-group col-lg-3">
|
||||
<label class="control-label" for="txt_parent_menus_name">父级菜单</label>
|
||||
<input type="text" class="form-control" id="txt_parent_menus_name" />
|
||||
</div>
|
||||
<div class="form-group col-lg-3">
|
||||
<label class="control-label" for="txt_menus_name">菜单名称</label>
|
||||
<input type="text" class="form-control" id="txt_menus_name" />
|
||||
</div>
|
||||
<div class="form-group col-lg-5">
|
||||
<div class="form-group col-lg-3">
|
||||
<label class="control-label" for="txt_menus_category">菜单类别</label>
|
||||
<input type="text" class="form-control hide" id="txt_menus_category" />
|
||||
<div class="btn-group">
|
||||
|
@ -40,7 +44,7 @@
|
|||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-lg-2">
|
||||
<div class="form-group col-lg-1">
|
||||
<button type="button" id="btn_query" class="btn btn-primary"><span class="glyphicon glyphicon-search" aria-hidden="true"></span>查询</button>
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -16,6 +16,10 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
public int ParentId { set; get; }
|
||||
/// <summary>
|
||||
/// 获得/设置 父级菜单名称
|
||||
/// </summary>
|
||||
public string ParentName { get; set; }
|
||||
/// <summary>
|
||||
/// 获得/设置 菜单名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
return CacheManager.GetOrAdd(RetrieveMenusDataKey, CacheSection.RetrieveIntervalByKey(RetrieveMenusDataKey), key =>
|
||||
{
|
||||
string sql = "select n.*, d.Name as CategoryName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = N'菜单' and d.Define = 0";
|
||||
string sql = "select n.*, d.Name as CategoryName, ln.Name as ParentName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = N'菜单' and d.Define = 0 left join Navigations ln on n.ParentId = ln.ID";
|
||||
List<Menu> Menus = new List<Menu>();
|
||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||
try
|
||||
|
@ -43,7 +43,8 @@ namespace Bootstrap.DataAccess
|
|||
Icon = LgbConvert.ReadValue(reader[4], string.Empty),
|
||||
Url = LgbConvert.ReadValue(reader[5], string.Empty),
|
||||
Category = (string)reader[6],
|
||||
CategoryName = (string)reader[7]
|
||||
CategoryName = (string)reader[7],
|
||||
ParentName = LgbConvert.ReadValue(reader[8], string.Empty)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue