增加部门管理前台页面,整合用户管理,使前台代码更简洁

This commit is contained in:
Argo-Lenovo 2016-10-24 20:53:05 +08:00
parent 8548c564d3
commit 3e4f670b17
16 changed files with 288 additions and 75 deletions

View File

@ -152,6 +152,7 @@
<Content Include="Content\js\Longbow.Common.js" />
<Content Include="Content\js\messages_zh.js" />
<Content Include="Content\js\messages_zh.min.js" />
<Content Include="Scripts\Groups.js" />
<Content Include="Scripts\Login.js" />
<Content Include="Scripts\Users.js" />
<Content Include="Content\js\jquery-1.10.2.js" />
@ -179,17 +180,19 @@
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="App_Start\WebApiConfig.cs" />
<Compile Include="Controllers\AdminController.cs" />
<Compile Include="Controllers\GroupsController.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\UsersController.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="Models\UsersPageOption.cs" />
<Compile Include="Models\QueryGroupOption.cs" />
<Compile Include="Models\QueryUserOption.cs" />
<Compile Include="Models\HeaderBarModel.cs" />
<Compile Include="Models\LoginModel.cs" />
<Compile Include="Models\ModelBase.cs" />
<Compile Include="Models\NavigatorBarModel.cs" />
<Compile Include="Models\UserEntity.cs" />
<Compile Include="Models\QueryData.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
@ -211,6 +214,7 @@
<Content Include="Views\Shared\UnAuthorized.cshtml" />
<Content Include="Views\Shared\AwesomeIcon.cshtml" />
<Content Include="Views\Admin\FAIcon.cshtml" />
<Content Include="Views\Admin\Groups.cshtml" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>

View File

@ -39,8 +39,14 @@
bootstrapTable: 'table',
validateForm: 'dataForm',
modal: 'dialogNew',
click: {}
}
click: {
query: 'btn_query',
create: 'btn_add',
edit: 'btn_edit',
del: 'btn_delete',
save: 'btnSubmit'
}
};
BootstrapAdmin.idFormatter = function (value, row, index) {
return "<a class='edit' href='javascript:void(0)'>" + value + "</a>";

View File

@ -36,6 +36,19 @@ namespace Bootstrap.Admin.Controllers
///
/// </summary>
/// <returns></returns>
public ActionResult Groups()
{
var v = new NavigatorBarModel();
v.BreadcrumbName = "部门管理";
v.ShowMenu = "hide";
v.Menus[3].Active = "active";
v.HomeUrl = "~/Admin";
return View(v);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
[AllowAnonymous]
public ActionResult FAIcon()
{

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 GroupsController : ApiController
{
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
[HttpGet]
public QueryData<Group> Get([FromUri]QueryGroupOption value)
{
return value.RetrieveData();
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet]
public Group Get(int id)
{
return GroupHelper.RetrieveGroups().FirstOrDefault(t => t.ID == id);
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
[HttpPost]
public bool Post([FromBody]Group value)
{
return GroupHelper.SaveGroup(value);
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
[HttpDelete]
public bool Delete([FromBody]string value)
{
return GroupHelper.DeleteGroup(value);
}
}
}

View File

@ -16,12 +16,9 @@ namespace Bootstrap.Admin.Controllers
/// <param name="value"></param>
/// <returns></returns>
[HttpGet]
public UserEntity Get([FromUri]UsersPageOption value)
public QueryData<User> Get([FromUri]QueryUserOption value)
{
var ret = new UserEntity();
ret.RetrieveUsers(value);
return ret;
return value.RetrieveData();
}
/// <summary>
///

View File

@ -0,0 +1,11 @@
using System.Collections.Generic;
namespace Bootstrap.Admin.Models
{
public class QueryData<T> where T : class
{
public int total { get; set; }
public IEnumerable<T> rows { get; set; }
}
}

View File

@ -0,0 +1,41 @@
using Bootstrap.DataAccess;
using Longbow.Web.Mvc;
using System.Linq;
namespace Bootstrap.Admin.Models
{
public class QueryGroupOption : PaginationOption
{
/// <summary>
///
/// </summary>
public string GroupName { get; set; }
/// <summary>
///
/// </summary>
public string Description { get; set; }
/// <summary>
///
/// </summary>
/// <returns></returns>
public QueryData<Group> RetrieveData()
{
// int limit, int offset, string name, string price, string sort, string order
var data = GroupHelper.RetrieveGroups(string.Empty);
if (!string.IsNullOrEmpty(GroupName))
{
data = data.Where(t => t.GroupName.Contains(GroupName));
}
if (!string.IsNullOrEmpty(Description))
{
data = data.Where(t => t.Description.Contains(Description));
}
var ret = new QueryData<Group>();
ret.total = data.Count();
// TODO: 通过option.Sort属性判断对那列进行排序现在统一对名称列排序
data = Order == "asc" ? data.OrderBy(t => t.GroupName) : data.OrderByDescending(t => t.GroupName);
ret.rows = data.Skip(Offset).Take(Limit);
return ret;
}
}
}

View File

@ -0,0 +1,41 @@
using Bootstrap.DataAccess;
using Longbow.Web.Mvc;
using System.Linq;
namespace Bootstrap.Admin.Models
{
/// <summary>
///
/// </summary>
public class QueryUserOption : PaginationOption
{
/// <summary>
///
/// </summary>
public string Name { get; set; }
/// <summary>
///
/// </summary>
public string DisplayName { get; set; }
public QueryData<User> RetrieveData()
{
// int limit, int offset, string name, string price, string sort, string order
var data = UserHelper.RetrieveUsers(string.Empty);
if (!string.IsNullOrEmpty(Name))
{
data = data.Where(t => t.UserName.Contains(Name));
}
if (!string.IsNullOrEmpty(DisplayName))
{
data = data.Where(t => t.DisplayName.Contains(DisplayName));
}
var ret = new QueryData<User>();
ret.total = data.Count();
// TODO: 通过option.Sort属性判断对那列进行排序现在统一对名称列排序
data = Order == "asc" ? data.OrderBy(t => t.UserName) : data.OrderByDescending(t => t.UserName);
ret.rows = data.Skip(Offset).Take(Limit);
return ret;
}
}
}

View File

@ -1,28 +0,0 @@
using Bootstrap.DataAccess;
using Longbow.Web.Mvc;
using System.Collections.Generic;
using System.Linq;
namespace Bootstrap.Admin.Models
{
public class UserEntity
{
public int total { get; private set; }
public IEnumerable<User> rows { get; private set; }
public void RetrieveUsers(UsersPageOption option)
{
// int limit, int offset, string name, string price, string sort, string order
var data = UserHelper.RetrieveUsers(string.Empty);
if (!string.IsNullOrEmpty(option.Name))
{
data = data.Where(t => t.UserName.Contains(option.Name));
}
total = data.Count();
// TODO: 通过option.Sort属性判断对那列进行排序现在统一对名称列排序
data = option.Order == "asc" ? data.OrderBy(t => t.UserName) : data.OrderByDescending(t => t.UserName);
rows = data.Skip(option.Offset).Take(option.Limit);
}
}
}

View File

@ -1,12 +0,0 @@
using Longbow.Web.Mvc;
namespace Bootstrap.Admin.Models
{
/// <summary>
///
/// </summary>
public class UsersPageOption : PaginationOption
{
public string Name { get; set; }
}
}

View File

@ -0,0 +1,31 @@
$(function () {
var bsa = new BootstrapAdmin({
url: '../api/Groups',
dataEntity: new DataEntity({
map: {
ID: "groupID",
GroupName: "groupName",
Description: "groupDesc"
}
})
});
$('table').smartTable({
url: '../api/Groups', //请求后台的URL*
sortName: 'GroupName',
queryParams: function (params) { return $.extend(params, { groupName: $("#txt_search_name").val(), description: $("#txt_group_desc").val() }); }, //传递参数(*
columns: [{ checkbox: true },
{ title: "Id", field: "ID", events: bsa.idEvents(), formatter: BootstrapAdmin.idFormatter },
{ title: "部门名称", field: "GroupName", sortable: true },
{ title: "部门描述", field: "Description", sortable: true }
]
});
// validate
$('#dataForm').autoValidate({
groupName: {
required: true,
maxlength: 50
}
});
});

View File

@ -1,32 +1,24 @@
$(function () {
var dataEntity = new DataEntity({
map: {
ID: "userID",
UserName: "userName",
Password: "password",
DisplayName: "displayName"
}
});
var bsa = new BootstrapAdmin({
url: '../api/Users',
dataEntity: dataEntity,
click: {
query: 'btn_query',
create: 'btn_add',
edit: 'btn_edit',
del: 'btn_delete',
save: 'btnSubmit'
}
dataEntity: new DataEntity({
map: {
ID: "userID",
UserName: "userName",
Password: "password",
DisplayName: "displayName"
}
})
});
$('table').smartTable({
url: '../api/Users', //请求后台的URL*
sortName: 'UserName',
queryParams: function (params) { return $.extend(params, { name: $("#txt_search_name").val() }); }, //传递参数(*
queryParams: function (params) { return $.extend(params, { name: $("#txt_search_name").val(), displayName: $('#txt_display_name').val() }); }, //传递参数(*
columns: [{ checkbox: true },
{ title: "Id", field: "ID", events: bsa.idEvents(), formatter: BootstrapAdmin.idFormatter },
{ title: "用户名称", field: "UserName", sortable: true }
{ title: "登陆名称", field: "UserName", sortable: true },
{ title: "显示名称", field: "DisplayName", sortable: false }
]
});

View File

@ -0,0 +1,58 @@
@model NavigatorBarModel
@{
ViewBag.Title = "部门管理";
Layout = "~/Views/Shared/_Default.cshtml";
}
@section Javascript {
<script src="~/scripts/Groups.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_group_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="groupName">部门名称</label>
<input type="text" class="form-control" id="groupName" name="groupName" maxlength="50" />
</div>
<div class="form-group col-lg-6">
<label class="control-label" for="groupDesc">部门描述</label>
<input type="text" class="form-control" id="groupDesc" name="groupDesc" maxlength="50" />
<input type="text" class="form-control hide" id="groupID" name="groupID" />
</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

@ -53,15 +53,25 @@ namespace Bootstrap.DataAccess
/// 删除群组信息
/// </summary>
/// <param name="ids"></param>
public static void DeleteGroup(string ids)
public static bool DeleteGroup(string ids)
{
if (string.IsNullOrEmpty(ids) || ids.Contains("'")) return;
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Groups where ID in ({0})", ids);
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
var ret = false;
if (string.IsNullOrEmpty(ids) || ids.Contains("'")) return ret;
try
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
ClearCache();
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Groups where ID in ({0})", ids);
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
ClearCache();
ret = true;
}
}
catch (Exception ex)
{
ExceptionManager.Publish(ex);
}
return ret;
}
/// <summary>
/// 保存新建/更新的群组信息

View File

@ -30,7 +30,7 @@ namespace Bootstrap.DataAccess
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-home", Url="javascript:;", 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 = "" },
new Menu() { Name = "系统日志", Icon = "fa-lock", Url="javascript:;", Active = "" }