From d3d0f5c17680af5dd273002053451cad56e38c15 Mon Sep 17 00:00:00 2001 From: lq_avenue <704528201@qq.com> Date: Tue, 25 Oct 2016 18:54:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6=E6=97=B6=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E7=9A=84=E8=8F=9C=E5=8D=95=E7=AE=A1=E7=90=86=E5=89=8D=E5=8F=B0?= =?UTF-8?q?=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.Admin/Bootstrap.Admin.csproj | 4 ++ .../Controllers/AdminController.cs | 9 +++ .../Controllers/MenusController.cs | 52 +++++++++++++++ Bootstrap.Admin/Models/QueryMenuOption.cs | 41 ++++++++++++ Bootstrap.Admin/Scripts/Menus.js | 53 +++++++++++++++ Bootstrap.Admin/Views/Admin/Menus.cshtml | 64 +++++++++++++++++++ Bootstrap.DataAccess/Menu.cs | 2 +- 7 files changed, 224 insertions(+), 1 deletion(-) create mode 100644 Bootstrap.Admin/Controllers/MenusController.cs create mode 100644 Bootstrap.Admin/Models/QueryMenuOption.cs create mode 100644 Bootstrap.Admin/Scripts/Menus.js create mode 100644 Bootstrap.Admin/Views/Admin/Menus.cshtml diff --git a/Bootstrap.Admin/Bootstrap.Admin.csproj b/Bootstrap.Admin/Bootstrap.Admin.csproj index 066b8244..0a10d9e9 100644 --- a/Bootstrap.Admin/Bootstrap.Admin.csproj +++ b/Bootstrap.Admin/Bootstrap.Admin.csproj @@ -155,6 +155,7 @@ + @@ -184,12 +185,14 @@ + Global.asax + @@ -220,6 +223,7 @@ + diff --git a/Bootstrap.Admin/Controllers/AdminController.cs b/Bootstrap.Admin/Controllers/AdminController.cs index ab5c88bf..dded4a5e 100644 --- a/Bootstrap.Admin/Controllers/AdminController.cs +++ b/Bootstrap.Admin/Controllers/AdminController.cs @@ -54,6 +54,15 @@ namespace Bootstrap.Admin.Controllers v.HomeUrl = "~/Admin"; return View(v); } + public ActionResult Menus() + { + var v = new NavigatorBarModel(); + v.BreadcrumbName = "菜单管理"; + v.ShowMenu = "hide"; + v.Menus[0].Active = "active"; + v.HomeUrl = "~/Admin"; + return View(v); + } /// /// /// diff --git a/Bootstrap.Admin/Controllers/MenusController.cs b/Bootstrap.Admin/Controllers/MenusController.cs new file mode 100644 index 00000000..9be065c9 --- /dev/null +++ b/Bootstrap.Admin/Controllers/MenusController.cs @@ -0,0 +1,52 @@ +using Bootstrap.Admin.Models; +using Bootstrap.DataAccess; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +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); + } + } +} \ No newline at end of file diff --git a/Bootstrap.Admin/Models/QueryMenuOption.cs b/Bootstrap.Admin/Models/QueryMenuOption.cs new file mode 100644 index 00000000..abbacd7e --- /dev/null +++ b/Bootstrap.Admin/Models/QueryMenuOption.cs @@ -0,0 +1,41 @@ +using Bootstrap.DataAccess; +using Longbow.Web.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace Bootstrap.Admin.Models +{ + public class QueryMenuOption : PaginationOption + { + /// + /// + /// + public string Name { get; set; } + /// + /// + /// + public string Category { get; set; } + + public QueryData RetrieveData() + { + // int limit, int offset, string name, string price, string sort, string order + var data = MenuHelper.RetrieveMenus(string.Empty); + if (!string.IsNullOrEmpty(Name)) + { + data = data.Where(t => t.Name.Contains(Name)); + } + if (!string.IsNullOrEmpty(Category)) + { + data = data.Where(t => t.Category.Contains(Category)); + } + var ret = new QueryData(); + ret.total = data.Count(); + // TODO: 通过option.Sort属性判断对那列进行排序,现在统一对名称列排序 + data = Order == "asc" ? data.OrderBy(t => t.Name) : data.OrderByDescending(t => t.Name); + ret.rows = data.Skip(Offset).Take(Limit); + return ret; + } + } +} \ No newline at end of file diff --git a/Bootstrap.Admin/Scripts/Menus.js b/Bootstrap.Admin/Scripts/Menus.js new file mode 100644 index 00000000..310964f5 --- /dev/null +++ b/Bootstrap.Admin/Scripts/Menus.js @@ -0,0 +1,53 @@ +$(function () { + var bsa = new BootstrapAdmin({ + url: '../api/Menus', + dataEntity: new DataEntity({ + map: { + ID: "menuID", + ParentId: "parentId", + Name: "name", + Order: "order", + Icon: "icon", + Url: "url", + Category: "category" + } + }) + }); + + $('table').smartTable({ + url: '../api/Menus', //请求后台的URL(*) + sortName: 'UserName', + queryParams: function (params) { return $.extend(params, { 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: "Name", sortable: true }, + { title: "菜单序号", field: "Order", sortable: false }, + { title: "菜单图标", field: "Icon", sortable: false }, + { title: "菜单路径", field: "Url", sortable: false }, + { title: "菜单类别", field: "Category", sortable: false } + ] + }); + + // validate + $('#dataForm').autoValidate({ + name: { + required: true, + maxlength: 50 + }, + icon: { + required: true, + maxlength: 50 + }, + url: { + required: true, + maxlength: 50 + }, + category: { + required: true, + maxlength: 50 + } + }); + + //TODO: 客户端点击保存用户后,要更新页面右上角用户显示名称 +}); \ No newline at end of file diff --git a/Bootstrap.Admin/Views/Admin/Menus.cshtml b/Bootstrap.Admin/Views/Admin/Menus.cshtml new file mode 100644 index 00000000..41e6730d --- /dev/null +++ b/Bootstrap.Admin/Views/Admin/Menus.cshtml @@ -0,0 +1,64 @@ +@model NavigatorBarModel +@{ + ViewBag.Title = "菜单管理"; + Layout = "~/Views/Shared/_Default.cshtml"; +} +@section Javascript { + +} +@section header { + @Html.Partial("Header", Model) +} +@section navigator { + @Html.Partial("Navigator", Model) +} +@section query { +
+
+ + +
+
+ + +
+
+ +
+
+} +@section modal { + + +} \ No newline at end of file diff --git a/Bootstrap.DataAccess/Menu.cs b/Bootstrap.DataAccess/Menu.cs index 883a2221..b73d97af 100644 --- a/Bootstrap.DataAccess/Menu.cs +++ b/Bootstrap.DataAccess/Menu.cs @@ -43,7 +43,7 @@ namespace Bootstrap.DataAccess public static List RetrieveMenus() { return new List() { - new Menu() { Name = "菜单管理", Icon = "fa-dashboard", Url="javascript:;", Active = "" }, + new Menu() { Name = "菜单管理", Icon = "fa-dashboard", Url="/Admin/Menus", Active = "" }, new Menu() { Name = "用户管理", Icon = "fa-user", Url="/Admin/Users", Active = "" }, new Menu() { Name = "角色管理", Icon = "fa-sitemap", Url="/Admin/Roles", Active = "" }, new Menu() { Name = "部门管理", Icon = "fa-home", Url="/Admin/Groups", Active = "" },