菜单页面增加父级菜单显示名称功能

This commit is contained in:
Argo-Lenovo 2016-11-06 00:48:08 +08:00
parent 95e39a1e2c
commit dc96c34735
6 changed files with 65 additions and 56 deletions

View File

@ -1,49 +1,38 @@
using Bootstrap.Admin.Models; using Bootstrap.Admin.Models;
using Bootstrap.DataAccess; using Bootstrap.DataAccess;
using System.Linq; using System.Web.Http;
using System.Web.Http;
namespace Bootstrap.Admin.Controllers
namespace Bootstrap.Admin.Controllers {
{ public class MenusController : ApiController
public class MenusController : ApiController {
{ /// <summary>
/// <summary> ///
/// /// </summary>
/// </summary> /// <param name="value"></param>
/// <param name="value"></param> /// <returns></returns>
/// <returns></returns> [HttpGet]
[HttpGet] public QueryData<Menu> Get([FromUri]QueryMenuOption value)
public QueryData<Menu> Get([FromUri]QueryMenuOption value) {
{ return value.RetrieveData();
return value.RetrieveData(); }
} /// <summary>
/// <summary> ///
/// /// </summary>
/// </summary> /// <param name="value"></param>
/// <param name="id"></param> [HttpPost]
/// <returns></returns> public bool Post([FromBody]Menu value)
[HttpGet] {
public Menu Get(int id) return MenuHelper.SaveMenu(value);
{ }
return MenuHelper.RetrieveMenus().FirstOrDefault(t => t.ID == id); /// <summary>
} ///
/// <summary> /// </summary>
/// /// <param name="id"></param>
/// </summary> [HttpDelete]
/// <param name="value"></param> public bool Delete([FromBody]string value)
[HttpPost] {
public bool Post([FromBody]Menu value) return MenuHelper.DeleteMenu(value);
{ }
return MenuHelper.SaveMenu(value); }
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
[HttpDelete]
public bool Delete([FromBody]string value)
{
return MenuHelper.DeleteMenu(value);
}
}
} }

View File

@ -13,11 +13,19 @@ namespace Bootstrap.Admin.Models
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public string ParentName { get; set; }
/// <summary>
///
/// </summary>
public string Category { get; set; } public string Category { get; set; }
public QueryData<Menu> RetrieveData() public QueryData<Menu> RetrieveData()
{ {
var data = MenuHelper.RetrieveMenus(); var data = MenuHelper.RetrieveMenus();
if (!string.IsNullOrEmpty(ParentName))
{
data = data.Where(t => t.ParentName.Contains(ParentName));
}
if (!string.IsNullOrEmpty(Name)) if (!string.IsNullOrEmpty(Name))
{ {
data = data.Where(t => t.Name.Contains(Name)); data = data.Where(t => t.Name.Contains(Name));
@ -33,6 +41,9 @@ namespace Bootstrap.Admin.Models
case "Name": case "Name":
data = Order == "asc" ? data.OrderBy(t => t.Name) : data.OrderByDescending(t => t.Name); data = Order == "asc" ? data.OrderBy(t => t.Name) : data.OrderByDescending(t => t.Name);
break; break;
case "ParentName":
data = Order == "asc" ? data.OrderBy(t => t.ParentName) : data.OrderByDescending(t => t.ParentName);
break;
case "Order": case "Order":
data = Order == "asc" ? data.OrderBy(t => t.Order) : data.OrderByDescending(t => t.Order); data = Order == "asc" ? data.OrderBy(t => t.Order) : data.OrderByDescending(t => t.Order);
break; break;

View File

@ -37,11 +37,11 @@
$('table').smartTable({ $('table').smartTable({
url: '../api/Menus', //请求后台的URL* url: '../api/Menus', //请求后台的URL*
sortName: 'UserName', sortName: 'Order',
queryParams: function (params) { return $.extend(params, { name: $("#txt_menus_name").val(), category: $('#txt_menus_category').val() }); }, //传递参数(* 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 }, columns: [{ checkbox: true },
{ title: "Id", field: "ID", events: bsa.idEvents(), formatter: BootstrapAdmin.idFormatter }, { 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: "Name", sortable: true },
{ title: "菜单序号", field: "Order", sortable: true }, { title: "菜单序号", field: "Order", sortable: true },
{ title: "菜单图标", field: "Icon", sortable: false }, { title: "菜单图标", field: "Icon", sortable: false },

View File

@ -20,11 +20,15 @@
} }
@section query { @section query {
<form class="form-inline" role="form"> <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> <label class="control-label" for="txt_menus_name">菜单名称</label>
<input type="text" class="form-control" id="txt_menus_name" /> <input type="text" class="form-control" id="txt_menus_name" />
</div> </div>
<div class="form-group col-lg-5"> <div class="form-group col-lg-3">
<label class="control-label" for="txt_menus_category">菜单类别</label> <label class="control-label" for="txt_menus_category">菜单类别</label>
<input type="text" class="form-control hide" id="txt_menus_category" /> <input type="text" class="form-control hide" id="txt_menus_category" />
<div class="btn-group"> <div class="btn-group">
@ -40,7 +44,7 @@
</ul> </ul>
</div> </div>
</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> <button type="button" id="btn_query" class="btn btn-primary"><span class="glyphicon glyphicon-search" aria-hidden="true"></span>查询</button>
</div> </div>
</form> </form>

View File

@ -16,6 +16,10 @@ namespace Bootstrap.DataAccess
/// </summary> /// </summary>
public int ParentId { set; get; } public int ParentId { set; get; }
/// <summary> /// <summary>
/// 获得/设置 父级菜单名称
/// </summary>
public string ParentName { get; set; }
/// <summary>
/// 获得/设置 菜单名称 /// 获得/设置 菜单名称
/// </summary> /// </summary>
public string Name { get; set; } public string Name { get; set; }

View File

@ -25,7 +25,7 @@ namespace Bootstrap.DataAccess
{ {
return CacheManager.GetOrAdd(RetrieveMenusDataKey, CacheSection.RetrieveIntervalByKey(RetrieveMenusDataKey), key => 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>(); List<Menu> Menus = new List<Menu>();
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql); DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
try try
@ -43,7 +43,8 @@ namespace Bootstrap.DataAccess
Icon = LgbConvert.ReadValue(reader[4], string.Empty), Icon = LgbConvert.ReadValue(reader[4], string.Empty),
Url = LgbConvert.ReadValue(reader[5], string.Empty), Url = LgbConvert.ReadValue(reader[5], string.Empty),
Category = (string)reader[6], Category = (string)reader[6],
CategoryName = (string)reader[7] CategoryName = (string)reader[7],
ParentName = LgbConvert.ReadValue(reader[8], string.Empty)
}); });
} }
} }