增加字典表维护功能

This commit is contained in:
renshuo 2016-10-29 16:46:02 +08:00
parent 96093f8d34
commit 9d1f5c1385
10 changed files with 190 additions and 68 deletions

View File

@ -223,6 +223,7 @@
<Content Include="Views\Admin\Groups.cshtml" />
<Content Include="Views\Admin\Roles.cshtml" />
<Content Include="Views\Admin\Menus.cshtml" />
<Content Include="Views\Admin\Dicts.cshtml" />
<Content Include="Views\Shared\Glyphicons.cshtml" />
<Content Include="Views\Shared\RoleConfig.cshtml" />
<Content Include="Views\Shared\IconView.cshtml" />

View File

@ -43,6 +43,19 @@ namespace Bootstrap.Admin.Controllers
v.HomeUrl = "~/Admin";
return View(v);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public ActionResult Dicts()
{
var v = new NavigatorBarModel();
v.ShowMenu = "hide";
v.Menus[4].Active = "active";
v.HomeUrl = "~/Admin";
return View(v);
}
public ActionResult Roles()
{
var v = new NavigatorBarModel();

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 DictsController : ApiController
{
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
[HttpGet]
public QueryData<Dict> Get([FromUri]QueryDictOption value)
{
return value.RetrieveData();
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet]
public Dict Get(int id)
{
return DictHelper.RetrieveDicts().FirstOrDefault(t => t.ID == id);
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
[HttpPost]
public bool Post([FromBody]Dict value)
{
return DictHelper.SaveDict(value);
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
[HttpDelete]
public bool Delete([FromBody]string value)
{
return DictHelper.DeleteDict(value);
}
}
}

View File

@ -1,65 +0,0 @@
using Bootstrap.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Mvc;
namespace Bootstrap.Controllers
{
public class TestController : ApiController
{
// GET api/<controller>
public Dummy Get(int limit, int offset, string name, string price, string sort, string order)
{
var p = new TerminalsModel();
var ret = new List<TerminalsModel>();
Random rnd = new Random();
for (int index = 1; index < 1000; index++)
{
ret.Add(new TerminalsModel() { Id = index.ToString(), Name = string.Format("Argo-{0:D4}", index), Price = index.ToString() });
}
if (!string.IsNullOrEmpty(name)) ret = ret.Where(n => n.Name.Contains(name)).ToList();
if (!string.IsNullOrEmpty(price)) ret = ret.Where(n => n.Price.Contains(price)).ToList();
if (!string.IsNullOrEmpty(sort))
{
if (sort.Equals("Name")) { ret = order == "desc" ? ret.OrderByDescending(n => n.Name).ToList() : ret.OrderBy(n => n.Name).ToList(); }
if (sort.Equals("Price")) { ret = order == "desc" ? ret.OrderByDescending(n => n.Price).ToList() : ret.OrderBy(n => n.Price).ToList(); }
}
var total = ret.Count;
var rows = ret.Skip(offset).Take(limit).ToList();
return new Dummy() { total = total, rows = rows };
}
public class Dummy
{
}
// GET api/<controller>/5
public string Get(int id)
{
return "value";
}
// POST api/<controller>
public string Post([FromBody]string value)
{
return "value";
}
// PUT api/<controller>/5
public void Put(int id, [FromBody]string value)
{
}
[System.Web.Mvc.HttpDelete]
// DELETE api/<controller>/5
public void Delete(int id)
{
}
}
}

View File

@ -0,0 +1,40 @@
using Bootstrap.DataAccess;
using Longbow.Web.Mvc;
using System.Linq;
namespace Bootstrap.Admin.Models
{
public class QueryDictOption : PaginationOption
{
/// <summary>
/// 字典名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 字典种类
/// </summary>
public string Category { get; set; }
/// <summary>
/// 字典表查询
/// </summary>
/// <returns></returns>
public QueryData<Dict> RetrieveData()
{
var data = DictHelper.RetrieveDicts(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<Dict>();
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;
}
}
}

View File

@ -0,0 +1,33 @@
$(function () {
var bsa = new BootstrapAdmin({
url: '../api/Dicts',
dataEntity: new DataEntity({
map: {
ID: "dictID",
Category: "dictCate",
Name: "dictName",
Code: "dictCode"
}
})
});
$('table').smartTable({
url: '../api/Dicts', //请求后台的URL*
sortName: 'Category',
queryParams: function (params) { return $.extend(params, { name: $("#txt_dict_name").val(), category: $("#txt_dict_cate").val() }); },
columns: [{ checkbox: true },
{ title: "Id", field: "ID", events: bsa.idEvents(), formatter: BootstrapAdmin.idFormatter },
{ title: "字典种类", field: "Category", sortable: true },
{ title: "字典名称", field: "Name", sortable: false },
{ title: "字典代码", field: "Code", sortable: false }
]
});
// validate
$('#dataForm').autoValidate({
groupName: {
required: true,
maxlength: 50
}
});
});

View File

@ -0,0 +1,52 @@
@model NavigatorBarModel
@{
ViewBag.Title = "字典表管理";
Layout = "~/Views/Shared/_Default.cshtml";
}
@section Javascript {
<script src="~/scripts/Dicts.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_dict_name">字典名称</label>
<input type="text" class="form-control" id="txt_dict_name" />
</div>
<div class="form-group col-lg-5">
<label class="control-label" for="txt_dict_cate">字典种类</label>
<input type="text" class="form-control" id="txt_dict_cate" />
</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-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="dictCate">字典种类</label>
<input type="text" class="form-control" id="dictCate" name="dictCate" maxlength="50" />
</div>
<div class="form-group col-lg-6">
<label class="control-label" for="dictName">字典名称</label>
<input type="text" class="form-control" id="dictName" name="dictName" maxlength="50" />
<input type="text" class="form-control hide" id="dictID" name="dictID" />
</div>
<div class="form-group col-lg-6">
<label class="control-label" for="dictCode">字典代码</label>
<input type="text" class="form-control" id="dictCode" name="dictCode" maxlength="50" />
</div>
</form>
</div>
}

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net45" />

View File

@ -2,7 +2,6 @@
{
/// <summary>
/// 字典表实体
/// Category与Code自关联
/// author:renshuo
/// date:2016.10.27
/// </summary>

View File

@ -249,7 +249,7 @@ insert into Navigations (ID, Name, [Order], Icon, Url) values (1, '菜单管理'
insert into Navigations (ID, Name, [Order], Icon, Url) values (2, '用户管理', 20, 'fa fa-user', '~/Admin/Users')
insert into Navigations (ID, Name, [Order], Icon, Url) values (3, '角色管理', 30, 'fa fa-sitemap', '~/Admin/Roles')
insert into Navigations (ID, Name, [Order], Icon, Url) values (4, '部门管理', 40, 'fa fa-home', '~/Admin/Groups')
insert into Navigations (ID, Name, [Order], Icon, Url) values (5, '字典表维护', 50, 'fa fa-book', '~/Admin/Dict')
insert into Navigations (ID, Name, [Order], Icon, Url) values (5, '字典表维护', 50, 'fa fa-book', '~/Admin/Dicts')
insert into Navigations (ID, Name, [Order], Icon, Url) values (6, '个性化维护', 60, 'fa fa-pencil', '~/Admin/Profiles')
insert into Navigations (ID, Name, [Order], Icon, Url) values (7, '系统日志', 70, 'fa fa-gears', '~/Admin/EventLog')
SET IDENTITY_INSERT Navigations OFF