增加角色前台页面与后台数据绑定功能

This commit is contained in:
Argo-Lenovo 2016-10-24 22:10:17 +08:00
parent 0dce8e43ef
commit 9c295cc59a
9 changed files with 194 additions and 2 deletions

View File

@ -154,6 +154,7 @@
<Content Include="Content\js\messages_zh.min.js" />
<Content Include="Scripts\Groups.js" />
<Content Include="Scripts\Login.js" />
<Content Include="Scripts\Roles.js" />
<Content Include="Scripts\Users.js" />
<Content Include="Content\js\jquery-1.10.2.js" />
<Content Include="Content\js\jquery-1.10.2.min.js" />
@ -182,11 +183,13 @@
<Compile Include="Controllers\AdminController.cs" />
<Compile Include="Controllers\GroupsController.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\RolesController.cs" />
<Compile Include="Controllers\UsersController.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="Models\QueryGroupOption.cs" />
<Compile Include="Models\QueryRoleOption.cs" />
<Compile Include="Models\QueryUserOption.cs" />
<Compile Include="Models\HeaderBarModel.cs" />
<Compile Include="Models\LoginModel.cs" />
@ -215,6 +218,7 @@
<Content Include="Views\Shared\AwesomeIcon.cshtml" />
<Content Include="Views\Admin\FAIcon.cshtml" />
<Content Include="Views\Admin\Groups.cshtml" />
<Content Include="Views\Admin\Roles.cshtml" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>

View File

@ -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);
}
/// <summary>
///
/// </summary>

View File

@ -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
{
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
[HttpGet]
public QueryData<Role> Get([FromUri]QueryRoleOption value)
{
return value.RetrieveData();
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet]
public Role Get(int id)
{
return RoleHelper.RetrieveRole().FirstOrDefault(t => t.ID == id);
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
[HttpPost]
public bool Post([FromBody]Role value)
{
return RoleHelper.SaveRole(value);
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
[HttpDelete]
public bool Delete([FromBody]string value)
{
return RoleHelper.DeleteRole(value);
}
}
}

View File

@ -0,0 +1,41 @@
using Bootstrap.DataAccess;
using Longbow.Web.Mvc;
using System.Linq;
namespace Bootstrap.Admin.Models
{
public class QueryRoleOption : PaginationOption
{
/// <summary>
///
/// </summary>
public string RoleName { get; set; }
/// <summary>
///
/// </summary>
public string Description { get; set; }
/// <summary>
///
/// </summary>
/// <returns></returns>
public QueryData<Role> 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<Role>();
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;
}
}
}

View File

@ -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 }
]
});

View File

@ -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
}
});
});

View File

@ -0,0 +1,58 @@
@model NavigatorBarModel
@{
ViewBag.Title = "角色管理";
Layout = "~/Views/Shared/_Default.cshtml";
}
@section Javascript {
<script src="~/scripts/Roles.js"></script>
}
@section header {
@Html.Partial("Header", Model)
}
@section navigator {
@Html.Partial("Navigator", Model)
}
@section query {
<form class="form-inline" role="form">
<div class="form-group col-lg-5">
<label class="control-label" for="txt_search_name">角色名称</label>
<input type="text" class="form-control" id="txt_search_name" />
</div>
<div class="form-group col-lg-5">
<label class="control-label" for="txt_group_desc">角色描述</label>
<input type="text" class="form-control" id="txt_role_desc" />
</div>
<div class="form-group col-lg-2">
<button type="button" id="btn_query" class="btn btn-primary"><span class="glyphicon glyphicon-search" aria-hidden="true"></span>查询</button>
</div>
</form>
}
@section modal {
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">角色编辑窗口</h4>
</div>
<div class="modal-body">
<form class="form-inline" id="dataForm" name="dataForm" role="form">
<div class="form-group col-lg-6">
<label class="control-label" for="roleName">角色名称</label>
<input type="text" class="form-control" id="roleName" name="roleName" maxlength="50" />
</div>
<div class="form-group col-lg-6">
<label class="control-label" for="roleDesc">角色描述</label>
<input type="text" class="form-control" id="roleDesc" name="roleDesc" maxlength="50" />
<input type="text" class="form-control hide" id="roleID" name="roleID" />
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">
关闭
</button>
<button type="button" class="btn btn-primary" id="btnSubmit">
提交更改
</button>
</div>
</div>
}

View File

@ -29,7 +29,7 @@ namespace Bootstrap.DataAccess
return new List<Menu>() {
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 = "" },