You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

111 lines
3.7 KiB

  1. using Learun.Cache.Base;
  2. using Learun.Cache.Factory;
  3. using Learun.Util;
  4. using System.Text;
  5. using System.Web;
  6. using System.Web.Mvc;
  7. namespace Learun.Application.Web
  8. {
  9. /// <summary>
  10. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  11. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  12. /// 创建人:陈彬彬
  13. /// 日 期:2017.03.07
  14. /// 描 述:对HtmlHelper类进行扩展
  15. /// </summary>
  16. public static class HtmlHelperExtensions
  17. {
  18. private static ICache cache = CacheFactory.CaChe();
  19. /// <summary>
  20. /// 往页面中写入js文件
  21. /// </summary>
  22. /// <param name="htmlHelper">需要扩展对象</param>
  23. /// <param name="jsFiles">文件路径</param>
  24. /// <returns></returns>
  25. public static MvcHtmlString AppendJsFile(this HtmlHelper htmlHelper, params string[] jsFiles)
  26. {
  27. string jsFile = "";
  28. foreach (string file in jsFiles)
  29. {
  30. if (jsFile != "")
  31. {
  32. jsFile += ",";
  33. }
  34. jsFile += file;
  35. }
  36. string jsStr = "";
  37. if (Config.GetValue("JsCompressorCache") == "true")
  38. {
  39. jsStr = cache.Read<string>(jsFile, CacheId.jscss);
  40. }
  41. if (string.IsNullOrEmpty(jsStr))
  42. {
  43. jsStr = JsCssHelper.ReadJSFile(jsFiles);
  44. cache.Write<string>(jsFile, jsStr, CacheId.jscss);
  45. }
  46. StringBuilder content = new StringBuilder();
  47. string jsFormat = "<script>{0}</script>";
  48. content.AppendFormat(jsFormat, jsStr);
  49. return new MvcHtmlString(content.ToString());
  50. }
  51. /// <summary>
  52. /// 往页面中写入css样式
  53. /// </summary>
  54. /// <param name="htmlHelper">需要扩展对象</param>
  55. /// <param name="cssFiles">文件路径</param>
  56. /// <returns></returns>
  57. public static MvcHtmlString AppendCssFile(this HtmlHelper htmlHelper, params string[] cssFiles)
  58. {
  59. string cssFile = "";
  60. foreach (string file in cssFiles)
  61. {
  62. if (cssFile != "")
  63. {
  64. cssFile += ",";
  65. }
  66. cssFile += file;
  67. }
  68. string cssStr = "";
  69. if (Config.GetValue("JsCompressorCache") == "true")
  70. {
  71. cssStr = cache.Read<string>(cssFile, CacheId.jscss);
  72. }
  73. if (string.IsNullOrEmpty(cssStr))
  74. {
  75. var url = HttpContext.Current.Request.ApplicationPath;
  76. cssStr = JsCssHelper.ReadCssFile(cssFiles);
  77. if (url != "/")
  78. {
  79. cssStr = cssStr.Replace("url(", "url(" + url);
  80. }
  81. cache.Write<string>(cssFile, cssStr, CacheId.jscss);
  82. }
  83. StringBuilder content = new StringBuilder();
  84. string cssFormat = "<style>{0}</style>";
  85. content.AppendFormat(cssFormat, cssStr);
  86. return new MvcHtmlString(content.ToString());
  87. }
  88. #region 权限模块
  89. /// <summary>
  90. /// 设置当前页面地址
  91. /// </summary>
  92. /// <param name="htmlHelper"></param>
  93. /// <returns></returns>
  94. public static MvcHtmlString SetCurrentUrl(this HtmlHelper htmlHelper)
  95. {
  96. string currentUrl = (string)WebHelper.GetHttpItems("currentUrl");
  97. return new MvcHtmlString("<script>var lrCurrentUrl='" + currentUrl + "';var lrModuleButtonList;var lrModuleColumnList;var lrModule;</script>");
  98. }
  99. #endregion
  100. }
  101. }