From dc96c34735433b8571662d95425a0039fa446efd Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Sun, 6 Nov 2016 00:48:08 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8F=9C=E5=8D=95=E9=A1=B5=E9=9D=A2=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=88=B6=E7=BA=A7=E8=8F=9C=E5=8D=95=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/MenusController.cs | 85 ++++++++----------- Bootstrap.Admin/Models/QueryMenuOption.cs | 11 +++ Bootstrap.Admin/Scripts/Menus.js | 6 +- Bootstrap.Admin/Views/Admin/Menus.cshtml | 10 ++- Bootstrap.DataAccess/Menu.cs | 4 + Bootstrap.DataAccess/MenuHelper.cs | 5 +- 6 files changed, 65 insertions(+), 56 deletions(-) diff --git a/Bootstrap.Admin/Controllers/MenusController.cs b/Bootstrap.Admin/Controllers/MenusController.cs index e0071d44..02050b38 100644 --- a/Bootstrap.Admin/Controllers/MenusController.cs +++ b/Bootstrap.Admin/Controllers/MenusController.cs @@ -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 - { - /// - /// - /// - /// - /// - [HttpGet] - public QueryData Get([FromUri]QueryMenuOption value) - { - return value.RetrieveData(); - } - /// - /// - /// - /// - /// - [HttpGet] - public Menu Get(int id) - { - return MenuHelper.RetrieveMenus().FirstOrDefault(t => t.ID == id); - } - /// - /// - /// - /// - [HttpPost] - public bool Post([FromBody]Menu value) - { - return MenuHelper.SaveMenu(value); - } - /// - /// - /// - /// - [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 + { + /// + /// + /// + /// + /// + [HttpGet] + public QueryData Get([FromUri]QueryMenuOption value) + { + return value.RetrieveData(); + } + /// + /// + /// + /// + [HttpPost] + public bool Post([FromBody]Menu value) + { + return MenuHelper.SaveMenu(value); + } + /// + /// + /// + /// + [HttpDelete] + public bool Delete([FromBody]string value) + { + return MenuHelper.DeleteMenu(value); + } + } } \ No newline at end of file diff --git a/Bootstrap.Admin/Models/QueryMenuOption.cs b/Bootstrap.Admin/Models/QueryMenuOption.cs index 0d8b56fe..388280d7 100644 --- a/Bootstrap.Admin/Models/QueryMenuOption.cs +++ b/Bootstrap.Admin/Models/QueryMenuOption.cs @@ -13,11 +13,19 @@ namespace Bootstrap.Admin.Models /// /// /// + public string ParentName { get; set; } + /// + /// + /// public string Category { get; set; } public QueryData 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; diff --git a/Bootstrap.Admin/Scripts/Menus.js b/Bootstrap.Admin/Scripts/Menus.js index b686f38c..11d50cce 100644 --- a/Bootstrap.Admin/Scripts/Menus.js +++ b/Bootstrap.Admin/Scripts/Menus.js @@ -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 }, diff --git a/Bootstrap.Admin/Views/Admin/Menus.cshtml b/Bootstrap.Admin/Views/Admin/Menus.cshtml index c297ccf2..868b735f 100644 --- a/Bootstrap.Admin/Views/Admin/Menus.cshtml +++ b/Bootstrap.Admin/Views/Admin/Menus.cshtml @@ -20,11 +20,15 @@ } @section query {
-
+
+ + +
+
-
+
@@ -40,7 +44,7 @@
-
+
diff --git a/Bootstrap.DataAccess/Menu.cs b/Bootstrap.DataAccess/Menu.cs index 580232f6..82438d99 100644 --- a/Bootstrap.DataAccess/Menu.cs +++ b/Bootstrap.DataAccess/Menu.cs @@ -16,6 +16,10 @@ namespace Bootstrap.DataAccess /// public int ParentId { set; get; } /// + /// 获得/设置 父级菜单名称 + /// + public string ParentName { get; set; } + /// /// 获得/设置 菜单名称 /// public string Name { get; set; } diff --git a/Bootstrap.DataAccess/MenuHelper.cs b/Bootstrap.DataAccess/MenuHelper.cs index d6d41622..40bd8188 100644 --- a/Bootstrap.DataAccess/MenuHelper.cs +++ b/Bootstrap.DataAccess/MenuHelper.cs @@ -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 Menus = new List(); 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) }); } }