完成分类列表处理

This commit is contained in:
yubaolee 2016-10-14 17:03:18 +08:00
parent 9606a71f72
commit 7f7c0f891a
14 changed files with 710 additions and 288 deletions

View File

@ -1,22 +1,23 @@
using System;
using Infrastructure;
using OpenAuth.App.ViewModel;
using OpenAuth.Domain;
using OpenAuth.Domain.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using Infrastructure;
namespace OpenAuth.App
{
public class CategoryManagerApp
{
private ICategoryRepository _repository;
private IOrgRepository _orgRepository;
private IUnitWork _unitWork;
public CategoryManagerApp(ICategoryRepository repository,
IOrgRepository orgRepository)
IUnitWork unitWork)
{
_repository = repository;
_orgRepository = orgRepository;
_unitWork = unitWork;
}
public int GetCategoryCntInOrg(Guid orgId)
@ -37,29 +38,45 @@ namespace OpenAuth.App
}
/// <summary>
/// 加载一个部门及子部门全部Categorys
/// 加载一个分类及子分类全部Categorys
/// </summary>
public dynamic Load(Guid parentId, int pageindex, int pagesize)
public GridData Load(Guid parentId, int pageindex, int pagesize)
{
IEnumerable<Category> Categorys;
IQueryable<Category> categories;
int total = 0;
if (parentId == Guid.Empty)
{
Categorys = _repository.LoadCategorys(pageindex, pagesize);
categories = _unitWork.Find<Category>(pageindex, pagesize);
total = _repository.GetCount();
}
else
{
var ids = GetSubCategories(parentId);
Categorys = _repository.LoadInOrgs(pageindex, pagesize, ids);
categories = _unitWork.Find<Category>(pageindex, pagesize, "SortNo", u => ids.Contains(u.Id));
total = _repository.GetCategoryCntInOrgs(ids);
}
return new
var query = from c in categories
join category in _unitWork.Find<Category>(null) on c.ParentId equals category.Id into temp
from category in temp.DefaultIfEmpty()
select new
{
c.CascadeId,
c.Name,
c.ParentId,
ParentName = category.Name,
c.SortNo,
c.RootName,
c.RootKey,
c.Status,
c.Id
};
return new GridData()
{
total = total,
list = Categorys,
pageCurrent = pageindex
records = total,
total = (int)Math.Ceiling((double)total/pagesize),
rows = query.ToList(),
page = pageindex
};
}
@ -68,7 +85,7 @@ namespace OpenAuth.App
/// </summary>
private Guid[] GetSubCategories(Guid orgId)
{
var category = Find(orgId);
var category = Find(orgId);
var categories = _repository.Find(u => u.CascadeId.Contains(category.CascadeId)).Select(u => u.Id).ToArray();
return categories;
}
@ -81,14 +98,14 @@ namespace OpenAuth.App
return category;
}
public void Delete(Guid id)
public void Delete(Guid[] ids)
{
_repository.Delete(id);
_repository.Delete(u =>ids.Contains(u.Id));
}
public void AddOrUpdate(Category model)
{
Category category = new Category();
Category category = new Category();
model.CopyTo(category);
ChangeModuleCascade(category);
@ -116,7 +133,7 @@ namespace OpenAuth.App
if (currentCascadeId <= objCascadeId) currentCascadeId = objCascadeId + 1;
}
if (org.ParentId != Guid.Empty)
if (org.ParentId != null && org.ParentId != Guid.Empty)
{
var parentOrg = _repository.FindSingle(o => o.Id == org.ParentId);
if (parentOrg != null)

View File

@ -134,7 +134,7 @@ namespace OpenAuth.App
if (currentCascadeId <= objCascadeId) currentCascadeId = objCascadeId + 1;
}
if (org.ParentId != Guid.Empty)
if (org.ParentId != null && org.ParentId != Guid.Empty)
{
var parentOrg = _repository.FindSingle(o => o.Id == org.ParentId);
if (parentOrg != null)

View File

@ -11,74 +11,13 @@
// <summary>分类管理</summary>
// ***********************************************************************
//grid列表模块
function MainGrid() {
var url = '/CategoryManager/Load?parentId=';
var selectedId = '00000000-0000-0000-0000-000000000000'; //ztree选中的模块
this.maingrid = $('#maingrid').datagrid({
showToolbar: false,
loadType: 'GET',
filterThead: false,
target: $(this),
columns: [
{name: 'Id',label: '资源表ID',hide: true},
{
name: 'CascadeId',
label: '节点语义ID',
width: 100
},
{
name: 'Name',
label: '名称',
width: 100
},
{
name: 'ParentId',
label: '父节点流水号',
width: 100
},
{
name: 'Status',
label: '当前状态',
width: 100,
align: 'center',
items: [{ '0': '默认' }, { '1': '删除' }]
},
{
name: 'SortNo',
label: '排序号',
width: 100,
align: 'center',
},
{
name: 'RootKey',
label: '从属行业标识',
width: 100
},
{
name: 'RootName',
label: '从属行业名称',
width: 100
},
],
dataUrl: url + selectedId,
fullGrid: true,
showLinenumber: true,
showCheckboxcol: true,
paging: true,
filterMult: false,
showTfoot: false,
$(function () {
$("#ParentName").on("click", function () {
parent.reload();
});
this.reload = function (id) {
if (id != undefined) selectedId = id;
this.maingrid.datagrid('reload', { dataUrl: url+ selectedId });
};
};
MainGrid.prototype = new Grid();
var list = new MainGrid();
});
//左边分类导航
//左边导航
var ztree = function () {
var url = '/CategoryManager/LoadForTree';
var setting = {
@ -95,39 +34,106 @@ var ztree = function () {
rootPId: 'null'
}
},
callback: { onClick: zTreeOnClick }
callback: {
onClick: function (event, treeId, treeNode) {
list.reload(treeNode.Id);
}
}
};
$.getJSON(url, function (json) {
$.fn.zTree.init($("#tree"), setting, json).expandAll(true);
});
function zTreeOnClick(event, treeId, treeNode) {
list.reload(treeNode.Id);
}
var load = function () {
$.getJSON(url, function (json) {
var zTreeObj = $.fn.zTree.init($("#orgtree"), setting, json);
list.reload();
zTreeObj.expandAll(true);
});
};
load();
return {
reload:function() {
$.getJSON(url, function (json) {
$.fn.zTree.init($("#tree"), setting, json).expandAll(true);
});
}
reload: load
}
}();
//grid列表模块
function MainGrid() {
var url = '/CategoryManager/Load?parentId=';
var selectedId = '00000000-0000-0000-0000-000000000000'; //ztree选中的模块
this.maingrid = $('#maingrid')
.jqGrid({
colModel: [
{
name: 'Id',
index: 'Id',
hidden: true
},
{
index: 'CascadeId',
name: 'CascadeId',
label: '节点语义ID'
},
{
index: 'Name',
name: 'Name',
label: '分类名称'
},
{
index: 'ParentName',
name: 'ParentName',
label: '上级分类'
},
{
index: 'ParentId',
name: 'ParentId',
hidden: true
},
//编辑时,选择上级弹出的树
var parentTree = function () {
var nameDom = "#ParentName";
var idDom = "#ParentId";
{
index: 'SortNo',
name: 'SortNo',
label: '排序号'
}
],
url: url + selectedId,
datatype: "json",
viewrecords: true,
rowNum: 18,
pager: "#grid-pager",
altRows: true,
height: 'auto',
multiselect: true,
multiboxonly: true,
loadComplete: function () {
var table = this;
setTimeout(function () {
updatePagerIcons(table);
},
0);
}
}).jqGrid('navGrid', "#grid-pager", {
edit: false, add: false, del: false, refresh: false, search: false
});
this.reload = function (id) {
if (id != undefined) selectedId = id;
this.maingrid.jqGrid("setGridParam", { url: url + selectedId })
.trigger("reloadGrid", [{ page: 1 }]); //重载JQGrid
};
};
MainGrid.prototype = new Grid();
var list = new MainGrid();
var vm = new Vue({
el: '#editDlg'
});
//上级机构选择框
var parent = function () { //ztree搜索框
var zTreeObj;
var setting = {
view: {
selectedMulti: false
},
check: {
enable: true,
chkStyle: "radio", //单选
radioType: "all"
},
view: { selectedMulti: false },
data: {
key: {
name: 'Name',
@ -141,112 +147,113 @@ var parentTree = function () {
}
},
callback: {
onClick: zTreeOnClick,
onCheck: zTreeCheck
onClick: onClick
}
};
var showMenu = function () {
$("#menuContent").css({ left: "10px", top: $("#ParentName").outerHeight() + "px" }).slideDown("fast");
$("body").bind("mousedown", onBodyDown);
};
function onClick(e, treeId, treeNode) {
var nodes = zTreeObj.getSelectedNodes();
function zTreeCheck(event, treeId, treeNode) {
var nodes = zTreeObj.getCheckedNodes(true);
var ids = nodes.map(function (e) { return e.Id; }).join(",");
var names = nodes.map(function (e) { return e.Name; }).join(",");
$(nameDom).val(names);
$(idDom).val(ids);
for (var i = 0, l = nodes.length; i < l; i++) {
vm.$set('ParentName', nodes[i].Name);
vm.$set('ParentId', nodes[i].Id);
break;
}
hideMenu();
}
function zTreeOnClick(event, treeId, treeNode) {
zTreeObj.checkNode(treeNode, !treeNode.checked, true, true);
event.preventDefault();
function onBodyDown(event) {
if (!(event.target.id == "menuContent" || $(event.target).parents("#menuContent").length > 0)) {
hideMenu();
}
}
function hideMenu() {
$("#menuContent").fadeOut("fast");
$("body").unbind("mousedown", onBodyDown);
}
return {
show:function() {
$.getJSON('/CategoryManager/LoadForTree', function (json) {
zTreeObj = $.fn.zTree.init($('#j_select_tree1'), setting, json);
var orgstr = $(idDom).val();
var name = '';
if (orgstr != '') {
var nodeIds = orgstr.split(',');
$.each(nodeIds, function () {
var node = zTreeObj.getNodeByParam("Id", this, null);
name += ',' + node.Name;
zTreeObj.checkNode(node, true, true);
});
$(nameDom).val(name.substr(1)); //显示名称
reload: function () {
var index = layer.load();
$.getJSON("/CategoryManager/LoadForTree", {
page: 1, rows: 10000
}, function (json) {
layer.close(index);
if (json.length == 0) {
vm.$set('ParentName', '');
vm.$set('ParentId', '');
return;
}
zTreeObj = $.fn.zTree.init($("#org"), setting, json);
zTreeObj.expandAll(true);
showMenu();
});
}
};
}
}();
//添加(编辑)对话框
var editDlg = function () {
var update = false;
var show = function () {
BJUI.dialog({ id: 'editDlg', title: '分类管理', target: '#editDlg' });
$("#btnSave").on("click", function() {
editDlg.save();
layer.open({
type: 1,
skin: 'layui-layer-rim', //加上边框
title: "用户管理", //不显示标题
area: ['400px', '300px'], //宽高
content: $('#editDlg'), //捕获的元素
btn: ['保存', '关闭'],
yes: function (index, layero) {
$.post("/CategoryManager/Add", vm.$data, function (data) {
layer.msg(data.Message);
if (data.Status) {
list.reload();
ztree.reload();
}
}, "json");
},
cancel: function (index) {
layer.close(index);
}
});
}
return {
add: function () { //弹出添加
update = false;
show();
$.CurrentDialog.find("form")[0].reset(); //reset方法只能通过dom调用
$("#Id").val('00000000-0000-0000-0000-000000000000');
$("#SortNo").val(0);
parentTree.show();
vm.$set('$data', {
Id: '00000000-0000-0000-0000-000000000000',
SortNo: 0
});
},
update: function (ret) { //弹出编辑框
update = true;
show();
$("#Id").val(ret.Id);
$("#Name").val(ret.Name);
$("#ParentId").val(ret.ParentId);
$('#Status').selectpicker('val', ret.Status);
$("#SortNo").val(ret.SortNo);
$("#RootKey").val(ret.RootKey);
$("#RootName").val(ret.RootName);
parentTree.show();
},
save: function() { //编辑-->保存
$('#editForm').isValid(function (v) {
if (!v) return; //验证没通过
$("#editForm").bjuiajax('ajaxForm', {
reload: false,
callback: function (json) {
if (json.statusCode == "400") {
$(this).alertmsg('warn', json.message);
return null;
}
list.reload();
ztree.reload();
}
});
});
vm.$set('$data', ret);
}
};
}();
//删除
function del() {
var selected = list.getSelectedObj();
var selected = list.getSelectedProperties("Id");
if (selected == null) return;
$.post('/CategoryManager/Delete?Id=' + selected.Id, function (data) {
if (data.statusCode == "200") {
$.post('/CategoryManager/Delete',
{ ids: selected },
function (data) {
if (data.Status) {
list.reload();
ztree.reload();
}
else {
$(this).alertmsg('warn', data.message);
layer.msg(data.Message);
}
}, "json");
}
//编辑
//自定义的编辑按钮
function edit() {
var selected = list.getSelectedObj();
if (selected == null) {
@ -255,14 +262,10 @@ function edit() {
editDlg.update(selected);
}
//添加
function add() {
editDlg.add();
}
//刷新
function refresh() {
list.reload();
}
//@@ sourceURL=categoryManager.js
}

View File

@ -13,16 +13,17 @@
// ***********************************************************************
function Grid() {
this.maingrid = undefined;
this.selectObjs = function () {
var ids = this.maingrid.jqGrid('getGridParam', 'selarrrow');
if (ids.length == 0) {
return null;
}
var ret = new Array();
var maingrid = this.maingrid;
$(ids).each(function () {
var obj = this.maingrid.jqGrid('getRowData', this);
ret.push(obj.Account);
var obj =maingrid.jqGrid('getRowData', this);
ret.push(obj);
});
return ret;
};

View File

@ -4,7 +4,7 @@
});
});
//左边分类导航
//左边导航
var ztree = function () {
var url = '/OrgManager/LoadOrg';
var setting = {
@ -212,6 +212,7 @@ var editDlg = function () {
show();
vm.$set('$data', null);
vm.$set('Id', '00000000-0000-0000-0000-000000000000');
vm.$set('SortNo', 0);
},
update: function (ret) { //弹出编辑框
update = true;
@ -252,6 +253,4 @@ function add() {
function refresh() {
list.reload();
}
//@@ sourceURL=OrgManager.js
}

View File

@ -54,12 +54,12 @@ namespace OpenAuth.Mvc.Controllers
}
return JsonHelper.Instance.Serialize(Result);
}
public string Delete(Guid Id)
[HttpPost]
public string Delete(Guid[] ids)
{
try
{
_app.Delete(Id);
_app.Delete(ids);
}
catch (Exception e)
{

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 421 B

View File

@ -2,80 +2,86 @@
Layout = "~/Views/Shared/_Layout.cshtml";
}
@{ Html.RenderAction("MenuHeader", "Home");}
<div class="bjui-pageContent tableContent" style="position: relative">
<div class="clearfix">
<div style="float: left; width: 220px; overflow: auto;" class="table table-bordered">
<ul id="tree" class="ztree"></ul>
</div>
<div id="detail" style="margin-left: 225px;">
<table id="maingrid" class="table table-bordered"></table>
</div>
</div>
<!-- #section:basics/content.breadcrumbs -->
<div class="breadcrumbs" id="breadcrumbs">
<ul class="breadcrumb">
<li>
<i class="ace-icon fa fa-home home-icon"></i>
<a href="#">分类管理</a>
</li>
<li class="active">列表</li>
</ul><!-- /.breadcrumb -->
</div>
<!-- /section:basics/content.breadcrumbs -->
<div class="page-content">
<div class="row">
<div class="col-md-12">
<div class="col-md-3">
<div class="widget-box widget-color-blue">
<div class="widget-header">
</div>
<div class="widget-body">
<div class="widget-main">
<ul id="orgtree" class="ztree" style="width: 100%"></ul>
</div>
</div>
</div>
</div>
<div class="col-md-9">
<div class="widget-box widget-color-blue">
<div class="widget-header">
@Html.Action("MenuHeader", "Home")
</div>
<div class="widget-body gridwidth">
<div class="widget-main">
<div class="row">
<div class="col-md-12 ">
<table id="maingrid"></table>
<div id="grid-pager"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div><!-- /.page-content -->
<!--编辑对话框-->
<div class="bjui-dialog hidden bjui-dialog-container" id="editDlg" data-noinit="true">
<div class="bjui-pageContent">
<form action="/CategoryManager/Add" class="pageForm" data-toggle="validate" data-reload="false" id="editForm">
<input type="text" id="Id" name="Id" value="" class="hidden" />
<table class="table table-condensed table-hover">
<tbody>
<tr>
<td>
<label for="Name" class="control-label x120">名称:</label>
<input type="text" name="Name" id="Name" data-rule="required" size="20">
</td>
</tr>
<tr>
<td>
<label for="ParentName" class="control-label x120">上级分类:</label>
<input id="ParentId" name="ParentId" style="display: none" />
<input type="text" name="ParentName" id="ParentName"
data-toggle="selectztree" size="20" data-tree="#j_select_tree1">
<ul id="j_select_tree1" class="ztree hide" data-toggle="ztree"></ul>
</td>
</tr>
<div id="editDlg" style="display: none">
<div class="col-xs-12">
<form class="form-horizontal" id="editForm">
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for=""> 名称 </label>
<div class="col-sm-9">
<input type="text" id="Name" check-type="required" v-model="Name"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for=""> 排序号 </label>
<div class="col-sm-9">
<input type="text" id="SortNo" check-type="required" v-model="SortNo" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for=""> 上级分类</label>
<div class="col-sm-9">
<input id="ParentName" type="text" v-model="ParentName" />
<input id="ParentId" type="hidden" v-model="ParentId" />
<div id="menuContent" class="menuContent" style="display: none;">
<ul id="org" class="ztree"></ul>
</div>
</div>
</div>
<tr>
<td>
<label for="Status" class="control-label x120">当前状态:</label>
<select name="Status" id="Status" data-toggle="selectpicker" data-rule="required">
<option value="0">默认</option>
<option value="1">禁用</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="SortNo" class="control-label x120">排序号:</label>
<input type="text" name="SortNo" id="SortNo" data-rule="required" size="20">
</td>
</tr>
<tr>
<td>
<label for="RootName" class="control-label x120">从属行业(应用)</label>
<input type="text" name="RootName" id="RootName" size="20">
</td>
</tr>
<tr>
<td>
<label for="RootKey" class="control-label x120">从属行业(应用)标识:</label>
<input type="text" name="RootKey" id="RootKey" size="20">
</td>
</tr>
</tbody>
</table>
</form>
</div>
<div class="bjui-pageFooter">
<ul>
<li><button type="button" class="btn btn-close">关闭</button></li>
<li><button type="button" class="btn btn-primary" id="btnSave">保存</button></li>
</ul>
</div>
</div>
<script src="~/BllScripts/grid.js"></script>
<script src="~/BllScripts/categoryManager.js"></script>
<script src="~/BllScripts/categoryManager.js"></script>
<script src="~/BllScripts/jqEvent.js"></script>

View File

@ -47,38 +47,38 @@
</div>
</div>
</div>
<!--编辑对话框-->
<div id="editDlg" style="display: none">
<div class="col-xs-12">
<form class="form-horizontal" id="editForm">
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for=""> 组织名称 </label>
<div class="col-sm-9">
<input type="text" id="Name" check-type="required" v-model="Name"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for=""> 排序号 </label>
<div class="col-sm-9">
<input type="text" id="SortNo" check-type="required" v-model="SortNo" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for=""> 上级机构</label>
<div class="col-sm-9">
<input id="ParentName" type="text" v-model="ParentName" />
<input id="ParentId" type="hidden" v-model="ParentId"/>
<div id="menuContent" class="menuContent" style="display: none;">
<ul id="org" class="ztree"></ul>
</div>
</div>
</div>
</form>
</div>
</div>
</div><!-- /.page-content -->
<!--编辑对话框-->
<div id="editDlg" style="display: none">
<div class="col-xs-12">
<form class="form-horizontal" id="editForm">
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for=""> 组织名称 </label>
<div class="col-sm-9">
<input type="text" id="Name" v-model="Name" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for=""> 排序号 </label>
<div class="col-sm-9">
<input type="text" id="SortNo" v-model="SortNo" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for=""> 上级机构</label>
<div class="col-sm-9">
<input id="ParentName" type="text" v-model="ParentName" />
<input id="ParentId" type="hidden" v-model="ParentId" />
<div id="menuContent" class="menuContent" style="display: none;">
<ul id="org" class="ztree"></ul>
</div>
</div>
</div>
</form>
</div>
</div>
<!--组织修改对话框-->
<script src="~/BllScripts/grid.js"></script>
<script src="~/BllScripts/OrgManager.js"></script>

View File

@ -0,0 +1,268 @@
// ***********************************************************************
// Assembly : OpenAuth.Mvc
// Author : yubaolee
// Created : 04-13-2016
//
// Last Modified By : yubaolee
// Last Modified On : 04-14-2016
// Contact me : www.cnblogs.com/yubaolee
// ***********************************************************************
// File: categoryManager.js
// <summary>分类管理</summary>
// ***********************************************************************
//grid列表模块
function MainGrid() {
var url = '/CategoryManager/Load?parentId=';
var selectedId = '00000000-0000-0000-0000-000000000000'; //ztree选中的模块
this.maingrid = $('#maingrid').datagrid({
showToolbar: false,
loadType: 'GET',
filterThead: false,
target: $(this),
columns: [
{name: 'Id',label: '资源表ID',hide: true},
{
name: 'CascadeId',
label: '节点语义ID',
width: 100
},
{
name: 'Name',
label: '名称',
width: 100
},
{
name: 'ParentId',
label: '父节点流水号',
width: 100
},
{
name: 'Status',
label: '当前状态',
width: 100,
align: 'center',
items: [{ '0': '默认' }, { '1': '删除' }]
},
{
name: 'SortNo',
label: '排序号',
width: 100,
align: 'center',
},
{
name: 'RootKey',
label: '从属行业标识',
width: 100
},
{
name: 'RootName',
label: '从属行业名称',
width: 100
},
],
dataUrl: url + selectedId,
fullGrid: true,
showLinenumber: true,
showCheckboxcol: true,
paging: true,
filterMult: false,
showTfoot: false,
});
this.reload = function (id) {
if (id != undefined) selectedId = id;
this.maingrid.datagrid('reload', { dataUrl: url+ selectedId });
};
};
MainGrid.prototype = new Grid();
var list = new MainGrid();
//左边分类导航树
var ztree = function () {
var url = '/CategoryManager/LoadForTree';
var setting = {
view: { selectedMulti: false },
data: {
key: {
name: 'Name',
title: 'Name'
},
simpleData: {
enable: true,
idKey: 'Id',
pIdKey: 'ParentId',
rootPId: 'null'
}
},
callback: { onClick: zTreeOnClick }
};
$.getJSON(url, function (json) {
$.fn.zTree.init($("#tree"), setting, json).expandAll(true);
});
function zTreeOnClick(event, treeId, treeNode) {
list.reload(treeNode.Id);
}
return {
reload:function() {
$.getJSON(url, function (json) {
$.fn.zTree.init($("#tree"), setting, json).expandAll(true);
});
}
}
}();
//编辑时,选择上级弹出的树
var parentTree = function () {
var nameDom = "#ParentName";
var idDom = "#ParentId";
var zTreeObj;
var setting = {
view: {
selectedMulti: false
},
check: {
enable: true,
chkStyle: "radio", //单选
radioType: "all"
},
data: {
key: {
name: 'Name',
title: 'Name'
},
simpleData: {
enable: true,
idKey: 'Id',
pIdKey: 'ParentId',
rootPId: 'null'
}
},
callback: {
onClick: zTreeOnClick,
onCheck: zTreeCheck
}
};
function zTreeCheck(event, treeId, treeNode) {
var nodes = zTreeObj.getCheckedNodes(true);
var ids = nodes.map(function (e) { return e.Id; }).join(",");
var names = nodes.map(function (e) { return e.Name; }).join(",");
$(nameDom).val(names);
$(idDom).val(ids);
}
function zTreeOnClick(event, treeId, treeNode) {
zTreeObj.checkNode(treeNode, !treeNode.checked, true, true);
event.preventDefault();
}
return {
show:function() {
$.getJSON('/CategoryManager/LoadForTree', function (json) {
zTreeObj = $.fn.zTree.init($('#j_select_tree1'), setting, json);
var orgstr = $(idDom).val();
var name = '';
if (orgstr != '') {
var nodeIds = orgstr.split(',');
$.each(nodeIds, function () {
var node = zTreeObj.getNodeByParam("Id", this, null);
name += ',' + node.Name;
zTreeObj.checkNode(node, true, true);
});
$(nameDom).val(name.substr(1)); //显示名称
}
zTreeObj.expandAll(true);
});
}
};
}();
//添加(编辑)对话框
var editDlg = function () {
var update = false;
var show = function () {
BJUI.dialog({ id: 'editDlg', title: '分类管理', target: '#editDlg' });
$("#btnSave").on("click", function() {
editDlg.save();
});
}
return {
add: function () { //弹出添加
update = false;
show();
$.CurrentDialog.find("form")[0].reset(); //reset方法只能通过dom调用
$("#Id").val('00000000-0000-0000-0000-000000000000');
$("#SortNo").val(0);
parentTree.show();
},
update: function (ret) { //弹出编辑框
update = true;
show();
$("#Id").val(ret.Id);
$("#Name").val(ret.Name);
$("#ParentId").val(ret.ParentId);
$('#Status').selectpicker('val', ret.Status);
$("#SortNo").val(ret.SortNo);
$("#RootKey").val(ret.RootKey);
$("#RootName").val(ret.RootName);
parentTree.show();
},
save: function() { //编辑-->保存
$('#editForm').isValid(function (v) {
if (!v) return; //验证没通过
$("#editForm").bjuiajax('ajaxForm', {
reload: false,
callback: function (json) {
if (json.statusCode == "400") {
$(this).alertmsg('warn', json.message);
return null;
}
list.reload();
ztree.reload();
}
});
});
}
};
}();
//删除
function del() {
var selected = list.getSelectedObj();
if (selected == null) return;
$.post('/CategoryManager/Delete?Id=' + selected.Id, function (data) {
if (data.statusCode == "200") {
list.reload();
ztree.reload();
}
else {
$(this).alertmsg('warn', data.message);
}
}, "json");
}
//编辑
function edit() {
var selected = list.getSelectedObj();
if (selected == null) {
return;
}
editDlg.update(selected);
}
//添加
function add() {
editDlg.add();
}
//刷新
function refresh() {
list.reload();
}
//@@ sourceURL=categoryManager.js

View File

@ -0,0 +1,81 @@
@{
Layout = "~/Views/Shared/_BjuiLayout.cshtml";
}
@{ Html.RenderAction("MenuHeader", "Home");}
<div class="bjui-pageContent tableContent" style="position: relative">
<div class="clearfix">
<div style="float: left; width: 220px; overflow: auto;" class="table table-bordered">
<ul id="tree" class="ztree"></ul>
</div>
<div id="detail" style="margin-left: 225px;">
<table id="maingrid" class="table table-bordered"></table>
</div>
</div>
</div>
<!--编辑对话框-->
<div class="bjui-dialog hidden bjui-dialog-container" id="editDlg" data-noinit="true">
<div class="bjui-pageContent">
<form action="/CategoryManager/Add" class="pageForm" data-toggle="validate" data-reload="false" id="editForm">
<input type="text" id="Id" name="Id" value="" class="hidden" />
<table class="table table-condensed table-hover">
<tbody>
<tr>
<td>
<label for="Name" class="control-label x120">名称:</label>
<input type="text" name="Name" id="Name" data-rule="required" size="20">
</td>
</tr>
<tr>
<td>
<label for="ParentName" class="control-label x120">上级分类:</label>
<input id="ParentId" name="ParentId" style="display: none" />
<input type="text" name="ParentName" id="ParentName"
data-toggle="selectztree" size="20" data-tree="#j_select_tree1">
<ul id="j_select_tree1" class="ztree hide" data-toggle="ztree"></ul>
</td>
</tr>
<tr>
<td>
<label for="Status" class="control-label x120">当前状态:</label>
<select name="Status" id="Status" data-toggle="selectpicker" data-rule="required">
<option value="0">默认</option>
<option value="1">禁用</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="SortNo" class="control-label x120">排序号:</label>
<input type="text" name="SortNo" id="SortNo" data-rule="required" size="20">
</td>
</tr>
<tr>
<td>
<label for="RootName" class="control-label x120">从属行业(应用)</label>
<input type="text" name="RootName" id="RootName" size="20">
</td>
</tr>
<tr>
<td>
<label for="RootKey" class="control-label x120">从属行业(应用)标识:</label>
<input type="text" name="RootKey" id="RootKey" size="20">
</td>
</tr>
</tbody>
</table>
</form>
</div>
<div class="bjui-pageFooter">
<ul>
<li><button type="button" class="btn btn-close">关闭</button></li>
<li><button type="button" class="btn btn-primary" id="btnSave">保存</button></li>
</ul>
</div>
</div>
<script src="~/BllScripts/grid.js"></script>
<script src="~/BllScripts/categoryManager.js"></script>

View File

@ -125,6 +125,7 @@
<Compile Include="TestLogin.cs" />
<Compile Include="TestAuthen.cs" />
<Compile Include="TestCommonApply.cs" />
<Compile Include="TestOrg.cs" />
<Compile Include="TestUser.cs" />
</ItemGroup>
<ItemGroup>

View File

@ -0,0 +1,46 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenAuth.App;
using OpenAuth.App.ViewModel;
using OpenAuth.Domain;
namespace OpenAuth.UnitTest
{
[TestClass]
public class TestOrg : TestBase
{
private OrgManagerApp _app;
public TestOrg()
{
_app = AutofacExt.GetFromFac<OrgManagerApp>();
}
[TestMethod]
public void Add()
{
try
{
for (int i = 0; i < 2; i++)
{
var random = new Random();
int val = random.Next();
_app.AddOrUpdate(new Org
{
Id = Guid.Empty,
Name = "test" + val,
CreateTime = DateTime.Now,
ParentId = null,
ParentName = "",
SortNo = 1
});
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}