diff --git a/Bootstrap.Admin/Content/js/framework.js b/Bootstrap.Admin/Content/js/framework.js
index 0c6e879f..f87932ee 100644
--- a/Bootstrap.Admin/Content/js/framework.js
+++ b/Bootstrap.Admin/Content/js/framework.js
@@ -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('
', 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 = {};
diff --git a/Bootstrap.Admin/Controllers/RolesController.cs b/Bootstrap.Admin/Controllers/RolesController.cs
index 9e198f40..83bd0a2d 100644
--- a/Bootstrap.Admin/Controllers/RolesController.cs
+++ b/Bootstrap.Admin/Controllers/RolesController.cs
@@ -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;
}
///
///
@@ -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;
}
diff --git a/Bootstrap.Admin/Scripts/Menus.js b/Bootstrap.Admin/Scripts/Menus.js
index 0e53dc5f..f8da8a4f 100644
--- a/Bootstrap.Admin/Scripts/Menus.js
+++ b/Bootstrap.Admin/Scripts/Menus.js
@@ -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('', element.ID, element.RoleName);
- } else if (element.IsSelect == 0) {
- return $.format('', element.ID, element.RoleName);
- }
- }).join('');
$('#dialogRole form').html(data);
$('#dialogRole').modal('show');
});
diff --git a/Bootstrap.Admin/Scripts/Users.js b/Bootstrap.Admin/Scripts/Users.js
index 44de58c4..8d614e08 100644
--- a/Bootstrap.Admin/Scripts/Users.js
+++ b/Bootstrap.Admin/Scripts/Users.js
@@ -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('', element.ID, element.RoleName, element.Checked, element.Description);
- }).join('');
$('#dialogRole form').html(data);
$('#dialogRole').modal('show');
});
diff --git a/Bootstrap.Admin/Views/Admin/Menus.cshtml b/Bootstrap.Admin/Views/Admin/Menus.cshtml
index 03787687..76e6c44c 100644
--- a/Bootstrap.Admin/Views/Admin/Menus.cshtml
+++ b/Bootstrap.Admin/Views/Admin/Menus.cshtml
@@ -1,76 +1,81 @@
-@model NavigatorBarModel
-@{
- ViewBag.Title = "菜单管理";
- Layout = "~/Views/Shared/_Default.cshtml";
-}
-@section css {
-
-}
-@section Javascript {
-
-}
-@section header {
- @Html.Partial("Header", Model)
-}
-@section navigator {
- @Html.Partial("Navigator", Model)
-}
-@section query {
-
-}
-@section toolbar {
-
-}
-@section modal {
-
-
-}
-@section customModal {
- @Html.Partial("RoleConfig")
- @Html.Partial("IconView")
-}
+@model NavigatorBarModel
+@{
+ ViewBag.Title = "菜单管理";
+ Layout = "~/Views/Shared/_Default.cshtml";
+}
+@section css {
+
+}
+@section Javascript {
+
+}
+@section header {
+ @Html.Partial("Header", Model)
+}
+@section navigator {
+ @Html.Partial("Navigator", Model)
+}
+@section query {
+
+}
+@section toolbar {
+
+}
+@section modal {
+
+
+}
+@section customModal {
+ @Html.Partial("RoleConfig")
+ @Html.Partial("IconView")
+}
diff --git a/Bootstrap.Admin/Web.config b/Bootstrap.Admin/Web.config
index 811f1a94..902add1e 100644
--- a/Bootstrap.Admin/Web.config
+++ b/Bootstrap.Admin/Web.config
@@ -29,7 +29,7 @@
-
+
diff --git a/Bootstrap.DataAccess/RoleHelper.cs b/Bootstrap.DataAccess/RoleHelper.cs
index d43d4e45..e0bf8a0f 100644
--- a/Bootstrap.DataAccess/RoleHelper.cs
+++ b/Bootstrap.DataAccess/RoleHelper.cs
@@ -18,10 +18,9 @@ namespace Bootstrap.DataAccess
///
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-";
///
/// 查询所有角色
///
@@ -222,17 +221,17 @@ namespace Bootstrap.DataAccess
///
///
///
- public static IEnumerable RetrieveRolesByMenuId(string menuId)
+ public static IEnumerable 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 Roles = new List();
- 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));
}
///