using Learun.Cache.Base; using Learun.Cache.Factory; using Learun.Util; using System.Text; using System.Web; using System.Web.Mvc; namespace Learun.Application.Web { /// /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园 /// Copyright (c) 2013-2018 北京泉江科技有限公司 /// 创建人:陈彬彬 /// 日 期:2017.03.07 /// 描 述:对HtmlHelper类进行扩展 /// public static class HtmlHelperExtensions { private static ICache cache = CacheFactory.CaChe(); /// /// 往页面中写入js文件 /// /// 需要扩展对象 /// 文件路径 /// public static MvcHtmlString AppendJsFile(this HtmlHelper htmlHelper, params string[] jsFiles) { string jsFile = ""; foreach (string file in jsFiles) { if (jsFile != "") { jsFile += ","; } jsFile += file; } string jsStr = ""; if (Config.GetValue("JsCompressorCache") == "true") { jsStr = cache.Read(jsFile, CacheId.jscss); } if (string.IsNullOrEmpty(jsStr)) { jsStr = JsCssHelper.ReadJSFile(jsFiles); cache.Write(jsFile, jsStr, CacheId.jscss); } StringBuilder content = new StringBuilder(); string jsFormat = ""; content.AppendFormat(jsFormat, jsStr); return new MvcHtmlString(content.ToString()); } /// /// 往页面中写入css样式 /// /// 需要扩展对象 /// 文件路径 /// public static MvcHtmlString AppendCssFile(this HtmlHelper htmlHelper, params string[] cssFiles) { string cssFile = ""; foreach (string file in cssFiles) { if (cssFile != "") { cssFile += ","; } cssFile += file; } string cssStr = ""; if (Config.GetValue("JsCompressorCache") == "true") { cssStr = cache.Read(cssFile, CacheId.jscss); } if (string.IsNullOrEmpty(cssStr)) { var url = HttpContext.Current.Request.ApplicationPath; cssStr = JsCssHelper.ReadCssFile(cssFiles); if (url != "/") { cssStr = cssStr.Replace("url(", "url(" + url); } cache.Write(cssFile, cssStr, CacheId.jscss); } StringBuilder content = new StringBuilder(); string cssFormat = ""; content.AppendFormat(cssFormat, cssStr); return new MvcHtmlString(content.ToString()); } #region 权限模块 /// /// 设置当前页面地址 /// /// /// public static MvcHtmlString SetCurrentUrl(this HtmlHelper htmlHelper) { string currentUrl = (string)WebHelper.GetHttpItems("currentUrl"); return new MvcHtmlString(""); } #endregion } }