zoukankan      html  css  js  c++  java
  • DoMes平台首页菜单栏

    问题1:左侧菜单栏数据是在哪里获取的?

    答案1:

    项目根目录的Views/Home/Index文件为平台首页

    打开Index.cshtml文件,有一个framework-clientdata.js引入此页面

    打开framework-clientdata.js文件,有一个ajax请求,该请求时"获取客户端数据",该"获取客户端数据"返回值有authorizeMenu和authorizeButton,并将返回值返回到Index页面(clients)

    打开ClientsDataController/GetClientsDataJson()方法,果然是获取菜单和按钮的(具体的获取就不再细说)

    问题2:DoMes平台在创建菜单页面上设置,若是父节点则value值是0,但保存时又将ParentId由0改为了null,这样的结果是修改菜单时无法回显"父节点",如何让它回显父节点?

    答案2:

    分析:要想在修改时回显父节点,只需要保存的时候保存为0即可,不要转换为null值保存,那么问题是保存了ParentId为0,如何让所获取菜单的地方正确显示的?

    1.打开Form修改页面,查看ParentId下拉框的数据源是/SystemManage/Module/GetTreeSelectJson

    2.查看/SystemManage/Module/GetTreeSelectJson方法,此方法最主要的地方是treeList.TreeSelectJson()

    3.查看treeList.TreeSelectJson(),此方法有两处之前均为null值(花圈处),全部改为字符串0

    至此,修改页面的上级下拉框的值就可以正常获取并显示ParentId值为0的数据了

    问题3:虽然修改页面正确显示了,但是菜单管理页面并没有正确显示ParentId为0的,而依旧是显示ParentId为null的数据,怎么做?

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

  • 相关阅读:
    出现Invalid input of type: 'CacheKey'. Convert to a byte, string or number first
    如果错误发生在某个封装号的模块中,那请查看数据库里面的数据是不是哪里出现问题
    发现匿名用户问题
    关于序列化器中class Meta中属性说明
    序列化和反序列化
    前端出现has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource
    出现bad ruqest,查找原因思路
    注册验证出现错误Define UserView.model, UserView.queryset, or override UserView.get_queryset()
    跨域问题
    celery异步使用和启动方法
  • 原文地址:https://www.cnblogs.com/luna-hehe/p/11207125.html
Copyright © 2011-2022 走看看