var pageSelect = pageActionList.Where(m => m.PageUrl == actionUrl); if (pageSelect != null && pageSelect.Count() > 0) { //判断有无执行该页面的权利
View Code这个是用来判断当前执行的方法是否在全部要显示的页面之中,如果不是则直接输出,是的话继续往下走。
codeList = AdminMenuHelper.LoadActionCodeList(); codeSelect = codeList.Where(m => m.ActionCode == actionCode); if (codeSelect != null && codeSelect.Count() > 0) { int codeId = codeSelect.First().Id; JavaScriptSerializer serializer = new JavaScriptSerializer(); roleActionList = pageSelect.First().RoleActionList;
View Code这里是先判断了当前执行的方法按钮是否在该管理员所属的角色 可操作的按钮之中,不是的话直接输出,如果是的话则继续往下走。
List<AuthorDesign.Web.Areas.Admin.Models.RolePageActionModel> roleActionListModel = serializer.Deserialize<List<AuthorDesign.Web.Areas.Admin.Models.RolePageActionModel>>(roleActionList); if (roleActionListModel != null && roleActionListModel.Where(m => m.ActionId == codeId && m.actionChecked == 1).Count() > 0) { //判断CodeId在管理员动作列表中是否为选择状态 List<AuthorDesign.Web.Areas.Admin.Models.RolePageActionModel> adminActionListModel = serializer.Deserialize<List<AuthorDesign.Web.Areas.Admin.Models.RolePageActionModel>>(pageSelect.First().AdminActionList); if (adminActionListModel != null && adminActionListModel.Where(m => m.ActionId == codeId && m.actionChecked == 1).Count() > 0) { StringBuilder sb = new StringBuilder(); sb.Append(); (var item in roleActionListModel) { if (item.actionChecked == 1) { var needChangeAction = adminActionListModel.Where(m => m.ActionId == item.ActionId).FirstOrDefault(); if (needChangeAction == null) { item.actionChecked = 0; } else if (needChangeAction.actionChecked == 0) { item.actionChecked = 0; } } AuthorDesign.Model.PageAction OneAction = codeList.Where(m => m.Id == item.ActionId).FirstOrDefault(); sb.Append().Append().Append().Append().Append().Append().Append(OneAction == ).Append().Append().Append().Append().Append().Append(item.actionChecked).Append().Append(); } sb.Remove(sb.Length - 1, 1); sb.Append(); filterContext.Controller.ViewBag.CanOperationActionList = sb.ToString();
View Code这部分就是主要用来判断当前执行的方法是否在该管理员可执行的按钮之中,如果在的话那么将改页面的按钮以及是否可操作状态通过ViewBag进行传到前台,然后前台利用Js来移除相对应的不显示按钮。
左边的菜单按钮部分待会上源码自己去看下吧