DoMes Platform Home Menu Bar

Question 1: The menu bar on the left of where the data is acquired?

Answer 1:

Project more directories Views / Home / Index file as a platform Home

Index.cshtml open a file, there is a framework-clientdata.js introduction of this page

Open framework-clientdata.js file, there is a ajax request, when the request is "acquisition client data", the "client data acquisition" return value authorizeMenu and authorizeButton, and returns the value returned to the Index page (Clients)

Open ClientsDataController / GetClientsDataJson () method, and it really is to get a menu button (not elaborate on the specific access)

Question 2: DoMes create a platform on the Page Setup menu, if the parent node of the value value is 0, but in turn save ParentId from 0 instead of null, such a result is not echo "parent" When you modify a menu, how to make it echoes parent?

Answer 2:

Save To echo the parent at the time of modification, only need to save time is zero, but do not convert and save null value, then the problem is preserved ParentId 0, how to make the place acquired the right to display the menu: analysis?

Form 1. Open the modified pages, view data source ParentId drop-down box is / SystemManage / Module / GetTreeSelectJson

2. View / SystemManage / Module / GetTreeSelectJson method, which is the most important place treeList.TreeSelectJson ()

3. See treeList.TreeSelectJson (), this method has two prior values ​​are null (wreath at), the entire string to 0

Thus, the higher the value of the modified pages of the drop-down box can normally acquire and display the data value of 0 ParentId

Question 3: Although the modified pages display correctly, but the menu management page does not display correctly ParentId 0, while still displaying ParentId is null data, how do?

Answer 3:

1.打开系统菜单Index页面,找到获取数据的路径/SystemManage/Module/GetTreeGridJson

2.打开此路径/SystemManage/Module/GetTreeGridJson,此方法最主要的地方是treeList.TreeGridJson()

 3.打开treeList.TreeGridJson()方法,此方法有一处给ParentId赋值null,并依据此值判断查询,将此处的Null值改为字符串0

 至此,系统菜单页面可以正常获取ParentId为0的数据并显示了

问题4:更改完以上内容后,刷新项目,发现左侧菜单一个也不显示了?怎么回事?

答案4:首先回到答案1的结尾,继续跟踪是如何获取菜单内容的

1.进入GetMenuList()方法内,此方法最主要的还是this.ToMenuJson(menuList, "0");语句,将此方法的第二个参数null改为字符串0,因为ToMenuJson(List<Sys_Module> data, string parentId)方法内有根据ParentId进行判断查询

2.进入GetMenuButtonList()方法,此方法并没有根据ParentId进行判断的地方也没有对返回值进行处理,没有需要更改的地方

 

3.更改完上述操作后再次刷新页面发现还是没有菜单数据!!!

4.接着分析发现:ClientsDataController/GetClientsDataJson()方法执行完仅仅是"<script src="~/Content/js/framework-clientdata.js"></script>"执行完,而Home/Index页面末尾还有几个js引入进来,其中有一个index.js文件

5.打开index.js文件,有一个GetLoadNav()方法,此方法正好是调用了framework-clientdata.js执行完返回的数据clients并进行循环判断,其中就有根据ParentId是否为Null的判断,将null改为字符串0

6.最后重新编译解决方案,并且清空浏览器的缓存,再次登陆项目,发现可以正确显示菜单了!!!

问题5:ParentId不存Null改为存储字符串0,会不会对角色授权部分有影响?

答案5:

1.打开新增修改角色权限的页面,找到数据源标签及数据访问地址/SystemManage/RoleAuthorize/GetPermissionTree?roleId=

2.打开此地址“/SystemManage/RoleAuthorize/GetPermissionTree?roleId=”对应的方法,此方法较长截图其中一部分,其余代码另行附上,其中最主要的还是返回值的处理上TreeHelper.ConvertToJson(treeList)

 1  /// <summary>
 2         /// 根据角色Id获取已经授权的权限
 3         /// </summary>
 4         /// <param name="roleId">角色Id</param>
 5         /// <returns></returns>
 6         public ActionResult GetPermissionTree(string roleId)
 7         {
 8             var IsAdmin = this.CurrentSession.IsAdmin;
 9             var LoginroleId = this.CurrentSession.RoleId;//值为NULL,何时不为NULL
10             //获取所有的菜单列表:64个菜单
11             List<Sys_Module> AllModuleList = this.CreateService<IRoleAuthorizeAppService>().GetMenuList(LoginroleId, IsAdmin);
12             //获取所有的按钮列表:150个按钮
13             List<Sys_ModuleButton> AllButtonList = (this.CreateService<IModuleButtonAppService>() as ModuleButtonAppService).GetModelList<Sys_ModuleButton>(null);
14             //获取角色Id为roleId,已配置权限的菜单权限列表
15             List<Sys_RoleAuthorize> Authorizedata = this.CreateService<IRoleAuthorizeAppService>().GetList(roleId);//该角色的按钮权限有11个
16             if (string.IsNullOrEmpty(roleId))
17             {
18                 List<TreeViewModel> treeList = new List<TreeViewModel>();
19                 foreach (Sys_Module module in AllModuleList)
20                 {
21                     TreeViewModel tree = new TreeViewModel();
22                     bool hasChildren = AllModuleList.Any(a => a.ParentId == module.Id);
23                     tree.Id = module.Id;
24                     tree.Text = module.Name;
25                     tree.Value = module.EnCode;
26                     tree.ParentId = module.ParentId;
27                     tree.Isexpand = true;
28                     tree.Complete = true;
29                     tree.Showcheck = true;
30                     tree.Checkstate = AllButtonList.Count(t => t.ModuleId == module.Id);
31                     tree.HasChildren = true;
32                     tree.Img = module.Icon == "" ? "" : module.Icon;
33                     treeList.Add(tree);
34                 }
35                 foreach (Sys_ModuleButton moduleButton in AllButtonList)
36                 {
37                     TreeViewModel tree = new TreeViewModel();
38                     bool hasChildren = AllModuleList.Any(a => a.ParentId == moduleButton.Id);
39                     tree.Id = moduleButton.Id;
40                     tree.Text = moduleButton.FullName;
41                     tree.Value = moduleButton.EnCode;
42                     tree.ParentId = moduleButton.ModuleId;
43                     tree.Isexpand = true;
44                     tree.Complete = true;
45                     tree.Showcheck = true;
46                     tree.Checkstate = AllButtonList.Count(t => t.ModuleId == moduleButton.Id);
47                     tree.HasChildren = hasChildren;
48                     tree.Img = moduleButton.Icon == "" ? "" : moduleButton.Icon;
49                     treeList.Add(tree);
50                 }
51                 return Content(TreeHelper.ConvertToJson(treeList));
52             }
53             else
54             {
55                 List<TreeViewModel> treeList = new List<TreeViewModel>();
56                 foreach (Sys_Module module in AllModuleList)
57                 {
58                     TreeViewModel tree = new TreeViewModel();
59                     bool hasChildren = AllModuleList.Any(a => a.ParentId == module.Id);
60                     tree.Id = module.Id;
61                     tree.Text = module.Name;//显示内容
62                     tree.Value = module.EnCode;
63                     tree.ParentId = module.ParentId;
64                     tree.Isexpand = true;
65                     tree.Complete = true;
66                     tree.Showcheck = true;
67                     tree.Checkstate = Authorizedata.Count(t => t.ModuleId == module.Id);//复选框的状态应该有是否配置权限决定
68                     tree.HasChildren = true;
69                     tree.Img = module.Icon == "" ? "" : module.Icon;
70                     treeList.Add(tree);
71                 }
72                 foreach (Sys_ModuleButton moduleButton in AllButtonList)
73                 {
74                     TreeViewModel tree = new TreeViewModel();
75                     //bool hasChildren = AllModuleList.Any(a => a.ParentId == moduleButton.Id);
76                     tree.Id = moduleButton.Id;
77                     tree.Text = moduleButton.FullName;
78                     tree.Value = moduleButton.EnCode;
79                     tree.ParentId = moduleButton.ModuleId;
80                     tree.Isexpand = true;
81                     tree.Complete = true;
82                     tree.Showcheck = true;
83                     tree.Checkstate = Authorizedata.Count(t => t.ModuleId == moduleButton.Id);
84                     //tree.HasChildren = hasChildren;
85                     tree.Img = moduleButton.Icon == "" ? "" : moduleButton.Icon;
86                     treeList.Add(tree);
87                 }
88                 return Content(TreeHelper.ConvertToJson(treeList,"0"));
89             }
90 
91         }
View Code

 

3.打开TreeHelper类,有三个ConvertToJson()方法,其中前两个是调用者的roleId为空时执行的,后面一个方法是调用者的roleId不为空时执行的,绿色圈起来的地方均是由null改为了字符串0

public static string ConvertToJson(this List<TreeViewModel> data, string parentId = "0")
        {
            StringBuilder strJson = new StringBuilder();
            List<TreeViewModel> item = data.FindAll(t => t.ParentId == parentId);
            strJson.Append("[");
            if (item.Count > 0)
            {
                foreach (TreeViewModel entity in item)
                {
                    strJson.Append("{");
                    strJson.Append("\"id\":\"" + entity.Id + "\",");
                    strJson.Append("\"text\":\"" + entity.Text.Replace("&nbsp;", "") + "\",");
                    strJson.Append("\"value\":\"" + entity.Value + "\",");
                    if (entity.Title != null && !string.IsNullOrEmpty(entity.Title.Replace("&nbsp;", "")))
                    {
                        strJson.Append("\"title\":\"" + entity.Title.Replace("&nbsp;", "") + "\",");
                    }
                    if (entity.Img != null && !string.IsNullOrEmpty(entity.Img.Replace("&nbsp;", "")))
                    {
                        strJson.Append("\"img\":\"" + entity.Img.Replace("&nbsp;", "") + "\",");
                    }
                    if (entity.Checkstate != null)
                    {
                        strJson.Append("\"checkstate\":" + entity.Checkstate + ",");
                    }
                    if (entity.ParentId != null)
                    {
                        strJson.Append("\"parentnodes\":\"" + entity.ParentId + "\",");
                    }
                    strJson.Append("\"showcheck\":" + entity.Showcheck.ToString().ToLower() + ",");
                    strJson.Append("\"isexpand\":" + entity.Isexpand.ToString().ToLower() + ",");
                    if (entity.Complete == true)
                    {
                        strJson.Append("\"complete\":" + entity.Complete.ToString().ToLower() + ",");
                    }
                    strJson.Append("\"hasChildren\":" + entity.HasChildren.ToString().ToLower() + ",");
                    strJson.Append("\"ChildNodes\":" + ConvertToJson(data, entity.Id) + "");
                    strJson.Append("},");
                }
                strJson = strJson.Remove(strJson.Length - 1, 1);
            }
            strJson.Append("]");
            return strJson.ToString();
        }
View Code

 

4.至此角色权限的配置就可以正常使用了。

Guess you like

Origin www.cnblogs.com/luna-hehe/p/11207125.html