| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 | 
							- 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
 
- {
 
- 	/// <summary>
 
- 	/// 描 述:对HtmlHelper类进行扩展
 
- 	/// </summary>
 
- 	public static class HtmlHelperExtensions
 
- 	{
 
- 		private const ERedisCacheNo RedisCacheNo = ERedisCacheNo.CssJs;
 
- 		/// <summary>
 
- 		/// 往页面中写入js文件
 
- 		/// </summary>
 
- 		/// <param name="htmlHelper">需要扩展对象</param>
 
- 		/// <param name="jsFiles">文件路径</param>
 
- 		/// <returns></returns>
 
- 		public static HtmlString AppendJsFile(this IHtmlHelper htmlHelper, params string[] jsFiles)
 
- 		{
 
- 			//string jsfilename = "script_" + string.Join("_", jsFiles);
 
- 			//string jsStr = RedisCache.Read<string>(jsfilename, RedisCacheNo);
 
- 			//if (string.IsNullOrWhiteSpace(jsStr))
 
- 			//{
 
- 			//    jsStr = JsCssUtil.ReadJSFile(jsFiles, SysSetCore.GetSysSet().IsJsCssCompressor);
 
- 			//    jsStr = string.Format("<script>{0}</script>", jsStr);
 
- 			//    RedisCache.Write<string>(jsfilename, jsStr, RedisCacheNo);
 
- 			//}
 
- 			string jsStr = JsCssUtil.ReadJSFile(jsFiles, SysSetCore.GetSysSet().IsJsCssCompressor);
 
- 			jsStr = string.Format("<script>{0}</script>", jsStr);
 
- 			return new HtmlString(jsStr);
 
- 		}
 
- 		/// <summary>
 
- 		/// 往页面中写入js文件
 
- 		/// </summary>
 
- 		/// <param name="htmlHelper">需要扩展对象</param>
 
- 		/// <param name="jsFiles">文件路径</param>
 
- 		/// <returns></returns>
 
- 		//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<string>("env") != "dev")
 
- 		//	{
 
- 		//		jsStr = ConfigHelper.GetCache(jsFile);
 
- 		//	}
 
- 		//	if (string.IsNullOrEmpty(jsStr))
 
- 		//	{
 
- 		//		jsStr = JsCssHelper.ReadJSFile(jsFiles);
 
- 		//		ConfigHelper.SetCache(jsFile, jsStr);
 
- 		//	}
 
- 		//	StringBuilder content = new StringBuilder();
 
- 		//	string jsFormat = "<script>{0}</script>";
 
- 		//	content.AppendFormat(jsFormat, jsStr);
 
- 		//	return new HtmlString(content.ToString());
 
- 		//}
 
- 		public static HtmlString AppendString(this IHtmlHelper htmlHelper, string jsFiles)
 
- 		{
 
- 			return new HtmlString(jsFiles);
 
- 		}
 
- 		/// <summary>
 
- 		/// 往页面中写入js文件
 
- 		/// </summary>
 
- 		/// <param name="htmlHelper">需要扩展对象</param>
 
- 		/// <param name="jsFiles">文件路径</param>
 
- 		/// <returns></returns>
 
- 		public static HtmlString AppendJsFileByLocation(this IHtmlHelper htmlHelper, params string[] jsFiles)
 
- 		{
 
- 			//string jsfilename = "script_" + string.Join("_", jsFiles);
 
- 			//string jsStr = RedisCache.Read<string>(jsfilename, RedisCacheNo);
 
- 			//if (string.IsNullOrWhiteSpace(jsStr))
 
- 			//{
 
- 			//    jsStr = JsCssUtil.ReadJSFile(jsFiles, false);
 
- 			//    jsStr = string.Format("<script>{0}</script>", jsStr);
 
- 			//    RedisCache.Write<string>(jsfilename, jsStr, RedisCacheNo);
 
- 			//}
 
- 			string jsStr = JsCssUtil.ReadJSFile(jsFiles, false);
 
- 			jsStr = string.Format("<script>{0}</script>", jsStr);
 
- 			return new HtmlString(jsStr);
 
- 		}
 
- 		/// <summary>
 
- 		/// 往页面中写入css样式
 
- 		/// </summary>
 
- 		/// <param name="htmlHelper">需要扩展对象</param>
 
- 		/// <param name="cssFiles">文件路径</param>
 
- 		/// <returns></returns>
 
- 		//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<string>("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 = "<style>{0}</style>";
 
- 		//	content.AppendFormat(cssFormat, cssStr);
 
- 		//	return new HtmlString(content.ToString());
 
- 		//}
 
- 		/// <summary>
 
- 		/// 往页面中写入css样式
 
- 		/// </summary>
 
- 		/// <param name="htmlHelper">需要扩展对象</param>
 
- 		/// <param name="cssFiles">文件路径</param>
 
- 		/// <returns></returns>
 
- 		public static HtmlString AppendCssFile(this IHtmlHelper htmlHelper, params string[] cssFiles)
 
- 		{
 
- 			//string cssfilename = "style_" + string.Join("_", cssFiles);
 
- 			//string cssStr = RedisCache.Read<string>(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("<style>{0}</style>", cssStr);
 
- 			//    RedisCache.Write<string>(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("<style>{0}</style>", cssStr);
 
- 			return new HtmlString(cssStr);
 
- 		}
 
- 		/// <summary>
 
- 		/// 获取虚拟目录
 
- 		/// </summary>
 
- 		/// <returns></returns>
 
- 		public static string GetVirtualPath(this IHtmlHelper htmlHelper)
 
- 		{
 
- 			if (htmlHelper is null)
 
- 			{
 
- 				throw new System.ArgumentNullException(nameof(htmlHelper));
 
- 			}
 
- 			return ConfigHelper.GetConfig().VirtualPath;
 
- 		}
 
- 		/// <summary>
 
- 		/// 设置当前页面地址
 
- 		/// </summary>
 
- 		/// <param name="htmlHelper"></param>
 
- 		/// <returns></returns>
 
- 		public static HtmlString SetCurrentUrl(this IHtmlHelper htmlHelper)
 
- 		{
 
- 			string currentUrl = "";//(string)WebHelper.GetHttpItems("currentUrl");
 
- 			return new HtmlString("<script>var lrCurrentUrl='" + currentUrl + "';var lrModuleButtonList;var lrModuleColumnList;var lrModule;</script>");
 
- 		}
 
- 		public static string GetUITheme()
 
- 		{
 
- 			return "lr-uitheme-top";
 
- 		}
 
- 	}
 
- }
 
 
  |