コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public static List <Sysmenu> GetListByuserid_Sysmenu(int userid)
        {
            var menulist = new List <Sysmenu>();

            try
            {
                if (userid <= 0)
                {
                    return(menulist);
                }

                //1是超管
                if (userid == 1)
                {
                    return(GetAllList());
                }
                else
                {
                    var userrole = SysroleLogic.GetListByInSelect(nameof(Sysuserrole), nameof(Sysrole.KID), nameof(Sysuserrole.Roleid), new Dictionary <string, object>()
                    {
                        { nameof(Sysmenu.IsDeleted), 0 },
                        { nameof(Sysmenu.States), 0 }
                    },
                                                                  new Dictionary <string, object>()
                    {
                        { nameof(Sysuserrole.Userid), userid }
                    });

                    var roleids = string.Join(",", userrole.Select(x => x.KID));
                    var roles   = SysroleLogic.GetList(new Dictionary <string, object>()
                    {
                        { $"{nameof(Sysrole.KID)}|i", roleids }
                    });
                    var menulists = string.Join(",", roles.Select(x => x.MenuList));
                    menulist = GetList(new Dictionary <string, object>()
                    {
                        {
                            $"{nameof(Sysmenu.KID)}|i", menulists
                        },
                        { nameof(Sysmenu.IsDeleted), 0 }
                    });
                }
            }
            catch (Exception ex)
            {
            }

            return(menulist);
        }
コード例 #2
0
        /// <summary>
        /// 根据员工账号查询菜单
        /// </summary>
        /// <param name="userKID">员工账号ID</param>
        /// <returns>
        /// UserAuthorMenu.
        /// </returns>
        public static UserAuthorMenu GetMenuByUserID(int userKID)
        {
            //递归查询得到菜单信息
            UserAuthorMenu ret = new UserAuthorMenu()
            {
                UserMenuList = new List <zTreeModel>()
            };

            var allmenu = GetAllList().OrderByDescending(t => t.Menusort);

            var roleList = new List <Sysrole>();

            var dic = new Dictionary <string, object>();

            if (userKID > 1)
            {
                dic.Add(nameof(Sysuserrole.Userid), userKID);
                var roleLst = SysuserroleLogic.GetList(dic);

                if (roleLst.Count() == 0)
                {
                    return(new UserAuthorMenu()
                    {
                        Message = "未分配权限角色,请联系管理员开通权限"
                    });
                }

                var allRoleIds = string.Join(",", roleLst.Select(p => p.Roleid).ToArray());

                if (allRoleIds.Count() == 0)
                {
                    return(new UserAuthorMenu()
                    {
                        Message = "未分配权限角色,请联系管理员开通权限"
                    });
                }

                dic = new Dictionary <string, object>();
                dic.Add(nameof(Sysrole.KID) + "|i", allRoleIds);

                dic.Add(nameof(Sysrole.IsDeleted), 0);

                roleList = SysroleLogic.GetList(dic);

                if (roleList.Count() == 0)
                {
                    return(new UserAuthorMenu()
                    {
                        Message = "不存在对应角色,请联系管理员开通权限"
                    });
                }
                List <string> removelst = new List <string>();

                var allAuthMenu = string.Join(",", roleList.Select(p => p.MenuList).ToArray()).Split(',').ToList();

                foreach (var item in allmenu.Where(p => allAuthMenu.Contains(p.KID.ToString())).OrderByDescending(k => k.Menusort))
                {
                    if (item.IsNull())
                    {
                        continue;
                    }
                    if (item.IsNull() || removelst.Contains(item.KID.ToString()))
                    {
                        continue;
                    }
                    removelst.Add(item.KID.ToString());

                    ret.UserMenuList.Add(new zTreeModel()
                    {
                        id   = item.KID.ToString(),
                        pId  = item.Fatherid.ToString(),
                        name = item.Menuname,
                        url  = item.MenuUrl,
                        sort = item.Menusort,
                        ico  = item.Menuicon,
                        open = true
                    });
                }
            }
            else
            {
                foreach (var item in allmenu.OrderByDescending(p => p.Menusort))
                {
                    ret.UserMenuList.Add(new zTreeModel()
                    {
                        id   = item.KID.ToString(),
                        pId  = item.Fatherid.ToString(),
                        name = item.Menuname,
                        url  = item.MenuUrl,
                        sort = item.Menusort,
                        ico  = item.Menuicon,
                        open = true
                    });
                }
            }
            if (ret.UserMenuList.Count() > 0)
            {
                ret.IsSucceed = true;
                ret.Message   = "菜单获取成功";
            }
            else
            {
                ret.Message = "未找到对应菜单,请联系管理员";
            }

            return(ret);
        }