public IActionResult Index() { ViewData["Title"] = ConfigHelper.Get <SiteConfig>().SiteName; ViewData["AdminName"] = User.FindFirst(ClaimTypes.Name).Value; string adminMenuPath = Utility.GetAdminMenuPath(); XmlHelper xmlHelper = XmlHelper.Instance(FileHelper.MapPath(adminMenuPath), XmlType.File); XmlDocument xmlDoc = xmlHelper.XmlDoc; XmlNode rootNode = xmlDoc.SelectSingleNode("menu"); if (rootNode == null) { Utility.WriteMessage("菜单配置文件不存在menu根元素", "/admin/home/login"); return(View()); } if (rootNode.HasChildNodes) { IList <MenuEntity> menuEntityList = new List <MenuEntity>(); foreach (XmlNode channelMenuNode in rootNode) { string operateCode = XmlHelper.GetAttributesValue(channelMenuNode, "operateCode"); if (Utility.AccessCheck(User, operateCode)) { string NodeName = channelMenuNode.Name; string id = XmlHelper.GetAttributesValue(channelMenuNode, "id"); string title = XmlHelper.GetAttributesValue(channelMenuNode, "title"); string Description = XmlHelper.GetAttributesValue(channelMenuNode, "Description"); string rightUrl = XmlHelper.GetAttributesValue(channelMenuNode, "rightUrl"); string MenuType = XmlHelper.GetAttributesValue(channelMenuNode, "type"); string MenuIcon = XmlHelper.GetAttributesValue(channelMenuNode, "icon"); bool ShowOnForm = DataConverter.CBoolean(XmlHelper.GetAttributesValue(channelMenuNode, "ShowOnForm")); bool ShowOnMenu = DataConverter.CBoolean(XmlHelper.GetAttributesValue(channelMenuNode, "ShowOnMenu")); if (!ShowOnMenu) { continue; } MenuEntity menuEntity = new MenuEntity { NodeName = NodeName, ID = id, Title = title, OperateCode = operateCode, Description = Description, Url = rightUrl, MenuType = MenuType, MenuIcon = MenuIcon, ShowOnForm = ShowOnForm, ShowOnMenu = ShowOnMenu }; menuEntity.MenuItem = InitSubMenu(channelMenuNode); menuEntityList.Add(menuEntity); } } return(View(menuEntityList)); } return(View()); }
private IList <MenuEntity> InitSubMenu(XmlNode channelMenuNode) { IList <MenuEntity> menuEntityList = new List <MenuEntity>(); if (channelMenuNode == null || !channelMenuNode.HasChildNodes) { return(menuEntityList); } foreach (XmlNode menuNode in channelMenuNode) { string operateCode = XmlHelper.GetAttributesValue(menuNode, "operateCode"); if (Utility.AccessCheck(User, operateCode)) { string NodeName = menuNode.Name; string id = XmlHelper.GetAttributesValue(menuNode, "id"); string title = XmlHelper.GetAttributesValue(menuNode, "title"); string Description = XmlHelper.GetAttributesValue(menuNode, "Description"); string rightUrl = XmlHelper.GetAttributesValue(menuNode, "rightUrl"); string MenuType = XmlHelper.GetAttributesValue(menuNode, "type"); string MenuIcon = XmlHelper.GetAttributesValue(channelMenuNode, "icon"); bool ShowOnForm = DataConverter.CBoolean(XmlHelper.GetAttributesValue(menuNode, "ShowOnForm")); bool ShowOnMenu = DataConverter.CBoolean(XmlHelper.GetAttributesValue(menuNode, "ShowOnMenu")); if (!ShowOnMenu) { continue; } MenuEntity subMenuEntity = new MenuEntity { NodeName = NodeName, ID = id, Title = title, OperateCode = operateCode, Description = Description, Url = rightUrl, MenuType = MenuType, MenuIcon = MenuIcon, ShowOnForm = ShowOnForm, ShowOnMenu = ShowOnMenu }; menuEntityList.Add(subMenuEntity); } } return(menuEntityList); }