Esempio n. 1
0
        public List <MenuModels> GetMenuList(string RoleId, string appKey)
        {
            List <View_Sys_RolePurviewAndMenu> menuList = new Sys_RolePurviewBLL().GetMenus(RoleId);
            string javaScript = string.Empty;
            View_Sys_RolePurviewAndMenu        RoleMenuInfo   = menuList.Find(p => p.Menu_ModuleId == appKey);
            List <View_Sys_RolePurviewAndMenu> menuListLevel1 = new List <View_Sys_RolePurviewAndMenu>();

            if (RoleMenuInfo.IsNotNull())
            {
                menuListLevel1 = menuList.FindAll(p => p.Menu_ParentCode == RoleMenuInfo.Menu_Code).OrderBy(p => p.Menu_Sequence).ToList();
            }
            List <MenuModels> tree = new List <MenuModels>();

            menuListLevel1.ForEach(item =>
            {
                tree.Add(new MenuModels
                {
                    menuid   = item.MenuID,
                    menuname = item.Menu_Name,
                    icon     = "icon-" + item.Menu_IconName,
                    url      = item.Menu_Url,
                    child    = children(item.Menu_Code, menuList)
                });
            });

            return(tree);
        }
Esempio n. 2
0
        /// <summary>
        /// 菜单加载
        /// </summary>
        /// <param name="context"></param>
        public void LoadMenuTree(HttpContext context)
        {
            menuList = new Sys_RolePurviewBLL().GetMenus(currentUser.RoleID);//new Sys_RolePurviewBLL().GetRoleMenus(currentUser.UserID);//加载用户菜单
            string javaScript = string.Empty;

            javaScript += "{ 'child': [";
            View_Sys_RolePurviewAndMenu        RoleMenuInfo   = menuList.Find(p => p.Menu_ModuleId == SystemModuleId);
            List <View_Sys_RolePurviewAndMenu> menuListLevel1 = new List <View_Sys_RolePurviewAndMenu>();

            if (RoleMenuInfo.IsNotNull())
            {
                menuListLevel1 = menuList.FindAll(p => p.Menu_ParentCode == RoleMenuInfo.Menu_Code); //menuList.FindAll(p => p.Menu_ParentCode == "10");
            }

            foreach (View_Sys_RolePurviewAndMenu menuModel1 in menuListLevel1.OrderBy(p => p.Menu_Sequence))//一级菜单
            {
                javaScript += "{ 'menuid': '" + menuModel1.MenuID + "', 'menuname': '" + menuModel1.Menu_Name + "', 'icon': 'icon-" + menuModel1.Menu_IconName + "', 'child': [";

                string menuLel2String = "";
                foreach (View_Sys_RolePurviewAndMenu menuModel2 in menuList.FindAll(p => p.Menu_ParentCode == menuModel1.Menu_Code).OrderBy(p => p.Menu_Sequence))//二级菜单
                {
                    menuLel2String += "{";
                    menuLel2String += "'menuid': '" + menuModel2.MenuID + "',";
                    menuLel2String += "'menuname': '" + menuModel2.Menu_Name + "',";
                    menuLel2String += "'icon': 'icon-" + menuModel2.Menu_IconName + "',";
                    List <View_Sys_RolePurviewAndMenu> list3 = menuList.FindAll(p => p.Menu_ParentCode == menuModel2.Menu_Code);
                    string menuLel3String = "";
                    if (list3.Count == 0)
                    {
                        menuLel2String += "'url': '" + menuModel2.Menu_Url + "'";
                    }
                    else
                    {
                        menuLel2String += "'url': '" + menuModel2.Menu_Url + "',";

                        menuLel2String += "'child': [";

                        foreach (View_Sys_RolePurviewAndMenu menuModel3 in list3.OrderBy(p => p.Menu_Sequence))//三级菜单
                        {
                            menuLel3String += "{";
                            menuLel3String += "'menuid': '" + menuModel3.MenuID + "',";
                            menuLel3String += "'menuname': '" + menuModel3.Menu_Name + "',";
                            menuLel3String += "'icon': 'icon-" + menuModel3.Menu_IconName + "',";
                            menuLel3String += "'url': '" + menuModel3.Menu_Url + "'";
                            menuLel3String += "},";
                        }
                        if (!menuLel3String.Equals(""))
                        {
                            menuLel3String = menuLel3String.Substring(0, menuLel3String.Length - 1);
                        }
                        else
                        {
                            menuLel3String = "{}";
                        }
                        menuLel3String += "]";
                    }


                    menuLel2String += menuLel3String + "},";
                }
                if (!menuLel2String.Equals(""))
                {
                    menuLel2String = menuLel2String.Substring(0, menuLel2String.Length - 1);
                }
                else
                {
                    menuLel2String = "";
                }
                javaScript += menuLel2String + "]},";
            }
            javaScript  = javaScript.Substring(0, javaScript.Length - 1);
            javaScript += "]}";
            context.Response.Write(javaScript);
            context.Response.End();
        }