修改菜单指派角色功能

This commit is contained in:
Argo-Lenovo 2016-10-28 14:45:09 +08:00
parent 35c915c3e8
commit 83bdfe3b71
7 changed files with 110 additions and 135 deletions

View File

@ -221,7 +221,15 @@
data: data.data,
type: data.method,
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) {
if ($.isFunction(data.callback)) data.callback(false);
@ -236,39 +244,14 @@
Role.getRolesByGroupId = function (groupId) {
processRolesData({ Id: groupId, callback: callback, data: { type: "group" } });
};
//查询菜单对应角色
Role.getRolesByMenuId = function (menuId, callback) {
$.ajax({
url: '../api/Roles/' + menuId,
data: { "": "menu" },
type: 'POST',
success: function (result) {
callback(result);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
callback();
}
});
processRolesData({ Id: menuId, callback: callback, data: { type: "menu" } });
};
Role.saveRolesByUserId = function (userId, roleIds, callback) {
processRolesData({ Id: userId, callback: callback, method: "PUT", data: { type: "user", roleIds: roleIds } });
}
//保存菜单对应角色
Role.saveRolesByMenuId = function (menuId, roleIds, callback) {
$.ajax({
url: '../api/Roles/' + menuId,
data: { "roleIds": roleIds, "type": "menu" },
type: 'PUT',
success: function (result) {
callback(result);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
callback();
}
});
processRolesData({ Id: menuId, callback: callback, method: "PUT", data: { type: "menu", roleIds: roleIds } });
};
Group = {};

View File

@ -37,15 +37,13 @@ namespace Bootstrap.Admin.Controllers
case "group":
ret = RoleHelper.RetrieveRolesByGroupId(id).ToList();
break;
case "menu"
ret = RoleHelper.RetrieveRolesByMenuId(id.ToString());
case "menu":
ret = RoleHelper.RetrieveRolesByMenuId(id).ToList();
break;
default:
break;
}
else
{
return null;
}
return ret;
}
/// <summary>
///
@ -66,8 +64,9 @@ namespace Bootstrap.Admin.Controllers
case "group":
ret = RoleHelper.SaveRolesByGroupId(id, roleIds);
break;
case "menu":
ret = RoleHelper.SavaRolesByMenuId(id, roleIds);
case "menu":
ret = RoleHelper.SavaRolesByMenuId(id, roleIds);
break;
default:
break;
}

View File

@ -16,15 +16,8 @@
assign: [{
id: 'btn_assignRole',
click: function (row) {
Role.getRolesByMenuId(row.ID, function (roles) {
Role.getRolesByMenuId(row.ID, function (data) {
$("#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').modal('show');
});

View File

@ -13,11 +13,8 @@
assign: [{
id: 'btn_assignRole',
click: function (row) {
Role.getRolesByUserId(row.ID, function (roles) {
Role.getRolesByUserId(row.ID, function (data) {
$("#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').modal('show');
});

View File

@ -57,7 +57,12 @@
</div>
<div class="form-group col-lg-6">
<label class="control-label" for="icon">菜单图标</label>
<input type="text" class="form-control" id="icon" name="icon" maxlength="50" />
<div class="input-group">
<input type="text" class="form-control disabled" disabled id="icon" name="icon" maxlength="50" />
<span class="input-group-btn">
<button class="btn btn-default" type="button"><i></i>选择</button>
</span>
</div>
</div>
<div class="form-group col-lg-6">
<label class="control-label" for="url">路径</label>

View File

@ -29,7 +29,7 @@
<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-Navigation" interval="600" desc="菜单角色信息缓存"/>
<add key="RoleData-CodeRoleHelper-Navigation-" interval="600" desc="菜单角色信息缓存"/>
<add key="MenuData-CodeMenuHelper" interval="600" desc="菜单信息缓存" />
</cacheManager>

View File

@ -18,10 +18,9 @@ namespace Bootstrap.DataAccess
/// </summary>
public class RoleHelper
{
// UNDONE: 两个缓存考虑可以共用,待完善
private const string RoleDataKey = "RoleData-CodeRoleHelper";
private const string RoleUserIDDataKey = "RoleData-CodeRoleHelper-";
private const string RoleNavigationIDDataKey = "RoleData-CodeRoleHelper-Navigation";
private const string RoleNavigationIDDataKey = "RoleData-CodeRoleHelper-Navigation-";
/// <summary>
/// 查询所有角色
/// </summary>
@ -222,17 +221,17 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="menuId"></param>
/// <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);
var ret = CacheManager.GetOrAdd(k, CacheSection.RetrieveIntervalByKey(RoleNavigationIDDataKey), key =>
return CacheManager.GetOrAdd(k, CacheSection.RetrieveIntervalByKey(RoleUserIDDataKey), key =>
{
List<Role> Roles = new List<Role>();
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@NavigationID", menuId, ParameterDirection.Input));
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";
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))
{
while (reader.Read())
@ -242,15 +241,14 @@ namespace Bootstrap.DataAccess
ID = (int)reader[0],
RoleName = (string)reader[1],
Description = (string)reader[2],
IsSelect = (int)reader[3]
Checked = (string)reader[3]
});
}
}
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return Roles;
}, CacheSection.RetrieveDescByKey(RoleNavigationIDDataKey));
return ret;
}, CacheSection.RetrieveDescByKey(RoleUserIDDataKey));
}
/// <summary>