Ejemplo n.º 1
0
        /// <summary>
        /// 查询Tree
        /// </summary>
        /// <returns></returns>
        public async Task <ApiResult <List <SysMenuTree> > > GetListTreeAsync()
        {
            var list     = SysMenuDb.GetList();
            var treeList = new List <SysMenuTree>();

            foreach (var item in list.Where(m => m.Layer == 1).OrderBy(m => m.Sort))
            {
                //获得子级
                var children = RecursionOrganize(list, new List <SysMenuTree>(), item.Guid);
                treeList.Add(new SysMenuTree()
                {
                    guid     = item.Guid,
                    name     = item.Name,
                    open     = children.Count > 0,
                    children = children.Count == 0 ? null : children
                });
            }
            var res = new ApiResult <List <SysMenuTree> >
            {
                statusCode = 200,
                data       = treeList
            };

            return(await Task.Run(() => res));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据登录账号,获得相应权限
        /// </summary>
        /// <returns></returns>
        public async Task <ApiResult <List <SysMenu> > > GetAuthorizeAsync(string admin)
        {
            var res = new ApiResult <List <SysMenu> >()
            {
                statusCode = (int)ApiEnum.Error
            };

            try
            {
                //根据用户查询角色列表, 一个用户对应多个角色
                var roleList = SysPermissionsDb.GetList(m => m.AdminGuid == admin && m.Types == 2).Select(m => m.RoleGuid).ToList();
                //根据角色获得多个菜单
                var menuList = SysPermissionsDb.GetList(m => roleList.Contains(m.RoleGuid) && m.Types == 1).Select(m => m.MenuGuid).ToList();
                //根据权限菜单查询列表
                res.data       = SysMenuDb.GetList(m => menuList.Contains(m.Guid) && m.Status).OrderBy(m => m.Sort).ToList();
                res.statusCode = (int)ApiEnum.Status;
            }
            catch (Exception ex)
            {
                res.message = ApiEnum.Error.GetEnumText() + ex.Message;
            }
            return(await Task.Run(() => res));
        }