ドームプラットフォームホームメニューバー

質問1:データが取得された場合の左側のメニューバー?

回答1:

プラットフォーム・ホームとしてプロジェクト複数のディレクトリ・ビュー/ホーム/インデックスファイル

ファイルを開くIndex.cshtml、このページのフレームワークclientdata.js導入があります

フレームワークclientdata.jsファイルを開き、要求は、「クライアントデータ取得」戻り値authorizeMenuとauthorizeButtonである「取得クライアントデータ」AJAXリクエストは、そこにあり、その値はインデックスページに戻ります戻ります(クライアント)

(特定のアクセスについて詳しく説明しない)オープンClientsDataController / GetClientsDataJson()メソッド、およびそれは実際にメニューボタンを取得することです

質問2:値値の親ノードが0であればドームは、[ページ設定]メニューのプラットフォームを作成するのではなく、代わりに0のヌルからParentIdは保存今度は、そのような結果を作る方法を、あなたはメニューを変更すると、「親」をエコーではありませんそれは親をエコー?

回答2:

変更の時に親をエコーに保存する、唯一の時間を節約する必要がゼロであるが、null値を変換して保存していない、問題がParentIdは0に保存され、場所を作るためにどのようにメニューを表示する権利を獲得した:分析?

フォーム1.変更されたページ、ビューデータソースParentIdは、ドロップダウンボックスには、/ SystemManage /モジュール/ GetTreeSelectJsonです

最も重要な場所であるtreeList.TreeSelectJson 2. [表示/ SystemManage /モジュール/ GetTreeSelectJson方法、()

3.参照treeList.TreeSelectJson()、この方法は、0に文字列全体(ATリース)ヌル2つの従来の値であるました

したがって、ドロップダウンボックスの変更されたページのより高い値は、通常0 ParentIdはのデータ値を取得し、表示することができ

質問3:変更されたページが正しく表示されますが、メニューの管理ページが正しく表示されませんが、まだParentIdは表示することはどのように行う、ナルデータである一方で、0をPARENTID?

回答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.至此角色权限的配置就可以正常使用了。

おすすめ

転載: www.cnblogs.com/luna-hehe/p/11207125.html