public async Task <MessageModel <NavigationBar> > Get()
        {
            var data  = new MessageModel <NavigationBar>();
            var menus = await menuService.Query(t => t.mIsDeleted == false);

            var menuTrees = (from child in menus
                             select new NavigationBar
            {
                id = child.mID,
                pid = child.mPid,
                order = child.mOrderSort,
                name = child.mName,
                iconCls = child.mIcon,
                path = child.mPath
            }).ToList();
            NavigationBar rootRoot = new NavigationBar()
            {
                id      = 0,
                pid     = 0,
                order   = 0,
                name    = "根节点",
                path    = "",
                iconCls = "",
            };

            RecursionHelper.LoopNaviBarAppendChildren(menuTrees, rootRoot);

            data.success = true;
            if (data.success)
            {
                data.response = rootRoot;
                data.msg      = "获取成功";
            }
            return(data);
        }
        public async Task <MessageModel <NavigationBar> > GetNavigationBar(int uid)
        {
            var data = new MessageModel <NavigationBar>();

            if (uid > 0)
            {
                var roleId = ((await _userRoleServices.Query(d => d.IsDeleted == false && d.UserId == uid)).FirstOrDefault()?.RoleId).ObjToInt();
                if (roleId > 0)
                {
                    var pids = (await _roleModulePermissionServices.Query(d => d.IsDeleted == false && d.RoleId == roleId)).Select(d => d.PermissionId.ObjToInt()).Distinct();

                    if (pids.Any())
                    {
                        var rolePermissionMoudles = (await _permissionServices.Query(d => pids.Contains(d.Id) && d.IsButton == false)).OrderBy(c => c.OrderSort);
                        var permissionTrees       = (from child in rolePermissionMoudles
                                                     where child.IsDeleted == false
                                                     orderby child.Id
                                                     select new NavigationBar
                        {
                            id = child.Id,
                            name = child.Name,
                            pid = child.Pid,
                            order = child.OrderSort,
                            path = child.Code,
                            iconCls = child.Icon,
                            meta = new NavigationBarMeta
                            {
                                requireAuth = true,
                                title = child.Name,
                            }
                        }).ToList();


                        NavigationBar rootRoot = new NavigationBar()
                        {
                            id      = 0,
                            pid     = 0,
                            order   = 0,
                            name    = "根节点",
                            path    = "",
                            iconCls = "",
                            meta    = new NavigationBarMeta(),
                        };

                        permissionTrees = permissionTrees.OrderBy(d => d.order).ToList();

                        RecursionHelper.LoopNaviBarAppendChildren(permissionTrees, rootRoot);

                        data.success = true;
                        if (data.success)
                        {
                            data.response = rootRoot;
                            data.msg      = "获取成功";
                        }
                    }
                }
            }
            return(data);
        }
Exemplo n.º 3
0
        public BaseResponse GetNavigationBar(int uid)
        {
            if (uid > 0)
            {
                var roleId = _userRoleServices.Get(d => d.IsDeleted == false && d.UserId == uid)?.RoleId;
                if (roleId > 0)
                {
                    var pids = _roleModulePermissionServices.Query(d => d.IsDeleted == false && d.RoleId == roleId).Select(d => d.PermissionId).Distinct();
                    if (pids.Any())
                    {
                        var rolePermissionMoudles = _permissionServices.Query(d => pids.Contains(d.Id) && d.IsButton == false).OrderBy(c => c.OrderSort);
                        var permissionTrees       = (from child in rolePermissionMoudles
                                                     where child.IsDeleted == false
                                                     orderby child.Id
                                                     select new NavigationBar
                        {
                            id = child.Id,
                            name = child.Name,
                            pid = (int)child.Pid,
                            order = child.OrderSort,
                            path = child.Code,
                            iconCls = child.Icon,
                            key = child.Key,
                            component = child.Component,
                            isbutton = child.IsButton,
                            meta = new NavigationBarMeta
                            {
                                requireAuth = true,
                                title = child.Name,
                                icon = child.Icon
                            }
                        }).ToList();
                        NavigationBar rootRoot = new NavigationBar()
                        {
                            id        = 0,
                            pid       = 0,
                            order     = 0,
                            name      = "根节点",
                            path      = "",
                            iconCls   = "",
                            component = "BasicLayout",
                            key       = "",
                            meta      = new NavigationBarMeta(),
                        };
                        permissionTrees = permissionTrees.OrderBy(d => d.order).ToList();

                        RecursionHelper.LoopNaviBarAppendChildren(permissionTrees, rootRoot);
                        List <NavigationBar> list = new List <NavigationBar>();
                        list.Add(rootRoot);
                        return(new SuccessResponse(list));
                    }
                }
            }
            return(new SuccessResponse());
        }
Exemplo n.º 4
0
        public async Task <MessageModel <NavigationBar> > GetNavigationBar(int uid)
        {
            var data = new MessageModel <NavigationBar>();

            // 两种方式获取 uid
            var uidInHttpcontext1 = (from item in _httpContext.HttpContext.User.Claims
                                     where item.Type == "jti"
                                     select item.Value).FirstOrDefault().ObjToInt();

            var uidInHttpcontext = (JwtHelper.SerializeJwt(_httpContext.HttpContext.Request.Headers["Authorization"].ObjToString().Replace("Bearer ", "")))?.Uid;

            if (uid > 0 && uid == uidInHttpcontext)
            {
                var roleId = ((await _userRoleServices.Query(d => d.IsDeleted == false && d.UserId == uid)).FirstOrDefault()?.RoleId).ObjToInt();
                if (roleId > 0)
                {
                    var pids = (await _roleModulePermissionServices.Query(d => d.IsDeleted == false && d.RoleId == roleId)).Select(d => d.PermissionId.ObjToInt()).Distinct();

                    if (pids.Any())
                    {
                        var rolePermissionMoudles = (await _permissionServices.Query(d => pids.Contains(d.Id) && d.IsButton == false)).OrderBy(c => c.OrderSort);
                        var permissionTrees       = (from child in rolePermissionMoudles
                                                     where child.IsDeleted == false
                                                     orderby child.Id
                                                     select new NavigationBar
                        {
                            id = child.Id,
                            name = child.Name,
                            pid = child.Pid,
                            order = child.OrderSort,
                            path = child.Code,
                            iconCls = child.Icon,
                            IsHide = child.IsHide.ObjToBool(),
                            meta = new NavigationBarMeta
                            {
                                requireAuth = true,
                                title = child.Name,
                                NoTabPage = child.IsHide.ObjToBool()
                            }
                        }).ToList();


                        NavigationBar rootRoot = new NavigationBar()
                        {
                            id      = 0,
                            pid     = 0,
                            order   = 0,
                            name    = "根节点",
                            path    = "",
                            iconCls = "",
                            meta    = new NavigationBarMeta(),
                        };

                        permissionTrees = permissionTrees.OrderBy(d => d.order).ToList();

                        RecursionHelper.LoopNaviBarAppendChildren(permissionTrees, rootRoot);

                        data.success = true;
                        if (data.success)
                        {
                            data.response = rootRoot;
                            data.msg      = "获取成功";
                        }
                    }
                }
            }
            return(data);
        }
Exemplo n.º 5
0
        public async Task <BaseResponse <RouterBar> > GetNavigationBar(int uid)
        {
            var data = new BaseResponse <RouterBar>();

            try
            {
                #region MyRegion
                //RouterBar rootRoot = new RouterBar()
                //{
                //    id = 0,
                //    pid = 0,
                //    order = 0,
                //    name = "根节点",
                //    path = "",
                //    icon = "",
                //    //meta = new NavigationBarMeta(),
                //};
                //RouterBar lst1 = new RouterBar
                //{
                //    id = 1,
                //    APIAddress = "",
                //    icon = "fa-qq",
                //    leaf = true,
                //    path = "/",
                //    name = "首页",
                //    pid = 1
                //};
                //RouterBar lst1_1 = new RouterBar
                //{
                //    id = 1,
                //    APIAddress = "",
                //    leaf = true,
                //    path = "",
                //    name = "About",
                //    pid = 1
                //};
                //lst1.children.Add(lst1_1);
                //RouterBar lst2 = new RouterBar
                //{
                //    id = 1,
                //    APIAddress = "",
                //    icon = "fa-users",
                //    leaf = false,
                //    path = "/Home",
                //    name = "权限管理",
                //    pid = 1
                //};
                //RouterBar lst2_1 = new RouterBar
                //{
                //    id = 1,
                //    APIAddress = "",
                //    icon = "fa-qq",
                //    leaf = false,
                //    path = "/User/User",
                //    name = "用户管理",
                //    pid = 1
                //};
                //RouterBar lst2_2 = new RouterBar
                //{
                //    id = 1,
                //    APIAddress = "",
                //    icon = "fa-qq",
                //    leaf = false,
                //    path = "/User/Roles",
                //    name = "角色管理",
                //    pid = 1
                //};
                //RouterBar lst2_3 = new RouterBar
                //{
                //    id = 1,
                //    APIAddress = "",
                //    icon = "fa-qq",
                //    leaf = false,
                //    path = "/Menu/Menu",
                //    name = "菜单管理",
                //    pid = 1
                //};
                //lst2.children.Add(lst2_1);
                //lst2.children.Add(lst2_2);
                //lst2.children.Add(lst2_3);
                //rootRoot.children.Add(lst1);
                //rootRoot.children.Add(lst2);
                //data.Data = rootRoot;
                #endregion
                // 三种方式获取 uid
                var uidInHttpcontext1 = (from item in _httpContext.HttpContext.User.Claims
                                         where item.Type == "jti"
                                         select item.Value).FirstOrDefault();
                var uidInHttpcontext = (JwtHelper.SerializeJwt(_httpContext.HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", "")))?.Uid;
                var uName            = _user.Name;
                if (uid > 0 && uid == uidInHttpcontext)
                {
                    var roleId = ((await _userRoleServices.Query(d => d.UserId == uid)).FirstOrDefault()?.RoleId);
                    if (roleId > 0)
                    {
                        var menus = await _menuServices.Query(d => d.IsDrop == false);

                        var menusTrees = (from item in menus
                                          where item.IsDrop == false
                                          orderby item.Id
                                          select new RouterBar
                        {
                            id = item.Id,
                            APIAddress = item.ApiUrl,
                            icon = item.Icon,
                            leaf = item.RoutePath == "-" ? false : true,
                            path = item.RoutePath,
                            name = item.Name,
                            pid = item.ParentId,
                            order = item.OrderSort,
                        }).ToList();

                        RouterBar rootRoot = new RouterBar()
                        {
                            id    = 0,
                            pid   = 0,
                            order = 0,
                            name  = "根节点",
                            path  = "",
                            icon  = ""
                        };
                        menusTrees = menusTrees.OrderBy(d => d.order).ToList();

                        RecursionHelper.LoopNaviBarAppendChildren(menusTrees, rootRoot);
                        data.Data = rootRoot;
                        data.Msg  = "获取成功";
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(data);
        }