mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-04-05 17:38:01 +08:00
分配模块
This commit is contained in:
parent
48db85f686
commit
277676cbba
@ -58,7 +58,7 @@ namespace OpenAuth.App
|
||||
set
|
||||
{
|
||||
_user = value;
|
||||
_userRoleIds = UnitWork.Find<Relevance>(u => u.FirstId == _user.Id && u.Key == "UserRole").Select(u => u.SecondId).ToList();
|
||||
_userRoleIds = UnitWork.Find<Relevance>(u => u.FirstId == _user.Id && u.Key == Define.USERROLE).Select(u => u.SecondId).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
{
|
||||
public static class Define
|
||||
{
|
||||
public static string USERROLE = "UserRole"; //用户角色关联KEY
|
||||
public const string ROLERESOURCE= "RoleResource"; //角色资源关联KEY
|
||||
public const string USERRESOURCE = "UserResource"; //用户资源关联KEY
|
||||
public const string USERORG = "UserOrg"; //用户机构关联KEY
|
||||
|
@ -6,6 +6,7 @@ namespace OpenAuth.App
|
||||
{
|
||||
public class ModuleManagerApp :BaseApp<Module>
|
||||
{
|
||||
public RevelanceManagerApp RevelanceManagerApp { get; set; }
|
||||
public void Add(Module model)
|
||||
{
|
||||
ChangeModuleCascade(model);
|
||||
@ -25,18 +26,25 @@ namespace OpenAuth.App
|
||||
/// TODO:这里会加载用户及用户角色的所有模块,“为用户分配模块”功能会给人一种混乱的感觉,但可以接受
|
||||
/// </summary>
|
||||
/// <param name="userId">The user unique identifier.</param>
|
||||
public List<Module> LoadForUser(string userId)
|
||||
public IEnumerable<Module> LoadForUser(string userId)
|
||||
{
|
||||
return null;
|
||||
var roleIds = RevelanceManagerApp.Get(Define.USERROLE, true, userId);
|
||||
var moduleIds = UnitWork.Find<Relevance>(
|
||||
u =>
|
||||
(u.FirstId == userId && u.Key == Define.USERMODULE) ||
|
||||
(u.Key == Define.ROLEMODULE && roleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||
return UnitWork.Find<Module>(u => moduleIds.Contains(u.Id)).OrderBy(u => u.SortNo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载特定角色的模块
|
||||
/// </summary>
|
||||
/// <param name="roleId">The role unique identifier.</param>
|
||||
public List<Module> LoadForRole(string roleId)
|
||||
public IEnumerable<Module> LoadForRole(string roleId)
|
||||
{
|
||||
return null;
|
||||
var moduleIds = UnitWork.Find<Relevance>(u => u.FirstId == roleId && u.Key == Define.ROLEMODULE)
|
||||
.Select(u => u.SecondId);
|
||||
return UnitWork.Find<Module>(u => moduleIds.Contains(u.Id)).OrderBy(u => u.SortNo);
|
||||
}
|
||||
|
||||
#endregion 用户/角色分配模块
|
||||
|
@ -68,7 +68,7 @@ namespace OpenAuth.App
|
||||
{
|
||||
//用户角色
|
||||
var userRoleIds =
|
||||
UnitWork.Find<Relevance>(u => u.FirstId == userId && u.Key == "UserRole").Select(u => u.SecondId).ToList();
|
||||
UnitWork.Find<Relevance>(u => u.FirstId == userId && u.Key == Define.USERROLE).Select(u => u.SecondId).ToList();
|
||||
|
||||
//用户角色与自己分配到的角色ID
|
||||
var moduleIds =
|
||||
|
@ -28,81 +28,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
//public ActionResult Assign(string firstId, string key)
|
||||
//{
|
||||
// ViewBag.FirstId = firstId;
|
||||
// ViewBag.ModuleType = key;
|
||||
|
||||
// var moduleWithChildren = AuthUtil.GetCurrentUser().Modules
|
||||
// .GenerateTree(u =>u.Id, u =>u.ParentId);
|
||||
// var modules = key == Define.USERMODULE ? App.LoadForUser(firstId) : App.LoadForRole(firstId);
|
||||
|
||||
// CheckModule(moduleWithChildren, modules);
|
||||
|
||||
// ViewBag.Modules = BuilderModules(moduleWithChildren);
|
||||
|
||||
// return View();
|
||||
//}
|
||||
|
||||
private void CheckModule(IEnumerable<TreeItem<ModuleView>> moduleWithChildren, List<Module> modules)
|
||||
{
|
||||
foreach (var module in moduleWithChildren)
|
||||
{
|
||||
if (module.Children.Any())
|
||||
{
|
||||
CheckModule(module.Children, modules);
|
||||
}
|
||||
|
||||
if (modules.Select(u => u.Id).Contains(module.Item.Id))
|
||||
{
|
||||
module.Item.Checked = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public string BuilderModules(IEnumerable<TreeItem<ModuleView>> modules)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (var moduleView in modules)
|
||||
{
|
||||
if (moduleView.Children.Any())
|
||||
{
|
||||
sb.Append("<fieldset class=\"layui-elem-field\">\r\n");
|
||||
sb.Append("<legend>");
|
||||
BuildCheckbox(sb, moduleView);
|
||||
sb.Append("</legend>\r\n");
|
||||
sb.Append("<div class=\"layui-field-box\">\r\n");
|
||||
sb.Append(BuilderModules(moduleView.Children));
|
||||
sb.Append("</div>\r\n");
|
||||
sb.Append("</fieldset>\r\n");
|
||||
|
||||
//sb.Append("<div class=\"layui-form-item\">\r\n");
|
||||
//BuildCheckbox(sb, moduleView);
|
||||
//sb.Append("<div class=\"layui-input-block\">\r\n");
|
||||
//sb.Append(BuilderModules(moduleView.Children));
|
||||
//sb.Append("</div>\r\n");
|
||||
//sb.Append("</div>\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
BuildCheckbox(sb, moduleView);
|
||||
}
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private void BuildCheckbox(StringBuilder sb, TreeItem<ModuleView> moduleView)
|
||||
{
|
||||
sb.Append("<input type=\"checkbox\" value=\"" + moduleView.Item.Id + "\" title=\"" + moduleView.Item.Name + "\"");
|
||||
if (moduleView.Item.Checked)
|
||||
{
|
||||
sb.Append(" checked");
|
||||
}
|
||||
sb.Append(">\r\n");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 加载用户模块
|
||||
/// </summary>
|
||||
|
@ -1,12 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.Mvc.Models;
|
||||
|
||||
namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
|
@ -11,19 +11,15 @@
|
||||
lay-filter="menulist" lay-size="sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th lay-data="{checkbox:true, fixed: true}"></th>
|
||||
<th lay-data="{field:'Name', width:120, sort: true, fixed: true}">名称</th>
|
||||
<th lay-data="{field:'DomId', width:80}">DomId</th>
|
||||
<th lay-data="{field:'Class', width:80}">样式</th>
|
||||
<th lay-data="{field:'Icon', width:60,templet: '#miconTpl'}">图标</th>
|
||||
<th lay-data="{field:'SortNo', width:80}">排序号</th>
|
||||
<th lay-data="{fixed: 'right', width:80, align:'center', toolbar: '#menuBar'}"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
<!--列表右边的按钮-->
|
||||
<script type="text/html" id="menuBar">
|
||||
<a class="layui-btn layui-btn-primary layui-btn-mini" lay-event="del">删除</a>
|
||||
</script>
|
||||
<script type="text/html" id="miconTpl">
|
||||
{{# if( d.Icon != null && d.Icon != ''){ }}
|
||||
<i class="layui-icon">{{ d.Icon }}</i>
|
||||
|
@ -1,12 +1,14 @@
|
||||
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,
|
||||
}).use(['form','vue', 'ztree', 'layer', 'jquery', 'table','droptree','openauth','queryString'], function () {
|
||||
var //layer = (parent == undefined || parent.layer === undefined )? layui.layer : parent.layer,
|
||||
layer = layui.layer,
|
||||
$ = layui.jquery;
|
||||
var table = layui.table;
|
||||
var openauth = layui.openauth;
|
||||
var id = $.getUrlParam("id"); //待分配的id
|
||||
var type = $.getUrlParam("type"); //待分配的类型
|
||||
var menuType = $.getUrlParam("menuType"); //待分配菜单的类型
|
||||
|
||||
//菜单列表
|
||||
var menucon = {}; //table的参数,如搜索key,点击tree的id
|
||||
@ -18,6 +20,21 @@ layui.config({
|
||||
url: '/ModuleManager/LoadMenus',
|
||||
where: menucon
|
||||
});
|
||||
//监听列表checkbox,设置是否分配菜单
|
||||
table.on('checkbox(menulist)', function (obj) {
|
||||
var url = "/RelevanceManager/Assign";
|
||||
if (!obj.checked) {
|
||||
url = "/RelevanceManager/UnAssign";
|
||||
}
|
||||
$.post(url, { type: menuType, firstId: id, secIds: [obj.data.Id] }
|
||||
, function (data) {
|
||||
layer.msg(data.Message);
|
||||
}
|
||||
, "json");
|
||||
});
|
||||
|
||||
//todo:如果该用户已经分配菜单了,则设置相应的状态
|
||||
|
||||
}
|
||||
|
||||
//左边树状机构列表
|
||||
@ -25,7 +42,12 @@ layui.config({
|
||||
var url = '/UserSession/QueryModuleList';
|
||||
var zTreeObj;
|
||||
var setting = {
|
||||
view: { selectedMulti: false },
|
||||
view: { selectedMulti: true },
|
||||
check: {
|
||||
enable: true,
|
||||
chkStyle: "checkbox",
|
||||
chkboxType: { "Y": "", "N": "" } //去掉勾选时级联
|
||||
},
|
||||
data: {
|
||||
key: {
|
||||
name: 'Name',
|
||||
@ -41,6 +63,18 @@ layui.config({
|
||||
callback: {
|
||||
onClick: function (event, treeId, treeNode) {
|
||||
menuList({ moduleId: treeNode.Id });
|
||||
},
|
||||
onCheck: function (event, treeId, treeNode) {
|
||||
var url = "/RelevanceManager/Assign";
|
||||
if (!treeNode.checked) {
|
||||
url = "/RelevanceManager/UnAssign";
|
||||
}
|
||||
|
||||
$.post(url, { type: type, firstId: id, secIds: [treeNode.Id] }
|
||||
, function (data) {
|
||||
layer.msg(data.Message);
|
||||
}
|
||||
, "json");
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -48,6 +82,8 @@ layui.config({
|
||||
$.getJSON(url, function (json) {
|
||||
zTreeObj = $.fn.zTree.init($("#tree"), setting);
|
||||
zTreeObj.addNodes(null, json);
|
||||
//todo:如果该用户已经分配模块了,则设置相应的状态
|
||||
|
||||
menuList({ moduleId: json[0].Id });
|
||||
zTreeObj.expandAll(true);
|
||||
});
|
||||
@ -57,15 +93,5 @@ layui.config({
|
||||
reload: load
|
||||
}
|
||||
}();
|
||||
|
||||
//监听菜单表格内部按钮
|
||||
table.on('tool(menulist)', function (obj) {
|
||||
var data = obj.data;
|
||||
if (obj.event === 'del') { //删除菜单
|
||||
openauth.del("/moduleManager/delMenu",
|
||||
data.Id,menuList);
|
||||
}
|
||||
});
|
||||
|
||||
//监听页面主按钮操作 end
|
||||
})
|
@ -146,13 +146,20 @@ layui.config({
|
||||
mainList();
|
||||
}
|
||||
, btnAccessModule: function () {
|
||||
var checkStatus = table.checkStatus('mainList')
|
||||
, data = checkStatus.data;
|
||||
if (data.length != 1) {
|
||||
layer.msg("请选择要分配的角色");
|
||||
return;
|
||||
}
|
||||
|
||||
var index = layer.open({
|
||||
title: "为用户分配模块",
|
||||
title: "为用角色配模块",
|
||||
type: 2,
|
||||
area: ['800px', '500px'],
|
||||
content: "/ModuleManager/Assign",
|
||||
success: function(layero, index) {
|
||||
|
||||
content: "/ModuleManager/Assign?type=RoleModule&menuType=RoleElement&id=" + data[0].Id,
|
||||
success: function (layero, index) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -146,11 +146,18 @@ layui.config({
|
||||
mainList();
|
||||
}
|
||||
, btnAccessModule: function () {
|
||||
var checkStatus = table.checkStatus('mainList')
|
||||
, data = checkStatus.data;
|
||||
if (data.length != 1) {
|
||||
layer.msg("请选择要分配的用户");
|
||||
return;
|
||||
}
|
||||
|
||||
var index = layer.open({
|
||||
title: "为用户分配模块",
|
||||
type: 2,
|
||||
area: ['800px', '500px'],
|
||||
content: "/ModuleManager/Assign",
|
||||
content: "/ModuleManager/Assign?type=UserModule&menuType=UserElement&id=" + data[0].Id,
|
||||
success: function(layero, index) {
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user