修改菜单指派角色功能
This commit is contained in:
parent
35c915c3e8
commit
83bdfe3b71
|
@ -221,7 +221,15 @@
|
||||||
data: data.data,
|
data: data.data,
|
||||||
type: data.method,
|
type: data.method,
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
if ($.isFunction(data.callback)) data.callback(result);
|
if ($.isFunction(data.callback)) {
|
||||||
|
if ($.isArray(result)) {
|
||||||
|
var html = $.map(result, function (element, index) {
|
||||||
|
return $.format('<div class="checkbox col-lg-3 col-xs-4"><label title="{3}"><input type="checkbox" value="{0}" {2}>{1}</label></div>', element.ID, element.RoleName, element.Checked, element.Description);
|
||||||
|
}).join('');
|
||||||
|
data.callback(html);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { data.callback(false); }
|
||||||
},
|
},
|
||||||
error: function (XMLHttpRequest, textStatus, errorThrown) {
|
error: function (XMLHttpRequest, textStatus, errorThrown) {
|
||||||
if ($.isFunction(data.callback)) data.callback(false);
|
if ($.isFunction(data.callback)) data.callback(false);
|
||||||
|
@ -236,39 +244,14 @@
|
||||||
Role.getRolesByGroupId = function (groupId) {
|
Role.getRolesByGroupId = function (groupId) {
|
||||||
processRolesData({ Id: groupId, callback: callback, data: { type: "group" } });
|
processRolesData({ Id: groupId, callback: callback, data: { type: "group" } });
|
||||||
};
|
};
|
||||||
|
|
||||||
//查询菜单对应角色
|
|
||||||
Role.getRolesByMenuId = function (menuId, callback) {
|
Role.getRolesByMenuId = function (menuId, callback) {
|
||||||
$.ajax({
|
processRolesData({ Id: menuId, callback: callback, data: { type: "menu" } });
|
||||||
url: '../api/Roles/' + menuId,
|
|
||||||
data: { "": "menu" },
|
|
||||||
type: 'POST',
|
|
||||||
success: function (result) {
|
|
||||||
callback(result);
|
|
||||||
},
|
|
||||||
error: function (XMLHttpRequest, textStatus, errorThrown) {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Role.saveRolesByUserId = function (userId, roleIds, callback) {
|
Role.saveRolesByUserId = function (userId, roleIds, callback) {
|
||||||
processRolesData({ Id: userId, callback: callback, method: "PUT", data: { type: "user", roleIds: roleIds } });
|
processRolesData({ Id: userId, callback: callback, method: "PUT", data: { type: "user", roleIds: roleIds } });
|
||||||
}
|
}
|
||||||
|
|
||||||
//保存菜单对应角色
|
|
||||||
Role.saveRolesByMenuId = function (menuId, roleIds, callback) {
|
Role.saveRolesByMenuId = function (menuId, roleIds, callback) {
|
||||||
$.ajax({
|
processRolesData({ Id: menuId, callback: callback, method: "PUT", data: { type: "menu", roleIds: roleIds } });
|
||||||
url: '../api/Roles/' + menuId,
|
|
||||||
data: { "roleIds": roleIds, "type": "menu" },
|
|
||||||
type: 'PUT',
|
|
||||||
success: function (result) {
|
|
||||||
callback(result);
|
|
||||||
},
|
|
||||||
error: function (XMLHttpRequest, textStatus, errorThrown) {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Group = {};
|
Group = {};
|
||||||
|
|
|
@ -37,15 +37,13 @@ namespace Bootstrap.Admin.Controllers
|
||||||
case "group":
|
case "group":
|
||||||
ret = RoleHelper.RetrieveRolesByGroupId(id).ToList();
|
ret = RoleHelper.RetrieveRolesByGroupId(id).ToList();
|
||||||
break;
|
break;
|
||||||
case "menu"
|
case "menu":
|
||||||
ret = RoleHelper.RetrieveRolesByMenuId(id.ToString());
|
ret = RoleHelper.RetrieveRolesByMenuId(id).ToList();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
return ret;
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
|
@ -66,8 +64,9 @@ namespace Bootstrap.Admin.Controllers
|
||||||
case "group":
|
case "group":
|
||||||
ret = RoleHelper.SaveRolesByGroupId(id, roleIds);
|
ret = RoleHelper.SaveRolesByGroupId(id, roleIds);
|
||||||
break;
|
break;
|
||||||
case "menu":
|
case "menu":
|
||||||
ret = RoleHelper.SavaRolesByMenuId(id, roleIds);
|
ret = RoleHelper.SavaRolesByMenuId(id, roleIds);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,15 +16,8 @@
|
||||||
assign: [{
|
assign: [{
|
||||||
id: 'btn_assignRole',
|
id: 'btn_assignRole',
|
||||||
click: function (row) {
|
click: function (row) {
|
||||||
Role.getRolesByMenuId(row.ID, function (roles) {
|
Role.getRolesByMenuId(row.ID, function (data) {
|
||||||
$("#dialogRole .modal-title").text($.format('{0}-角色授权窗口', row.Name));
|
$("#dialogRole .modal-title").text($.format('{0}-角色授权窗口', row.Name));
|
||||||
var data = $.map(roles, function (element, index) {
|
|
||||||
if (element.IsSelect == 1) {
|
|
||||||
return $.format('<div class="checkbox"><label><input type="checkbox" value="{0}" checked="checked">{1}</label></div>', element.ID, element.RoleName);
|
|
||||||
} else if (element.IsSelect == 0) {
|
|
||||||
return $.format('<div class="checkbox"><label><input type="checkbox" value="{0}">{1}</label></div>', element.ID, element.RoleName);
|
|
||||||
}
|
|
||||||
}).join('');
|
|
||||||
$('#dialogRole form').html(data);
|
$('#dialogRole form').html(data);
|
||||||
$('#dialogRole').modal('show');
|
$('#dialogRole').modal('show');
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,11 +13,8 @@
|
||||||
assign: [{
|
assign: [{
|
||||||
id: 'btn_assignRole',
|
id: 'btn_assignRole',
|
||||||
click: function (row) {
|
click: function (row) {
|
||||||
Role.getRolesByUserId(row.ID, function (roles) {
|
Role.getRolesByUserId(row.ID, function (data) {
|
||||||
$("#dialogRole .modal-title").text($.format('{0}-角色授权窗口', row.DisplayName));
|
$("#dialogRole .modal-title").text($.format('{0}-角色授权窗口', row.DisplayName));
|
||||||
var data = $.map(roles, function (element, index) {
|
|
||||||
return $.format('<div class="checkbox col-lg-3 col-xs-4"><label title="{3}"><input type="checkbox" value="{0}" {2}>{1}</label></div>', element.ID, element.RoleName, element.Checked, element.Description);
|
|
||||||
}).join('');
|
|
||||||
$('#dialogRole form').html(data);
|
$('#dialogRole form').html(data);
|
||||||
$('#dialogRole').modal('show');
|
$('#dialogRole').modal('show');
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,76 +1,81 @@
|
||||||
@model NavigatorBarModel
|
@model NavigatorBarModel
|
||||||
@{
|
@{
|
||||||
ViewBag.Title = "菜单管理";
|
ViewBag.Title = "菜单管理";
|
||||||
Layout = "~/Views/Shared/_Default.cshtml";
|
Layout = "~/Views/Shared/_Default.cshtml";
|
||||||
}
|
}
|
||||||
@section css {
|
@section css {
|
||||||
<link href="~/Content/css/fa.css" rel="stylesheet" />
|
<link href="~/Content/css/fa.css" rel="stylesheet" />
|
||||||
}
|
}
|
||||||
@section Javascript {
|
@section Javascript {
|
||||||
<script src="~/scripts/Menus.js"></script>
|
<script src="~/scripts/Menus.js"></script>
|
||||||
}
|
}
|
||||||
@section header {
|
@section header {
|
||||||
@Html.Partial("Header", Model)
|
@Html.Partial("Header", Model)
|
||||||
}
|
}
|
||||||
@section navigator {
|
@section navigator {
|
||||||
@Html.Partial("Navigator", Model)
|
@Html.Partial("Navigator", Model)
|
||||||
}
|
}
|
||||||
@section query {
|
@section query {
|
||||||
<form class="form-inline" role="form">
|
<form class="form-inline" role="form">
|
||||||
<div class="form-group col-lg-5">
|
<div class="form-group col-lg-5">
|
||||||
<label class="control-label" for="txt_menus_name">菜单名称</label>
|
<label class="control-label" for="txt_menus_name">菜单名称</label>
|
||||||
<input type="text" class="form-control" id="txt_menus_name" />
|
<input type="text" class="form-control" id="txt_menus_name" />
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-lg-5">
|
<div class="form-group col-lg-5">
|
||||||
<label class="control-label" for="txt_menus_category">菜单类别</label>
|
<label class="control-label" for="txt_menus_category">菜单类别</label>
|
||||||
<input type="text" class="form-control" id="txt_menus_category" />
|
<input type="text" class="form-control" id="txt_menus_category" />
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-lg-2">
|
<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>
|
<button type="button" id="btn_query" class="btn btn-primary"><span class="glyphicon glyphicon-search" aria-hidden="true"></span>查询</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
}
|
}
|
||||||
@section toolbar {
|
@section toolbar {
|
||||||
<button id="btn_assignRole" type="button" class="btn btn-info">
|
<button id="btn_assignRole" type="button" class="btn btn-info">
|
||||||
<span class="fa fa-sitemap" aria-hidden="true"></span>指派角色
|
<span class="fa fa-sitemap" aria-hidden="true"></span>指派角色
|
||||||
</button>
|
</button>
|
||||||
}
|
}
|
||||||
@section modal {
|
@section modal {
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||||
<h4 class="modal-title" id="myModalLabel">用户编辑窗口</h4>
|
<h4 class="modal-title" id="myModalLabel">用户编辑窗口</h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<form class="form-inline" id="dataForm" name="dataForm" role="form">
|
<form class="form-inline" id="dataForm" name="dataForm" role="form">
|
||||||
<div class="form-group col-lg-6">
|
<div class="form-group col-lg-6">
|
||||||
<label class="control-label" for="parentId">父级ID</label>
|
<label class="control-label" for="parentId">父级ID</label>
|
||||||
<input type="text" class="form-control" id="parentId" name="parentId" maxlength="50" />
|
<input type="text" class="form-control" id="parentId" name="parentId" maxlength="50" />
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-lg-6">
|
<div class="form-group col-lg-6">
|
||||||
<label class="control-label" for="name">菜单名称</label>
|
<label class="control-label" for="name">菜单名称</label>
|
||||||
<input type="text" class="form-control" id="name" name="name" maxlength="50" />
|
<input type="text" class="form-control" id="name" name="name" maxlength="50" />
|
||||||
<input type="text" class="form-control hide" id="menuID" name="menuID" />
|
<input type="text" class="form-control hide" id="menuID" name="menuID" />
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-lg-6">
|
<div class="form-group col-lg-6">
|
||||||
<label class="control-label" for="order">菜单序号</label>
|
<label class="control-label" for="order">菜单序号</label>
|
||||||
<input type="text" class="form-control" id="order" name="order" />
|
<input type="text" class="form-control" id="order" name="order" />
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-lg-6">
|
<div class="form-group col-lg-6">
|
||||||
<label class="control-label" for="icon">菜单图标</label>
|
<label class="control-label" for="icon">菜单图标</label>
|
||||||
<input type="text" class="form-control" id="icon" name="icon" maxlength="50" />
|
<div class="input-group">
|
||||||
</div>
|
<input type="text" class="form-control disabled" disabled id="icon" name="icon" maxlength="50" />
|
||||||
<div class="form-group col-lg-6">
|
<span class="input-group-btn">
|
||||||
<label class="control-label" for="url">路径</label>
|
<button class="btn btn-default" type="button"><i></i>选择</button>
|
||||||
<input type="text" class="form-control" id="url" name="url" maxlength="50" />
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-lg-6">
|
</div>
|
||||||
<label class="control-label" for="category">类别</label>
|
<div class="form-group col-lg-6">
|
||||||
<input type="text" class="form-control" id="category" name="category" maxlength="50" />
|
<label class="control-label" for="url">路径</label>
|
||||||
</div>
|
<input type="text" class="form-control" id="url" name="url" maxlength="50" />
|
||||||
</form>
|
</div>
|
||||||
</div>
|
<div class="form-group col-lg-6">
|
||||||
}
|
<label class="control-label" for="category">类别</label>
|
||||||
@section customModal {
|
<input type="text" class="form-control" id="category" name="category" maxlength="50" />
|
||||||
@Html.Partial("RoleConfig")
|
</div>
|
||||||
@Html.Partial("IconView")
|
</form>
|
||||||
}
|
</div>
|
||||||
|
}
|
||||||
|
@section customModal {
|
||||||
|
@Html.Partial("RoleConfig")
|
||||||
|
@Html.Partial("IconView")
|
||||||
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
<add key="UserData-CodeUserHelper-" interval="600" desc="用户信息缓存" />
|
<add key="UserData-CodeUserHelper-" interval="600" desc="用户信息缓存" />
|
||||||
<add key="RoleData-CodeRoleHelper" interval="600" desc="角色信息缓存" />
|
<add key="RoleData-CodeRoleHelper" interval="600" desc="角色信息缓存" />
|
||||||
<add key="RoleData-CodeRoleHelper-" interval="600" desc="角色信息缓存" />
|
<add key="RoleData-CodeRoleHelper-" interval="600" desc="角色信息缓存" />
|
||||||
<add key="RoleData-CodeRoleHelper-Navigation" interval="600" desc="菜单角色信息缓存"/>
|
<add key="RoleData-CodeRoleHelper-Navigation-" interval="600" desc="菜单角色信息缓存"/>
|
||||||
<add key="MenuData-CodeMenuHelper" interval="600" desc="菜单信息缓存" />
|
<add key="MenuData-CodeMenuHelper" interval="600" desc="菜单信息缓存" />
|
||||||
</cacheManager>
|
</cacheManager>
|
||||||
|
|
||||||
|
|
|
@ -18,10 +18,9 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class RoleHelper
|
public class RoleHelper
|
||||||
{
|
{
|
||||||
// UNDONE: 两个缓存考虑可以共用,待完善
|
|
||||||
private const string RoleDataKey = "RoleData-CodeRoleHelper";
|
private const string RoleDataKey = "RoleData-CodeRoleHelper";
|
||||||
private const string RoleUserIDDataKey = "RoleData-CodeRoleHelper-";
|
private const string RoleUserIDDataKey = "RoleData-CodeRoleHelper-";
|
||||||
private const string RoleNavigationIDDataKey = "RoleData-CodeRoleHelper-Navigation";
|
private const string RoleNavigationIDDataKey = "RoleData-CodeRoleHelper-Navigation-";
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查询所有角色
|
/// 查询所有角色
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -222,17 +221,17 @@ namespace Bootstrap.DataAccess
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="menuId"></param>
|
/// <param name="menuId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<Role> RetrieveRolesByMenuId(string menuId)
|
public static IEnumerable<Role> RetrieveRolesByMenuId(int menuId)
|
||||||
{
|
{
|
||||||
string sql = "select *,case when (ID in( select RoleID from NavigationRole where NavigationID=@NavigationID)) then 1 else 0 end as IsSelect from Roles";
|
|
||||||
string k = string.Format("{0}{1}", RoleNavigationIDDataKey, menuId);
|
string k = string.Format("{0}{1}", RoleNavigationIDDataKey, menuId);
|
||||||
var ret = CacheManager.GetOrAdd(k, CacheSection.RetrieveIntervalByKey(RoleNavigationIDDataKey), key =>
|
return CacheManager.GetOrAdd(k, CacheSection.RetrieveIntervalByKey(RoleUserIDDataKey), key =>
|
||||||
{
|
{
|
||||||
List<Role> Roles = new List<Role>();
|
List<Role> Roles = new List<Role>();
|
||||||
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join NavigationRole ur on r.ID = ur.RoleID and NavigationID = @NavigationID";
|
||||||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@NavigationID", menuId, ParameterDirection.Input));
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
|
||||||
|
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@NavigationID", menuId, ParameterDirection.Input));
|
||||||
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
|
@ -242,15 +241,14 @@ namespace Bootstrap.DataAccess
|
||||||
ID = (int)reader[0],
|
ID = (int)reader[0],
|
||||||
RoleName = (string)reader[1],
|
RoleName = (string)reader[1],
|
||||||
Description = (string)reader[2],
|
Description = (string)reader[2],
|
||||||
IsSelect = (int)reader[3]
|
Checked = (string)reader[3]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
catch (Exception ex) { ExceptionManager.Publish(ex); }
|
||||||
return Roles;
|
return Roles;
|
||||||
}, CacheSection.RetrieveDescByKey(RoleNavigationIDDataKey));
|
}, CacheSection.RetrieveDescByKey(RoleUserIDDataKey));
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue