From 9c295cc59aa4fd2a52555393f18216df896ec5e6 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Mon, 24 Oct 2016 22:10:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=A7=92=E8=89=B2=E5=89=8D?= =?UTF-8?q?=E5=8F=B0=E9=A1=B5=E9=9D=A2=E4=B8=8E=E5=90=8E=E5=8F=B0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=BB=91=E5=AE=9A=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.Admin/Bootstrap.Admin.csproj | 4 ++ Bootstrap.Admin/Content/js/_references.js | Bin 1718 -> 1816 bytes .../Controllers/AdminController.cs | 9 +++ .../Controllers/RolesController.cs | 49 +++++++++++++++ Bootstrap.Admin/Models/QueryRoleOption.cs | 41 +++++++++++++ Bootstrap.Admin/Scripts/Groups.js | 2 +- Bootstrap.Admin/Scripts/Roles.js | 31 ++++++++++ Bootstrap.Admin/Views/Admin/Roles.cshtml | 58 ++++++++++++++++++ Bootstrap.DataAccess/Menu.cs | 2 +- 9 files changed, 194 insertions(+), 2 deletions(-) create mode 100644 Bootstrap.Admin/Controllers/RolesController.cs create mode 100644 Bootstrap.Admin/Models/QueryRoleOption.cs create mode 100644 Bootstrap.Admin/Scripts/Roles.js create mode 100644 Bootstrap.Admin/Views/Admin/Roles.cshtml diff --git a/Bootstrap.Admin/Bootstrap.Admin.csproj b/Bootstrap.Admin/Bootstrap.Admin.csproj index d87903e8..18e23779 100644 --- a/Bootstrap.Admin/Bootstrap.Admin.csproj +++ b/Bootstrap.Admin/Bootstrap.Admin.csproj @@ -154,6 +154,7 @@ + @@ -182,11 +183,13 @@ + Global.asax + @@ -215,6 +218,7 @@ + Web.config diff --git a/Bootstrap.Admin/Content/js/_references.js b/Bootstrap.Admin/Content/js/_references.js index e1e0a9481bd757cd565840a2555ee745e1ec5e33..4f98db8a3f7689c8f2d02b6bd4b34c7c13b6cce3 100644 GIT binary patch delta 27 jcmdnSJA-e-EH?HchJ1z`hSbRm*+eJzvARv3#U=v)dnX8e delta 11 ScmbQiw~cqhEVjvi*kk}3-vny_ diff --git a/Bootstrap.Admin/Controllers/AdminController.cs b/Bootstrap.Admin/Controllers/AdminController.cs index 265f7c34..ab5c88bf 100644 --- a/Bootstrap.Admin/Controllers/AdminController.cs +++ b/Bootstrap.Admin/Controllers/AdminController.cs @@ -45,6 +45,15 @@ namespace Bootstrap.Admin.Controllers v.HomeUrl = "~/Admin"; return View(v); } + public ActionResult Roles() + { + var v = new NavigatorBarModel(); + v.BreadcrumbName = "角色管理"; + v.ShowMenu = "hide"; + v.Menus[2].Active = "active"; + v.HomeUrl = "~/Admin"; + return View(v); + } /// /// /// diff --git a/Bootstrap.Admin/Controllers/RolesController.cs b/Bootstrap.Admin/Controllers/RolesController.cs new file mode 100644 index 00000000..6a352e6b --- /dev/null +++ b/Bootstrap.Admin/Controllers/RolesController.cs @@ -0,0 +1,49 @@ +using Bootstrap.Admin.Models; +using Bootstrap.DataAccess; +using System.Linq; +using System.Web.Http; + +namespace Bootstrap.Admin.Controllers +{ + public class RolesController : ApiController + { + /// + /// + /// + /// + /// + [HttpGet] + public QueryData Get([FromUri]QueryRoleOption value) + { + return value.RetrieveData(); + } + /// + /// + /// + /// + /// + [HttpGet] + public Role Get(int id) + { + return RoleHelper.RetrieveRole().FirstOrDefault(t => t.ID == id); + } + /// + /// + /// + /// + [HttpPost] + public bool Post([FromBody]Role value) + { + return RoleHelper.SaveRole(value); + } + /// + /// + /// + /// + [HttpDelete] + public bool Delete([FromBody]string value) + { + return RoleHelper.DeleteRole(value); + } + } +} diff --git a/Bootstrap.Admin/Models/QueryRoleOption.cs b/Bootstrap.Admin/Models/QueryRoleOption.cs new file mode 100644 index 00000000..b7d1606a --- /dev/null +++ b/Bootstrap.Admin/Models/QueryRoleOption.cs @@ -0,0 +1,41 @@ +using Bootstrap.DataAccess; +using Longbow.Web.Mvc; +using System.Linq; + +namespace Bootstrap.Admin.Models +{ + public class QueryRoleOption : PaginationOption + { + /// + /// + /// + public string RoleName { get; set; } + /// + /// + /// + public string Description { get; set; } + /// + /// + /// + /// + public QueryData RetrieveData() + { + // int limit, int offset, string name, string price, string sort, string order + var data = RoleHelper.RetrieveRole(string.Empty); + if (!string.IsNullOrEmpty(RoleName)) + { + data = data.Where(t => t.RoleName.Contains(RoleName)); + } + if (!string.IsNullOrEmpty(Description)) + { + data = data.Where(t => t.Description.Contains(Description)); + } + var ret = new QueryData(); + ret.total = data.Count(); + // TODO: 通过option.Sort属性判断对那列进行排序,现在统一对名称列排序 + data = Order == "asc" ? data.OrderBy(t => t.RoleName) : data.OrderByDescending(t => t.RoleName); + ret.rows = data.Skip(Offset).Take(Limit); + return ret; + } + } +} \ No newline at end of file diff --git a/Bootstrap.Admin/Scripts/Groups.js b/Bootstrap.Admin/Scripts/Groups.js index 381081ae..5381b6fe 100644 --- a/Bootstrap.Admin/Scripts/Groups.js +++ b/Bootstrap.Admin/Scripts/Groups.js @@ -17,7 +17,7 @@ columns: [{ checkbox: true }, { title: "Id", field: "ID", events: bsa.idEvents(), formatter: BootstrapAdmin.idFormatter }, { title: "部门名称", field: "GroupName", sortable: true }, - { title: "部门描述", field: "Description", sortable: true } + { title: "部门描述", field: "Description", sortable: false } ] }); diff --git a/Bootstrap.Admin/Scripts/Roles.js b/Bootstrap.Admin/Scripts/Roles.js new file mode 100644 index 00000000..202e0ad0 --- /dev/null +++ b/Bootstrap.Admin/Scripts/Roles.js @@ -0,0 +1,31 @@ +$(function () { + var bsa = new BootstrapAdmin({ + url: '../api/Roles', + dataEntity: new DataEntity({ + map: { + ID: "roleID", + RoleName: "roleName", + Description: "roleDesc" + } + }) + }); + + $('table').smartTable({ + url: '../api/Roles', //请求后台的URL(*) + sortName: 'RoleName', + queryParams: function (params) { return $.extend(params, { roleName: $("#txt_search_name").val(), description: $("#txt_role_desc").val() }); }, //传递参数(*) + columns: [{ checkbox: true }, + { title: "Id", field: "ID", events: bsa.idEvents(), formatter: BootstrapAdmin.idFormatter }, + { title: "角色名称", field: "RoleName", sortable: true }, + { title: "角色描述", field: "Description", sortable: false } + ] + }); + + // validate + $('#dataForm').autoValidate({ + roleName: { + required: true, + maxlength: 50 + } + }); +}); \ No newline at end of file diff --git a/Bootstrap.Admin/Views/Admin/Roles.cshtml b/Bootstrap.Admin/Views/Admin/Roles.cshtml new file mode 100644 index 00000000..9921ad5c --- /dev/null +++ b/Bootstrap.Admin/Views/Admin/Roles.cshtml @@ -0,0 +1,58 @@ +@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 97305534..9176af6d 100644 --- a/Bootstrap.DataAccess/Menu.cs +++ b/Bootstrap.DataAccess/Menu.cs @@ -29,7 +29,7 @@ namespace Bootstrap.DataAccess return new List() { new Menu() { Name = "菜单管理", Icon = "fa-dashboard", Url="javascript:;", Active = "" }, new Menu() { Name = "用户管理", Icon = "fa-user", Url="/Admin/Users", Active = "" }, - new Menu() { Name = "角色管理", Icon = "fa-sitemap", Url="javascript:;", Active = "" }, + new Menu() { Name = "角色管理", Icon = "fa-sitemap", Url="/Admin/Roles", Active = "" }, new Menu() { Name = "部门管理", Icon = "fa-home", Url="/Admin/Groups", Active = "" }, new Menu() { Name = "字典表维护", Icon = "fa-book", Url="javascript:;", Active = "" }, new Menu() { Name = "个性化维护", Icon = "fa-pencil", Url="javascript:;", Active = "" },