Exemple #1
0
        /// <summary>
        /// 从文件中获取菜单JSON数据
        /// </summary>
        /// <returns></returns>
        private static string GetMenuJsonFromFile(bool isMaster, int siteId)
        {
            var sb = new StringBuilder();

            //获取文件
            var xd = new XmlDocument();

            //读取配置
            var setFile = $"{EnvUtil.GetBaseDirectory()}/config/sys_set.conf";

            if (File.Exists(setFile))
            {
                xd.Load(setFile);
            }
            else
            {
                xd.LoadXml(ResourceMap.GetBoardMenu()); //系统默认的配置
            }

            //读取菜单

            //sb.Remove(0, sb.Length);
            sb.Append("[");

            //XmlDocument xd = getSetFile();

            //
            //文件必须包含一个id为content的节点
            //
            XmlNodeList pl = xd.SelectNodes("/config/menu/bar"), //父列表
                        sl = null,                               //二级列表
                        tl = null;                               //三级列表

            int i = 0,
                j = 0,
                k = 0;

            foreach (XmlNode pn in pl)
            {
                sb.Append("{\"id\":\"").Append(pn.Attributes["id"].Value).Append("\",\"text\":\"")
                .Append(pn.Attributes["name"].Value).Append("\",\"uri\":\"")
                .Append("#").Append(pn.Attributes["id"].Value).Append("\",\"childs\":[");

                sl = xd.SelectNodes("/config/menu/bar[@id='" + pn.Attributes["id"].Value + "']/links");
                foreach (XmlNode sn in sl)
                {
                    sb.Append("{\"text\":\"").Append(sn.Attributes["title"].Value).Append("\",\"uri\":\"").Append("\",")
                    .Append("\"toggle\":").Append(sn.Attributes["toggle"].Value == "true" ? "true" : "false")
                    .Append(",")
                    .Append("\"iconPos\":\"").Append(sn.Attributes["iconPos"].Value).Append("\",")
                    .Append("\"childs\":[");

                    tl = sn.ChildNodes;

                    //添加二级link
                    foreach (XmlNode tn in tl)
                    {
                        if (tn.Name == "link")
                        {
                            if (tn.Attributes["siteid"].Value == "0" && !isMaster)
                            {
                                continue;
                            }
                            ++k;
                            if (k != 1)
                            {
                                sb.Append(",");
                            }

                            sb.Append("{\"text\":\"").Append(tn.Attributes["text"].Value)
                            .Append("\",\"uri\":\"").Append(tn.Attributes["href"].Value
                                                            .Replace("$prefix", Settings.SYS_ADMIN_TAG))
                            .Append("\"}");
                        }
                    }

                    k = 0;

                    sb.Append("]}");
                    if (++j < sl.Count)
                    {
                        sb.Append(",");
                    }
                }


                goto netx;
                //添加模块

                #region

                /*
                 * if (String.Compare(pn.Attributes["id"].Value, "content") == 0)
                 * {
                 *  if (j != 0)
                 *  {
                 *      sb.Append(",");
                 *      j = 0;
                 *  }
                 *  IList<Module> modules = new List<Module>(CmsLogic.Module.GetAvailableModules());
                 *
                 *  foreach (Module m in modules)
                 *  {
                 *      if (!m.IsDelete)
                 *      {
                 *          sb.Append("{\"text\":'").Append(m.Name).Append("',uri:'").Append("',toggle:").Append(modules.Count > 4 && j < modules.Count - 1 ? "true" : "false")
                 *              .Append(",childs:[");
                 *
                 *          sb.Append("{text:'").Append("发布信息").Append("',uri:'")
                 *              .Append("?module=archive&action=create&moduleID=")
                 *              .Append(m.ID.ToString()).Append("'},");
                 *
                 *          sb.Append("{text:'").Append("信息列表").Append("',uri:'")
                 *              .Append("?module=archive&action=list&module_id=")
                 *              .Append(m.ID.ToString()).Append("'}");
                 *
                 *
                 *          sb.Append("]}");
                 *          if (++j < modules.Count)
                 *          {
                 *              sb.Append(",");
                 *          }
                 *      }
                 *  }
                 * }
                 */

                #endregion


netx:
                j = 0;

                sb.Append("]}");

                if (++i < pl.Count)
                {
                    sb.Append(",");
                }
            }

            sb.Append("]");
            return(sb.ToString());
        }