GetPermission

public void GetPermission(List<PermissionEntity> permissions, int index, string pid, JArray root)
        {
            PermissionEntity entity = null;
            if (index >= permissions.Count)
            {
                return;
            }
            else if (index != -1)//一级菜单
            {
                entity = permissions[index];
            }
            else
            {
                //子菜单
                if (!string.IsNullOrEmpty(pid))
                {
                    entity = permissions.Where(d => d.Id == pid).FirstOrDefault();
                }
                else
                {
                    return;
                }
            }

            var node = new JObject();
            node.Add("id", entity.Id);
            node.Add("path", entity.Path);
            node.Add("name", entity.Name);
            node.Add("redirect", entity.Name);
            var node2 = new JObject();
            node2.Add("title", entity.Title);
            node2.Add("icon", entity.Icon);
            node.Add("meta", node2);
            node.Add("ability", new JArray());
            var childeData = new JArray();
            var childe = permissions.Where(d => d.Pid == entity.Id).FirstOrDefault();
            if (childe != null)
            {
                GetPermission(permissions, -1, childe.Id, childeData);
            }
            node.Add("children", childeData);

            if (index != -1)//一级菜单查询
            {
                GetPermission(permissions, ++index, "", root);
            }
            root.Add(node);

            var currentIndex = permissions.IndexOf(entity);
            permissions.RemoveAt(currentIndex); //删除已添加节点项
        }

  

posted @ 2021-03-04 09:56  dreamw  阅读(306)  评论(0编辑  收藏  举报