Example #1
0
        /// <summary>
        /// 根据某用户的用户名查询该用户可以访问的菜单项(系统左侧边栏菜单)
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public MsgModel GetMenuTreeByUsername(string username)
        {
            MsgModel msg = new MsgModel()
            {
                isok    = true,
                message = "查询成功!"
            };
            List <sys_menu> sysMenus = _mySystemService.SelectMenuByUserName(username);

            if (sysMenus.Count > 0)
            {
                int rootMenuId = sysMenus.First().id;

                List <SysMenuNode> sysMenuNodes = new List <SysMenuNode>();
                foreach (sys_menu sys_menu in sysMenus)
                {
                    SysMenuNode sysMenuNode = sys_menu.BuildAdapter().AdaptToType <SysMenuNode>();
                    sysMenuNodes.Add(sysMenuNode);
                }
                msg.data = DataTreeUtil <SysMenuNode, int> .BuildTreeWithoutRoot(sysMenuNodes, rootMenuId);

                return(msg);
            }
            msg.data = new List <SysMenuNode>();
            return(msg);
        }
Example #2
0
        /// <summary>
        /// 菜单管理:根据查询条件查询树形结构菜单列表
        /// </summary>
        /// <param name="menuNameLike">菜单名称</param>
        /// <param name="menuStatus">菜单可用状态</param>
        /// <returns>菜单列表或树形列表</returns>
        public MsgModel GetMenuTree(string menuNameLike, bool?menuStatus)
        {
            MsgModel msg = new MsgModel
            {
                message = "查询成功!",
                isok    = true
            };

            //保证数据库里面level=1的节点只有一个,根节点
            sys_menu rootSysMenu = _baseSysMenuService.GetModels(a => a.level == 1).SingleOrDefault();

            if (rootSysMenu != null)
            {
                int                rootMenuId   = rootSysMenu.id;
                List <sys_menu>    sysMenus     = _mySystemService.SelectMenuTree(rootMenuId, menuNameLike, menuStatus);
                List <SysMenuNode> sysMenuNodes = new List <SysMenuNode>();
                foreach (sys_menu sys_menu in sysMenus)
                {
                    SysMenuNode sysMenuNode = sys_menu.BuildAdapter().AdaptToType <SysMenuNode>();
                    sysMenuNodes.Add(sysMenuNode);
                }
                if (!string.IsNullOrEmpty(menuNameLike))
                {
                    // 根据菜单名称查询,返回平面列表
                    msg.data = sysMenuNodes;
                    return(msg);
                }
                else
                {
                    // 否则返回菜单的树型结构列表
                    msg.data = DataTreeUtil <SysMenuNode, int> .BuildTree(sysMenuNodes, rootMenuId);

                    return(msg);
                }
            }
            else
            {
                // "请先在数据库内为菜单配置一个分类的根节点,level=1"
                msg.message = "请先在数据库内为菜单配置一个分类的根节点,level=1";
                msg.data    = new List <SysMenuNode>();
                return(msg);
            }
        }