完成分配菜单

This commit is contained in:
yubaolee
2016-10-20 16:47:35 +08:00
parent 5d2569dddd
commit de50581f8b
26 changed files with 308 additions and 170 deletions

View File

@@ -76,10 +76,7 @@ namespace OpenAuth.Domain.Service
{ {
return listVms; return listVms;
} }
if (moduleId == Guid.Empty) return listVms; if (moduleId == Guid.Empty) return listVms;
string modulename = service.GetModulesQuery().SingleOrDefault(u => u.Id == moduleId).Name;
foreach (var element in service.GetModuleElementsQuery().Where(u =>u.ModuleId ==moduleId)) foreach (var element in service.GetModuleElementsQuery().Where(u =>u.ModuleId ==moduleId))
{ {
var accessed = _unitWork.FindSingle<Relevance>(u =>u.Key == accessType var accessed = _unitWork.FindSingle<Relevance>(u =>u.Key == accessType
@@ -90,8 +87,7 @@ namespace OpenAuth.Domain.Service
Name = element.Name, Name = element.Name,
ModuleId = element.ModuleId, ModuleId = element.ModuleId,
DomId = element.DomId, DomId = element.DomId,
ModuleName = modulename, Checked = accessed != null
Accessed = accessed != null
}; };
listVms.Add(vm); listVms.Add(vm);
} }

View File

@@ -10,94 +10,72 @@
//Description: 分配模块菜单(按钮) //Description: 分配模块菜单(按钮)
// *********************************************************************** // ***********************************************************************
$(document).ready(function () { function renderLayui() {
$.CurrentDialog.find("#btnAccess").on("click", function () { layui.use(['layer', 'form'], function () {
var ids = dlgList.getSelectedProperties('Id'); var form = layui.form();
if (ids == null) return;
$.post('/RelevanceManager/Assign', { form.on('checkbox', function (data) {
type: $("#moduleType").val(), if (data.elem.checked) {
firstId: $('#firstId').val(), $.post('/RelevanceManager/Assign', {
secIds: ids type: $("#moduleType").val(),
}, function (json) { firstId: $('#firstId').val(),
json = $.parseJSON(json); secIds: data.value
if (json.statusCode != "200") { }, function (json) {
$(this).alertmsg('warn', json.message); json = $.parseJSON(json);
return;
});
} }
dlgList.reload(); else {
}); $.post('/RelevanceManager/UnAssign', {
}); type: $("#moduleType").val(),
$.CurrentDialog.find("#btnDelAccess").on("click", function () { firstId: $('#firstId').val(),
var ids = dlgList.getSelectedProperties('Id'); secIds: data.value
if (ids == null) return; }, function (json) {
json = $.parseJSON(json);
$.post('/RelevanceManager/UnAssign', { });
type: $("#moduleType").val(),
firstId: $('#firstId').val(),
secIds: ids
}, function (json) {
json = $.parseJSON(json);
if (json.statusCode != "200") {
$(this).alertmsg('warn', json.message);
return;
} }
dlgList.reload();
}); });
});
});
//grid列表模块 form.render();
function DialogList() { });
}
var list = function () {
var selectedId = '00000000-0000-0000-0000-000000000000'; //选中的ID var selectedId = '00000000-0000-0000-0000-000000000000'; //选中的ID
var url = '/ModuleElementManager/LoadWithAccess?tId='; var url = '/ModuleElementManager/LoadWithAccess?firstId=' + $("#firstId").val() + "&key=" + $("#moduleType").val() + "&tId=";
this.maingrid = $.CurrentDialog.find('#maingrid').datagrid({ return {
showToolbar: false, reload: function (id) {
loadType: 'GET', if (id != undefined) selectedId = id;
filterThead: false, $.getJSON(url + selectedId,
target: $(this), function (data) {
columns: [ var str = '';
{ if (data.length > 0) {
name: 'Id', $.each(data,
label: '元素名称', function () {
hide: true str += "<input type=\"checkbox\" name=\"\" value=\""+this.Id+"\" title=\"" + this.Name + "\"";
}, if (this.Checked) {
{ str += " checked ";
name: 'Name', }
label: '元素名称', str += ">\r\n";
width: 80 });
}, }
{ $("#moduleElements").html(str);
name: 'ModuleName', renderLayui();
label: '所属模块', });
width: 80 }
}, };
{ }();
name: 'Accessed', //左边导航
label: '是否已经授权', var ztree = function() {
align: 'center', var url;
items: [{ 'false': '未授权', 'true': '已授权' }], var type = $("#moduleType");
width: 80 if (type.val() == "UserElement") {
} url = '/ModuleManager/LoadForUser';
], } else {
dataUrl: url + selectedId + '&key=' + $('#moduleType').val() + '&firstId=' + $('#firstId').val(), url = '/ModuleManager/LoadForRole';
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 + '&key=' + $('#moduleType').val() + '&firstId=' + $('#firstId').val() });
} }
};
DialogList.prototype = new Grid();
var dlgList = new DialogList();
var ztree = function () {
var setting = { var setting = {
view: { selectedMulti: false }, view: { selectedMulti: false },
data: { data: {
@@ -112,22 +90,25 @@ var ztree = function () {
rootPId: 'null' rootPId: 'null'
} }
}, },
callback: { onClick: zTreeOnClick } callback: {
onClick: function(event, treeId, treeNode) {
list.reload(treeNode.Id);
}
}
}; };
var load = function() {
$.getJSON(url,
{ firstId: $("#firstId").val() },
function(json) {
var zTreeObj = $.fn.zTree.init($("#orgtree"), setting, json);
list.reload();
zTreeObj.expandAll(true);
});
};
load();
var url; return {
var type = $("#moduleType"); reload: load
if (type.val() == "UserElement") {
url = '/ModuleManager/LoadForUser';
} else {
url = '/ModuleManager/LoadForRole';
} }
$.getJSON(url, { firstId: $("#firstId").val() }, function(json) {
var zTreeObj = $.fn.zTree.init($.CurrentDialog.find("#tree"), setting, json);
zTreeObj.expandAll(true);
});
}(); }();
function zTreeOnClick(event, treeId, treeNode) {
dlgList.reload(treeNode.Id);
}

View File

@@ -194,16 +194,11 @@ function assignRoleModule(obj) {
var selected = list.getSelectedObj(); var selected = list.getSelectedObj();
if (selected == null) return; if (selected == null) return;
$(obj).dialog({ layer.open({
id: 'accessUserOrg', type: 2,
url: '/ModuleManager/Assign', skin: 'layui-layer-rim', //加上边框
title: '为角色分配模块', area: ['410px', '390px'], //宽高
width: 620, content: '/ModuleManager/Assign?key=RoleModule&firstId=' + selected.Id
height: 500,
data: {
firstId: selected.Id,
key: "RoleModule"
}
}); });
} }
@@ -230,16 +225,11 @@ function assignRoleElement(obj) {
var selected = list.getSelectedObj(); var selected = list.getSelectedObj();
if (selected == null) return; if (selected == null) return;
$(obj).dialog({ layer.open({
id: 'accessRoleElement', type: 2,
url: '/ModuleElementManager/AssignModuleElement', skin: 'layui-layer-rim', //加上边框
title: '为角色分配菜单', area: ['600px', '400px'], //宽高
width: 600, content: '/ModuleElementManager/AssignModuleElement?key=RoleElement&firstId=' + selected.Id
height: 380,
data: {
firstId: selected.Id,
key: "RoleElement"
}
}); });
} }

View File

@@ -253,15 +253,10 @@ function openAssignUserElement(obj) {
var selected = list.getSelectedObj(); var selected = list.getSelectedObj();
if (selected == null) return; if (selected == null) return;
$(obj).dialog({ layer.open({
id: 'accessUserElement', type: 2,
url: '/ModuleElementManager/AssignModuleElement', skin: 'layui-layer-rim', //加上边框
title: '为用户分配资源', area: ['600px', '300px'], //宽高
width: 600, content: '/ModuleElementManager/AssignModuleElement?key=UserElement&firstId=' + selected.Id
height: 380,
data: {
firstId: selected.Id,
key: "UserElement"
}
}); });
} }

View File

@@ -1,3 +1,14 @@
.layui-elem-field { .layui-elem-field {
border: 1px solid #5fb878; border: 1px solid #5fb878;
} }
.site-tips {
margin-bottom: 10px;
padding: 15px;
border-left: 5px solid #0078AD;
background-color: #f2f2f2;
}
body .site-tips p {
margin: 0;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 399 B

View File

@@ -118,6 +118,28 @@ namespace OpenAuth.Mvc.Controllers
return JsonHelper.Instance.Serialize(orgs); return JsonHelper.Instance.Serialize(orgs);
} }
/// <summary>
/// 加载用户模块
/// </summary>
/// <param name="firstId">The user identifier.</param>
/// <returns>System.String.</returns>
public string LoadForUser(Guid firstId)
{
var orgs = _app.LoadForUser(firstId);
return JsonHelper.Instance.Serialize(orgs);
}
/// <summary>
/// 加载角色模块
/// </summary>
/// <param name="firstId">The role identifier.</param>
/// <returns>System.String.</returns>
public string LoadForRole(Guid firstId)
{
var orgs = _app.LoadForRole(firstId);
return JsonHelper.Instance.Serialize(orgs);
}
public string LoadModuleWithRoot() public string LoadModuleWithRoot()
{ {
var orgs = AuthUtil.GetCurrentUser().Modules.MapToList<ModuleView>(); var orgs = AuthUtil.GetCurrentUser().Modules.MapToList<ModuleView>();

View File

@@ -1059,21 +1059,6 @@
<Content Include="Content\plugins\zTree\css\metroStyle\img\metro.gif" /> <Content Include="Content\plugins\zTree\css\metroStyle\img\metro.gif" />
<Content Include="Content\plugins\zTree\css\metroStyle\img\metro.png" /> <Content Include="Content\plugins\zTree\css\metroStyle\img\metro.png" />
<Content Include="Content\plugins\zTree\css\metroStyle\metroStyle.css" /> <Content Include="Content\plugins\zTree\css\metroStyle\metroStyle.css" />
<Content Include="Content\plugins\zTree\css\zTreeStyle\img\diy\1_close.png" />
<Content Include="Content\plugins\zTree\css\zTreeStyle\img\diy\1_open.png" />
<Content Include="Content\plugins\zTree\css\zTreeStyle\img\diy\2.png" />
<Content Include="Content\plugins\zTree\css\zTreeStyle\img\diy\3.png" />
<Content Include="Content\plugins\zTree\css\zTreeStyle\img\diy\4.png" />
<Content Include="Content\plugins\zTree\css\zTreeStyle\img\diy\5.png" />
<Content Include="Content\plugins\zTree\css\zTreeStyle\img\diy\6.png" />
<Content Include="Content\plugins\zTree\css\zTreeStyle\img\diy\7.png" />
<Content Include="Content\plugins\zTree\css\zTreeStyle\img\diy\8.png" />
<Content Include="Content\plugins\zTree\css\zTreeStyle\img\diy\9.png" />
<Content Include="Content\plugins\zTree\css\zTreeStyle\img\line_conn.gif" />
<Content Include="Content\plugins\zTree\css\zTreeStyle\img\loading.gif" />
<Content Include="Content\plugins\zTree\css\zTreeStyle\img\zTreeStandard.gif" />
<Content Include="Content\plugins\zTree\css\zTreeStyle\img\zTreeStandard.png" />
<Content Include="Content\plugins\zTree\css\zTreeStyle\zTreeStyle.css" />
<Content Include="Content\plugins\zTree\js\jquery-1.4.4.min.js" /> <Content Include="Content\plugins\zTree\js\jquery-1.4.4.min.js" />
<Content Include="Content\plugins\zTree\js\jquery.ztree.all.js" /> <Content Include="Content\plugins\zTree\js\jquery.ztree.all.js" />
<Content Include="Content\plugins\zTree\js\jquery.ztree.all.min.js" /> <Content Include="Content\plugins\zTree\js\jquery.ztree.all.min.js" />

View File

@@ -1,31 +1,25 @@
<div class="bjui-pageHeader"> @{
<div class="bjui-searchBar"> Layout = null;
<input style="display: none" id="firstId" value="@ViewBag.FirstId" /> }
<input style="display: none" id="moduleType" , value="@ViewBag.ModuleType" /> <link href="~/Content/layui/css/layui.css" rel="stylesheet" />
<div class="pull-right"> <link href="~/Content/mylayer.css" rel="stylesheet" />
<div class="alert alert-info search-inline"> <script src="~/Content/layui/layui.js"></script>
<i class="fa fa-info-circle"></i> 点击行为单选,点击复选框可多选统一授权 <script src="~/Content/plugins/jQuery/jQuery-2.1.4.min.js"></script>
</div>&nbsp; <script src="~/Content/plugins/zTree/js/jquery.ztree.core.js"></script>
<button type="button" class="btn btn-green" data-num="1" data-icon="plus" id="btnAccess"> <link href="/Content/plugins/zTree/css/metroStyle/metroStyle.css" rel="stylesheet" />
授权选中
</button>&nbsp; <div style="display: inline-block; width: 180px; height: 210px; padding: 10px; border: 1px solid #ddd; overflow: auto;">
<button type="button" class="btn btn-danger" data-num="1" data-icon="trash" id="btnDelAccess"> <input style="display: none" id="firstId" value="@ViewBag.FirstId" />
取消授权 <input style="display: none" id="moduleType" , value="@ViewBag.ModuleType" />
</button>&nbsp; <ul id="orgtree" class="ztree" style="width: 100%"></ul>
</div>
</div>
</div> </div>
<div class="bjui-pageContent tableContent">
<div class="clearfix">
<div style="float: left; width: 220px; overflow: auto;" class="table table-bordered">
<ul id="tree" class="ztree"></ul>
</div>
<div style="margin-left: 225px;"> <div class="site-tips" style="display: inline-block; height: 210px; width: 340px; padding: 10px; margin-left: 10px; vertical-align: top;" id="demo2-view">
<table id="maingrid" class="table table-bordered table-hover table-striped table-top"></table> <form class="layui-form " action="" id="moduleElements">
</div> </form>
</div>
</div> </div>
<script src="~/BllScripts/grid.js"></script> <script src="~/BllScripts/grid.js"></script>
<script src="~/BllScripts/assignModuleElement.js"></script> <script src="~/BllScripts/assignModuleElement.js"></script>

View File

@@ -0,0 +1,133 @@
// ***********************************************************************
// Assembly : OpenAuth.Mvc
// Author : yubaolee
// Created : 04-19-2016
//
// Last Modified By : yubaolee
// Last Modified On : 05-26-2016
// Contact : www.cnblogs.com/yubaolee
// File: assignModuleElement.js
//Description: 分配模块菜单(按钮)
// ***********************************************************************
$(document).ready(function () {
$.CurrentDialog.find("#btnAccess").on("click", function () {
var ids = dlgList.getSelectedProperties('Id');
if (ids == null) return;
$.post('/RelevanceManager/Assign', {
type: $("#moduleType").val(),
firstId: $('#firstId').val(),
secIds: ids
}, function (json) {
json = $.parseJSON(json);
if (json.statusCode != "200") {
$(this).alertmsg('warn', json.message);
return;
}
dlgList.reload();
});
});
$.CurrentDialog.find("#btnDelAccess").on("click", function () {
var ids = dlgList.getSelectedProperties('Id');
if (ids == null) return;
$.post('/RelevanceManager/UnAssign', {
type: $("#moduleType").val(),
firstId: $('#firstId').val(),
secIds: ids
}, function (json) {
json = $.parseJSON(json);
if (json.statusCode != "200") {
$(this).alertmsg('warn', json.message);
return;
}
dlgList.reload();
});
});
});
//grid列表模块
function DialogList() {
var selectedId = '00000000-0000-0000-0000-000000000000'; //选中的ID
var url = '/ModuleElementManager/LoadWithAccess?tId=';
this.maingrid = $.CurrentDialog.find('#maingrid').datagrid({
showToolbar: false,
loadType: 'GET',
filterThead: false,
target: $(this),
columns: [
{
name: 'Id',
label: '元素名称',
hide: true
},
{
name: 'Name',
label: '元素名称',
width: 80
},
{
name: 'ModuleName',
label: '所属模块',
width: 80
},
{
name: 'Accessed',
label: '是否已经授权',
align: 'center',
items: [{ 'false': '未授权', 'true': '已授权' }],
width: 80
}
],
dataUrl: url + selectedId + '&key=' + $('#moduleType').val() + '&firstId=' + $('#firstId').val(),
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 + '&key=' + $('#moduleType').val() + '&firstId=' + $('#firstId').val() });
}
};
DialogList.prototype = new Grid();
var dlgList = new DialogList();
var ztree = function () {
var setting = {
view: { selectedMulti: false },
data: {
key: {
name: 'Name',
title: 'Name'
},
simpleData: {
enable: true,
idKey: 'Id',
pIdKey: 'ParentId',
rootPId: 'null'
}
},
callback: { onClick: zTreeOnClick }
};
var url;
var type = $("#moduleType");
if (type.val() == "UserElement") {
url = '/ModuleManager/LoadForUser';
} else {
url = '/ModuleManager/LoadForRole';
}
$.getJSON(url, { firstId: $("#firstId").val() }, function(json) {
var zTreeObj = $.fn.zTree.init($.CurrentDialog.find("#tree"), setting, json);
zTreeObj.expandAll(true);
});
}();
function zTreeOnClick(event, treeId, treeNode) {
dlgList.reload(treeNode.Id);
}

View File

@@ -1,7 +1,7 @@
/*------------------------------------- /*-------------------------------------
zTree Style zTree Style
version: 3.5.19 version: 3.4
author: Hunter.z author: Hunter.z
email: hunter.z@263.net email: hunter.z@263.net
website: http://code.google.com/p/jquerytree/ website: http://code.google.com/p/jquerytree/

View File

@@ -0,0 +1,31 @@
<div class="bjui-pageHeader">
<div class="bjui-searchBar">
<input style="display: none" id="firstId" value="@ViewBag.FirstId" />
<input style="display: none" id="moduleType" , value="@ViewBag.ModuleType" />
<div class="pull-right">
<div class="alert alert-info search-inline">
<i class="fa fa-info-circle"></i> 点击行为单选,点击复选框可多选统一授权
</div>&nbsp;
<button type="button" class="btn btn-green" data-num="1" data-icon="plus" id="btnAccess">
授权选中
</button>&nbsp;
<button type="button" class="btn btn-danger" data-num="1" data-icon="trash" id="btnDelAccess">
取消授权
</button>&nbsp;
</div>
</div>
</div>
<div class="bjui-pageContent tableContent">
<div class="clearfix">
<div style="float: left; width: 220px; overflow: auto;" class="table table-bordered">
<ul id="tree" class="ztree"></ul>
</div>
<div style="margin-left: 225px;">
<table id="maingrid" class="table table-bordered table-hover table-striped table-top"></table>
</div>
</div>
</div>
<script src="~/BllScripts/grid.js"></script>
<script src="~/BllScripts/assignModuleElement.js"></script>

Binary file not shown.

After

Width:  |  Height:  |  Size: 432 B