Example #1
0
        /// <summary>
        /// 创建导航对象
        /// </summary>
        /// <param name="url"></param>
        /// <param name="Menus"></param>
        /// <returns></returns>
        public NavInfo CreateNav(string url, List <MenuTreeInfo> Menus)
        {
            MenuTreeInfo menu     = Menus.Find(m => m.url == url);
            NavInfo      navModel = new NavInfo();

            if (menu != null)
            {
                string parentNav = CreateParentNav(Menus, menu.ParentID);
                string nav       = "<li><a href=\"/\"><i class=\"fa fa-dashboard\"></i>首页</a></li>" + parentNav + "<li class=\"active\">" + menu.title + "</li>";
                navModel.Nav   = nav;
                navModel.Title = menu.title;
            }
            return(navModel);
        }
Example #2
0
        /// <summary>
        /// 创建父级导航
        /// </summary>
        /// <param name="menuList"></param>
        /// <param name="parentID"></param>
        /// <returns></returns>
        private static string CreateParentNav(List <MenuTreeInfo> menuList, int parentID)
        {
            if (parentID <= 0)
            {
                return("");
            }
            string       nav  = "";
            MenuTreeInfo menu = menuList.Find(m => m.id == parentID);

            if (menu != null)
            {
                string parentNav = CreateParentNav(menuList, menu.ParentID);
                nav = parentNav + "<li><a href=\"" + (!String.IsNullOrEmpty(menu.url) ? menu.url : "#") + "\">" + menu.title + "</a></li>";
            }
            return(nav);
        }
Example #3
0
        /// <summary>
        /// 获取子菜单权限
        /// </summary>
        /// <param name="list"></param>
        /// <param name="parentID"></param>
        /// <returns></returns>
        private List <MenuTreeInfo> GetChildLimitTree(List <MenuTreeInfo> list, int parentID)
        {
            List <MenuTreeInfo> modelList = new List <MenuTreeInfo>();
            MenuTreeInfo        model     = null;

            foreach (MenuTreeInfo menu in list.FindAll(m => m.ParentID == parentID))
            {
                model          = new MenuTreeInfo();
                model.id       = menu.id;
                model.title    = menu.title;
                model.icon     = menu.icon;
                model.url      = menu.url;
                model.ParentID = menu.ParentID;
                model.Children = GetChildLimitTree(list, menu.id);
                modelList.Add(model);
            }
            return(modelList);
        }
Example #4
0
        /// <summary>
        /// 将菜单集合序列化为父子结构的对象
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public List <MenuTreeInfo> SerializationMenu(List <MenuTreeInfo> list)
        {
            List <MenuTreeInfo> Menus = new List <MenuTreeInfo>();
            //加载根目录
            MenuTreeInfo model = null;

            foreach (MenuTreeInfo menu in list.FindAll(m => m.ParentID <= 0))
            {
                model          = new MenuTreeInfo();
                model.id       = menu.id;
                model.title    = menu.title;
                model.icon     = menu.icon;
                model.url      = menu.url;
                model.ParentID = menu.ParentID;
                model.Children = GetChildLimitTree(list, menu.id);
                Menus.Add(model);
            }
            return(Menus);
        }
Example #5
0
        /// <summary>
        /// 初始化菜单对象
        /// </summary>
        /// <param name="MenuList"></param>
        public List <MenuTreeInfo> InitMenu(string MenuList)
        {
            List <MenuTreeInfo> Menus = new List <MenuTreeInfo>();
            List <Menu>         list  = new DataService.BLL.Menu().GetModelList("MenuID in(" + MenuList + ")");
            //加载根目录
            MenuTreeInfo model = null;

            foreach (Menu menu in list)
            {
                model          = new MenuTreeInfo();
                model.id       = menu.MenuID;
                model.title    = menu.MenuName;
                model.icon     = menu.Icon;
                model.url      = menu.Url;
                model.ParentID = menu.ParentID;
                Menus.Add(model);
            }
            return(Menus);
        }