using System; using System.Collections.Generic; using System.Text; using System.Web; using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Mvc.Rendering; using WMS.Util; using WMS.Core; using WMS.BZWeb.Extensions; using Microsoft.AspNetCore.Mvc.ViewFeatures; namespace WMS.BZWeb { /// /// 描 述:对HtmlHelper类进行扩展 /// public static class HtmlHelperExtensions { private const ERedisCacheNo RedisCacheNo = ERedisCacheNo.CssJs; /// /// 往页面中写入js文件 /// /// 需要扩展对象 /// 文件路径 /// public static HtmlString AppendJsFile(this IHtmlHelper htmlHelper, params string[] jsFiles) { //string jsfilename = "script_" + string.Join("_", jsFiles); //string jsStr = RedisCache.Read(jsfilename, RedisCacheNo); //if (string.IsNullOrWhiteSpace(jsStr)) //{ // jsStr = JsCssUtil.ReadJSFile(jsFiles, SysSetCore.GetSysSet().IsJsCssCompressor); // jsStr = string.Format("", jsStr); // RedisCache.Write(jsfilename, jsStr, RedisCacheNo); //} string jsStr = JsCssUtil.ReadJSFile(jsFiles, SysSetCore.GetSysSet().IsJsCssCompressor); jsStr = string.Format("", jsStr); return new HtmlString(jsStr); } /// /// 往页面中写入js文件 /// /// 需要扩展对象 /// 文件路径 /// //public static HtmlString AppendJsFile(this IHtmlHelper htmlHelper, params string[] jsFiles) //{ // if (htmlHelper is null) // { // throw new System.ArgumentNullException(nameof(htmlHelper)); // } // string jsFile = ""; // foreach (string file in jsFiles) // { // if (jsFile != "") // { // jsFile += ","; // } // jsFile += file; // } // string jsStr = ""; // if (ConfigHelper.GetValue("env") != "dev") // { // jsStr = ConfigHelper.GetCache(jsFile); // } // if (string.IsNullOrEmpty(jsStr)) // { // jsStr = JsCssHelper.ReadJSFile(jsFiles); // ConfigHelper.SetCache(jsFile, jsStr); // } // StringBuilder content = new StringBuilder(); // string jsFormat = ""; // content.AppendFormat(jsFormat, jsStr); // return new HtmlString(content.ToString()); //} public static HtmlString AppendString(this IHtmlHelper htmlHelper, string jsFiles) { return new HtmlString(jsFiles); } /// /// 往页面中写入js文件 /// /// 需要扩展对象 /// 文件路径 /// public static HtmlString AppendJsFileByLocation(this IHtmlHelper htmlHelper, params string[] jsFiles) { //string jsfilename = "script_" + string.Join("_", jsFiles); //string jsStr = RedisCache.Read(jsfilename, RedisCacheNo); //if (string.IsNullOrWhiteSpace(jsStr)) //{ // jsStr = JsCssUtil.ReadJSFile(jsFiles, false); // jsStr = string.Format("", jsStr); // RedisCache.Write(jsfilename, jsStr, RedisCacheNo); //} string jsStr = JsCssUtil.ReadJSFile(jsFiles, false); jsStr = string.Format("", jsStr); return new HtmlString(jsStr); } /// /// 往页面中写入css样式 /// /// 需要扩展对象 /// 文件路径 /// //public static HtmlString AppendCssFile(this IHtmlHelper htmlHelper, params string[] cssFiles) //{ // if (htmlHelper is null) // { // throw new System.ArgumentNullException(nameof(htmlHelper)); // } // string cssFile = ""; // foreach (string file in cssFiles) // { // if (cssFile != "") // { // cssFile += ","; // } // cssFile += file; // } // string cssStr = ""; // if (ConfigHelper.GetValue("env") != "dev") // { // cssStr = ConfigHelper.GetCache(cssFile); // } // if (string.IsNullOrEmpty(cssStr)) // { // var url = ConfigHelper.GetConfig().VirtualPath; // cssStr = JsCssHelper.ReadCssFile(cssFiles); // if (url != "") // { // cssStr = cssStr.Replace("url(", "url(" + url); // } // ConfigHelper.SetCache(cssFile, cssStr); // } // StringBuilder content = new StringBuilder(); // string cssFormat = ""; // content.AppendFormat(cssFormat, cssStr); // return new HtmlString(content.ToString()); //} /// /// 往页面中写入css样式 /// /// 需要扩展对象 /// 文件路径 /// public static HtmlString AppendCssFile(this IHtmlHelper htmlHelper, params string[] cssFiles) { //string cssfilename = "style_" + string.Join("_", cssFiles); //string cssStr = RedisCache.Read(cssfilename, RedisCacheNo); //if (string.IsNullOrWhiteSpace(cssStr)) //{ // cssStr = JsCssUtil.ReadCssFile(cssFiles, SysSetCore.GetSysSet().IsJsCssCompressor); // var url = HttpContext.Current.Request.ApplicationPath; // if (url != "/") // { // cssStr = cssStr.Replace("url(", "url(" + url); // } // cssStr = string.Format("", cssStr); // RedisCache.Write(cssfilename, cssStr, RedisCacheNo); //} string cssStr = JsCssUtil.ReadCssFile(cssFiles, SysSetCore.GetSysSet().IsJsCssCompressor); var url = ConfigHelper.GetConfig().VirtualPath; if (url != "/") { cssStr = cssStr.Replace("url(", "url(" + url); } cssStr = string.Format("", cssStr); return new HtmlString(cssStr); } /// /// 获取虚拟目录 /// /// public static string GetVirtualPath(this IHtmlHelper htmlHelper) { if (htmlHelper is null) { throw new System.ArgumentNullException(nameof(htmlHelper)); } return ConfigHelper.GetConfig().VirtualPath; } /// /// 设置当前页面地址 /// /// /// public static HtmlString SetCurrentUrl(this IHtmlHelper htmlHelper) { string currentUrl = "";//(string)WebHelper.GetHttpItems("currentUrl"); return new HtmlString(""); } public static string GetUITheme() { return "lr-uitheme-top"; } } }