示例#1
0
        public async Task <ApiResult <List <CommonTreeModel> > > GetModuleTreeAuthList(string Id)
        {
            ApiResult <List <CommonTreeModel> > res = new ApiResult <List <CommonTreeModel> >();

            res.data = new List <CommonTreeModel>();
            TokenModelBeta token = JwtToken.ParsingJwtToken(HttpContext);

            try
            {
                //获取可以看到的 模块
                var ModuleList = await _sysRoleAuthorizeService.GetRoleModuleByIdAsync(token.Role);

                if (ModuleList.Count > 0)
                {
                    //查询这个角色是否是菜单
                    var role = await _sysRoleService.QueryByIDAsync(Id);

                    //如果不是菜单
                    if (!string.IsNullOrEmpty(Id) && !UniversalTool.ModuleIsNull(role))
                    {
                        //获取传入角色的权限信息
                        List <string> roleKeyList = (await _sysRoleAuthorizeService.GetRoleModuleByIdAsync(Id)).Select(s => s.key).ToList();
                        ModuleList.Where(a => roleKeyList.Contains(a.key) && a.type == 1).ToList().ForEach(a => a.@checked = true);
                        //如果打开的是自己的就禁用
                        if (Id == token.Role)
                        {
                            ModuleList.ForEach(a => a.disableCheckbox = true);
                        }
                    }

                    res.data.AddRange(TreeGenerateTools.TreeGroup(ModuleList, "00000000-0000-0000-0000-000000000000"));
                }
            }
            catch (Exception ex)
            {
                res.code    = (int)ApiEnum.Error;
                res.message = "异常:" + ex.Message;
            }

            return(await Task.Run(() => res));
        }