Esempio n. 1
0
        public MessageModel GetNavigationBar()
        {
            var authorization = HttpContext.Request.Headers["Authorization"];

            if (string.IsNullOrWhiteSpace(authorization) || authorization.ToString() == "")
            {
                _msg.Success = false;
                _msg.Message = "没有token,您还没有权限";
                return(_msg);
            }
            string        jwtstr = authorization.ToString().Replace("Bearer ", "");
            TokenModelJwt token  = JwtHelper.SerializeJwt(jwtstr);

            Enum.TryParse <RoleHelper.Roletype>(token.Role, out RoleHelper.Roletype roletype);
            int   roleId = (int)roletype;
            Roles model  = _rolesService.GetModel(a => a.Id == roleId);

            if (model != null)
            {
                var          menusIds = model.Menus.Split(',');
                List <Menus> menulist = new List <Menus>();
                foreach (string item in menusIds)
                {
                    var m = _menuservice.GetModel(a => a.Id == int.Parse(item));
                    if (m != null)
                    {
                        menulist.Add(m);
                    }
                }
                List <NavigationBar> all = new List <NavigationBar>();
                all = menulist.Select(child => new NavigationBar
                {
                    id    = child.Id,
                    name  = child.MenuName,
                    pid   = child.Fid,
                    order = 1,
                    path  = child.MenuUrl,
                    meta  = new NavigationBarMeta
                    {
                        requireAuth = true,
                        title       = child.MenuName,
                        NoTabPage   = true
                    }
                }).ToList();

                //这时,所有角色所对应 菜单列表已经出来
                NavigationBar rootRoot = new NavigationBar()
                {
                    id      = 0,
                    pid     = 0,
                    order   = 0,
                    name    = "根节点",
                    path    = "",
                    iconCls = "",
                    meta    = new NavigationBarMeta(),
                };
                Recursion(all, rootRoot);
                _msg.Response = rootRoot;
            }

            _msg.Success = true;
            _msg.Message = "路由节点获取成功!";
            return(_msg);
        }