增加分类管理

This commit is contained in:
yubaolee 2017-11-29 21:32:55 +08:00
parent b7a72f62c0
commit c026f263f8
17 changed files with 490 additions and 16 deletions

View File

@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenAuth.App;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository.Domain;
namespace LwSolution.App
{
/// <summary>
/// 分类管理
/// </summary>
public class CategoryApp :BaseApp<Category>
{
public IEnumerable<Category> Get(string type)
{
return UnitWork.Find<Category>(u => u.TypeId == type);
}
public void Add(Category category)
{
if (string.IsNullOrEmpty(category.Id))
{
category.Id = Guid.NewGuid().ToString();
}
UnitWork.Add(category);
UnitWork.Save();
}
public void Update(Category category)
{
UnitWork.Update<Category>(u =>u.Id,category);
UnitWork.Save();
}
public void Delete(string[] ids)
{
UnitWork.Delete<Category>(u => ids.Contains(u.Id));
}
public TableData All(QueryCategoriesReq request)
{
var result = new TableData();
var categories = UnitWork.Find<Category>(null) ;
if (!string.IsNullOrEmpty(request.key))
{
categories = categories.Where(u => u.Name.Contains(request.key) || u.Id.Contains(request.key));
}
if (!string.IsNullOrEmpty(request.TypeId))
{
categories = categories.Where(u => u.TypeId == request.TypeId);
}
var query = from category in categories
join ct in UnitWork.Find<CategoryType>(null) on category.TypeId equals ct.Id
into tmp
from ct in tmp.DefaultIfEmpty()
select new
{
category.Name,
category.Id,
category.TypeId,
TypeName = ct.Name,
category.Description
};
result.data = query.OrderBy(u => u.TypeId)
.Skip((request.page - 1) * request.limit)
.Take(request.limit).ToList();
result.count = categories.Count();
return result;
}
public List<CategoryType> AllTypes()
{
return UnitWork.Find<CategoryType>(null).ToList();
}
}
}

View File

@ -1,6 +1,4 @@
using System; namespace OpenAuth.App.Extention
namespace OpenAuth.App.Extention
{ {
public class WF_RuntimeInitModel public class WF_RuntimeInitModel

View File

@ -83,13 +83,16 @@
<Compile Include="AuthoriseService.cs" /> <Compile Include="AuthoriseService.cs" />
<Compile Include="BaseApp.cs" /> <Compile Include="BaseApp.cs" />
<Compile Include="AuthorizeApp.cs" /> <Compile Include="AuthorizeApp.cs" />
<Compile Include="CategoryApp.cs" />
<Compile Include="Extention\IWF_Runtime.cs" /> <Compile Include="Extention\IWF_Runtime.cs" />
<Compile Include="Extention\WF_Runtime.cs" /> <Compile Include="Extention\WF_Runtime.cs" />
<Compile Include="Extention\WF_RuntimeInitModel.cs" /> <Compile Include="Extention\WF_RuntimeInitModel.cs" />
<Compile Include="Extention\WF_RuntimeModel.cs" /> <Compile Include="Extention\WF_RuntimeModel.cs" />
<Compile Include="Request\IdPageReq.cs" /> <Compile Include="Request\IdPageReq.cs" />
<Compile Include="Request\PageReq.cs" /> <Compile Include="Request\PageReq.cs" />
<Compile Include="Request\QueryCategoriesReq.cs" />
<Compile Include="Request\QueryUserListReq.cs" /> <Compile Include="Request\QueryUserListReq.cs" />
<Compile Include="Response\TableData.cs" />
<Compile Include="RevelanceManagerApp.cs" /> <Compile Include="RevelanceManagerApp.cs" />
<Compile Include="SystemAuthService.cs" /> <Compile Include="SystemAuthService.cs" />
<Compile Include="WFFormService.cs" /> <Compile Include="WFFormService.cs" />
@ -129,9 +132,7 @@
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup />
<Folder Include="Response\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

View File

@ -0,0 +1,16 @@
namespace OpenAuth.App.Request
{
public class QueryCategoriesReq : PageReq
{
/// <summary>
/// 是否审核all全部 true:已审核false未审核
/// </summary>
public string Checked { get; set; }
/// <summary>
/// TypeID
/// </summary>
public string TypeId { get; set; }
}
}

View File

@ -0,0 +1,41 @@
// ***********************************************************************
// Assembly : FundationAdmin
// Author : yubaolee
// Created : 03-09-2016
//
// Last Modified By : yubaolee
// Last Modified On : 03-09-2016
// ***********************************************************************
// <copyright file="TableData.cs" company="Microsoft">
// 版权所有(C) Microsoft 2015
// </copyright>
// <summary>layui datatable数据返回</summary>
// ***********************************************************************
namespace OpenAuth.App.Response
{
/// <summary>
/// table的返回数据
/// </summary>
public class TableData
{
/// <summary>
/// 状态码
/// </summary>
public int code;
/// <summary>
/// 操作消息
/// </summary>
public string msg;
/// <summary>
/// 总记录条数
/// </summary>
public int count;
/// <summary>
/// 数据内容
/// </summary>
public dynamic data;
}
}

View File

@ -1,7 +1,6 @@
using System; using System;
using System.Web; using System.Web;
using System.Web.Mvc; using System.Web.Mvc;
using Infrastructure;
using Infrastructure.Cache; using Infrastructure.Cache;
using OpenAuth.Repository.Domain; using OpenAuth.Repository.Domain;

View File

@ -1,5 +1,4 @@
using System; using Infrastructure;
using Infrastructure;
using System.Collections.Generic; using System.Collections.Generic;
using OpenAuth.Repository.Domain; using OpenAuth.Repository.Domain;

View File

@ -12,7 +12,6 @@
// <summary>角色模型视图</summary> // <summary>角色模型视图</summary>
// *********************************************************************** // ***********************************************************************
using System;
using Infrastructure; using Infrastructure;
using OpenAuth.Repository.Domain; using OpenAuth.Repository.Domain;

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using Infrastructure; using Infrastructure;
using OpenAuth.Repository.Domain; using OpenAuth.Repository.Domain;

View File

@ -13,7 +13,6 @@
// *********************************************************************** // ***********************************************************************
using System.Collections.Generic; using System.Collections.Generic;
using Infrastructure;
using OpenAuth.Repository.Domain; using OpenAuth.Repository.Domain;

View File

@ -1,5 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenAuth.App.ViewModel; using OpenAuth.App.ViewModel;
using OpenAuth.Repository.Domain; using OpenAuth.Repository.Domain;

View File

@ -0,0 +1,86 @@
using System;
using System.Web.Http;
using System.Web.Mvc;
using Infrastructure;
using LwSolution.App;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository.Domain;
namespace OpenAuth.Mvc.Controllers
{
public class CategoriesController : BaseController
{
public CategoryApp App { get; set; }
//
// GET: /UserManager/
public ActionResult Index()
{
return View();
}
public string All([FromUri]QueryCategoriesReq request)
{
TableData data = new TableData();
data = App.All(request);
return JsonHelper.Instance.Serialize(data);
}
[System.Web.Mvc.HttpPost]
public string Delete(string[] ids)
{
Response resp = new Response();
try
{
App.Delete(ids);
}
catch (Exception e)
{
resp.Code = 500;
resp.Message = e.Message;
}
return JsonHelper.Instance.Serialize(resp);
}
[System.Web.Mvc.HttpPost]
public string Add(Category obj)
{
Response resp = new Response();
try
{
App.Add(obj);
}
catch (Exception e)
{
resp.Code = 500;
resp.Message = e.Message;
}
return JsonHelper.Instance.Serialize(resp);
}
[System.Web.Mvc.HttpPost]
public string Update(Category obj)
{
Response resp = new Response();
try
{
App.Update(obj);
}
catch (Exception e)
{
resp.Code = 500;
resp.Message = e.Message;
}
return JsonHelper.Instance.Serialize(resp);
}
//所有得分类类型
public string AllTypes()
{
var data = App.AllTypes();
return JsonHelper.Instance.Serialize(data);
}
}
}

View File

@ -148,6 +148,7 @@
<Compile Include="Areas\FlowManage\FlowManageAreaRegistration.cs" /> <Compile Include="Areas\FlowManage\FlowManageAreaRegistration.cs" />
<Compile Include="AutofacExt.cs" /> <Compile Include="AutofacExt.cs" />
<Compile Include="Controllers\BaseController.cs" /> <Compile Include="Controllers\BaseController.cs" />
<Compile Include="Controllers\CategoriesController.cs" />
<Compile Include="Controllers\ErrorController.cs" /> <Compile Include="Controllers\ErrorController.cs" />
<Compile Include="Areas\FlowManage\Controllers\FlowInstancesController.cs" /> <Compile Include="Areas\FlowManage\Controllers\FlowInstancesController.cs" />
<Compile Include="Controllers\HomeController.cs" /> <Compile Include="Controllers\HomeController.cs" />
@ -170,6 +171,7 @@
<Content Include="BllScripts\categoryManager.js" /> <Content Include="BllScripts\categoryManager.js" />
<Content Include="BllScripts\formDesign.js" /> <Content Include="BllScripts\formDesign.js" />
<Content Include="BllScripts\login.js" /> <Content Include="BllScripts\login.js" />
<Content Include="js\categories.js" />
<Content Include="js\openauth.js" /> <Content Include="js\openauth.js" />
<Content Include="js\droptree.js" /> <Content Include="js\droptree.js" />
<Content Include="BllScripts\processDetail.js" /> <Content Include="BllScripts\processDetail.js" />
@ -368,6 +370,7 @@
<Content Include="Views\Home\Main.cshtml" /> <Content Include="Views\Home\Main.cshtml" />
<Content Include="Views\Shared\_Layout.cshtml" /> <Content Include="Views\Shared\_Layout.cshtml" />
<Content Include="Views\Home\MenuHeader.cshtml" /> <Content Include="Views\Home\MenuHeader.cshtml" />
<Content Include="Views\Categories\Index.cshtml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="App_Data\" /> <Folder Include="App_Data\" />

View File

@ -0,0 +1,91 @@
@section header
{
<link rel="stylesheet" href="/css/treetable.css" />
}
<blockquote class="layui-elem-quote news_search toolList">
<div class="layui-inline">
<div class="layui-input-inline">
<input class="layui-input" placeholder="请输入关键字"
name="key" id="key" autocomplete="off">
</div>
<button class="layui-btn" data-type="search">搜索</button>
</div>
<button class="layui-btn " data-type="refresh">刷新</button>
<button class="layui-btn " data-type="btnAdd">添加</button>
<button class="layui-btn " data-type="btnEdit">编辑</button>
<button class="layui-btn layui-btn-danger" data-type="btnDel">批量删除</button>
</blockquote>
<div style="display: flex;">
<ul id="tree" class="ztree" style="display: inline-block; width: 180px; padding: 10px; border: 1px solid #ddd; overflow: auto;"></ul>
<table class="layui-table"
lay-data="{height: 'full-80', page:true, id:'mainList'}"
lay-filter="list">
<thead>
<tr>
<th lay-data="{checkbox:true, fixed: true}"></th>
<th lay-data="{field:'Id', width:180}">ID</th>
<th lay-data="{field:'Name', width:180}">类型名称</th>
<th lay-data="{field:'TypeId', width:180}">类型分类</th>
<th lay-data="{field:'TypeName', width:180}">类型分类</th>
<th lay-data="{field:'Description', width:180}">描述</th>
<th lay-data="{fixed: 'right', width:160, align:'center', toolbar: '#barList'}"></th>
</tr>
</thead>
</table>
</div>
<script type="text/html" id="barList">
@*<a class="layui-btn layui-btn-primary layui-btn-mini" lay-event="detail">查看</a>*@
<a class="layui-btn layui-btn-mini" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">删除</a>
</script>
<!--用户添加/编辑窗口-->
<div id="divEdit" style="display: none">
<form class="layui-form" action="" id="formEdit">
<div class="layui-form-item">
<label class="layui-form-label">类型标识</label>
<div class="layui-input-block">
<input type="text" name="Id" v-model="Id" required lay-verify="required"
placeholder="请输入类型标识" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">名称</label>
<div class="layui-input-block">
<input type="text" name="Name" v-model="Name" required lay-verify="required"
placeholder="请输入名称" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">类型分类</label>
<div class="layui-input-block">
<input id="TypeName" name="TypeName" v-model="TypeName" required lay-verify="required" class="layui-input" />
<input id="TypeId" name="TypeId" v-model="TypeId" required lay-verify="required" type="hidden" />
<div id="menuContent" class="menuContent" style="display: none;">
<ul id="org" class="ztree"></ul>
</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">描述</label>
<div class="layui-input-block">
<input type="text" name="Description" v-model="Description"
placeholder="请输入描述" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit lay-filter="formSubmit">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</div>
</form>
</div>
<script type="text/javascript" src="/layui/layui.js"></script>
<script type="text/javascript" src="/js/categories.js"></script>

View File

@ -0,0 +1,153 @@
layui.config({
base: "/js/"
}).use(['form','vue', 'ztree', 'layer', 'jquery', 'table','droptree','openauth'], function () {
var form = layui.form,
//layer = (parent == undefined || parent.layer === undefined )? layui.layer : parent.layer,
layer = layui.layer,
$ = layui.jquery;
var table = layui.table;
var openauth = layui.openauth;
layui.droptree("/Categories/AllTypes", "#TypeName", "#TypeId", false);
//主列表加载,可反复调用进行刷新
var config= {}; //table的参数如搜索key点击tree的id
var mainList = function (options) {
if (options != undefined) {
$.extend(config, options);
}
table.reload('mainList', {
url: '/Categories/All',
where: config
});
}
//左边树状机构列表
var ztree = function () {
var url = '/Categories/AllTypes';
var zTreeObj;
var setting = {
view: { selectedMulti: false },
data: {
key: {
name: 'Name',
title: 'Name'
},
simpleData: {
enable: true,
idKey: 'Id',
pIdKey: 'ParentId',
rootPId: 'null'
}
},
callback: {
onClick: function (event, treeId, treeNode) {
mainList({ typeId: treeNode.Id });
}
}
};
var load = function () {
$.getJSON(url, function (json) {
zTreeObj = $.fn.zTree.init($("#tree"), setting, json);
mainList({ typeId: json[0].Id });
zTreeObj.expandAll(true);
});
};
load();
return {
reload: load
}
}();
//添加(编辑)对话框
var editDlg = function() {
var vm = new Vue({
el: "#formEdit"
});
var update = false; //是否为更新
var show = function (data) {
var title = update ? "编辑信息" : "添加";
layer.open({
title: title,
area: ["500px", "400px"],
type: 1,
content: $('#divEdit'),
success: function() {
vm.$set('$data', data);
},
end: mainList
});
var url = "/Categories/Add";
if (update) {
url = "/Categories/Update"; //暂时和添加一个地址
}
//提交数据
form.on('submit(formSubmit)',
function(data) {
$.post(url,
data.field,
function(data) {
layer.msg(data.Message);
},
"json");
return false;
});
}
return {
add: function() { //弹出添加
update = false;
show({
Id: ''
});
},
update: function(data) { //弹出编辑框
update = true;
show(data);
}
};
}();
//监听表格内部按钮
table.on('tool(list)', function (obj) {
var data = obj.data;
if (obj.event === 'detail') { //查看
layer.msg('ID' + data.Id + ' 的查看操作');
}
});
//监听页面主按钮操作
var active = {
btnDel: function () { //批量删除
var checkStatus = table.checkStatus('mainList')
, data = checkStatus.data;
openauth.del("/Categories/Delete",
data.map(function (e) { return e.Id; }),
mainList);
}
, btnAdd: function () { //添加
editDlg.add();
}
, btnEdit: function () { //编辑
var checkStatus = table.checkStatus('mainList')
, data = checkStatus.data;
if (data.length != 1) {
layer.msg("请选择编辑的行,且同时只能编辑一行");
return;
}
editDlg.update(data[0]);
}
, search: function () { //搜索
mainList({ key: $('#key').val() });
}
, btnRefresh: function() {
mainList();
}
};
$('.toolList .layui-btn').on('click', function () {
var type = $(this).data('type');
active[type] ? active[type].call(this) : '';
});
//监听页面主按钮操作 end
})

View File

@ -62,7 +62,10 @@ namespace OpenAuth.Repository
public void Add(T entity) public void Add(T entity)
{ {
entity.Id = Guid.NewGuid().ToString(); if (string.IsNullOrEmpty(entity.Id))
{
entity.Id = Guid.NewGuid().ToString();
}
Context.Set<T>().Add(entity); Context.Set<T>().Add(entity);
Save(); Save();
} }

View File

@ -62,7 +62,10 @@ namespace OpenAuth.Repository
public void Add<T>(T entity) where T : Domain.Entity public void Add<T>(T entity) where T : Domain.Entity
{ {
entity.Id = Guid.NewGuid().ToString(); if (string.IsNullOrEmpty(entity.Id))
{
entity.Id = Guid.NewGuid().ToString();
}
Context.Set<T>().Add(entity); Context.Set<T>().Add(entity);
} }