ModuleController.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. using LeaRun.Application.Busines.AuthorizeManage;
  2. using LeaRun.Application.Code;
  3. using LeaRun.Application.Entity.AuthorizeManage;
  4. using LeaRun.Util;
  5. using LeaRun.Util.WebControl;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Web.Mvc;
  9. namespace LeaRun.Application.Web.Areas.AuthorizeManage.Controllers
  10. {
  11. /// <summary>
  12. /// 版 本 6.1
  13. /// Copyright (c) 2013-2016 上海力软信息技术有限公司
  14. /// 创建人:佘赐雄
  15. /// 日 期:2015.10.27 09:16
  16. /// 描 述:系统功能
  17. /// </summary>
  18. public class ModuleController : MvcControllerBase
  19. {
  20. private ModuleBLL moduleBLL = new ModuleBLL();
  21. #region 视图功能
  22. /// <summary>
  23. /// 功能管理
  24. /// </summary>
  25. /// <returns></returns>
  26. [HttpGet]
  27. [HandlerAuthorize(PermissionMode.Enforce)]
  28. public ActionResult Index()
  29. {
  30. return View();
  31. }
  32. /// <summary>
  33. /// 功能表单
  34. /// </summary>
  35. /// <returns></returns>
  36. [HttpGet]
  37. [HandlerAuthorize(PermissionMode.Enforce)]
  38. public ActionResult Form()
  39. {
  40. ViewBag.ModuleId = Request["keyValue"];
  41. return View();
  42. }
  43. /// <summary>
  44. /// 功能图标
  45. /// </summary>
  46. /// <returns></returns>
  47. [HttpGet]
  48. public ActionResult Icon()
  49. {
  50. return View();
  51. }
  52. #endregion
  53. #region 获取数据
  54. /// <summary>
  55. /// 功能列表
  56. /// </summary>
  57. /// <param name="keyword">关键字</param>
  58. /// <returns>返回树形Json</returns>
  59. [HttpGet]
  60. public ActionResult GetTreeJson(string keyword)
  61. {
  62. var data = moduleBLL.GetList();
  63. if (!string.IsNullOrEmpty(keyword))
  64. {
  65. data = data.TreeWhere(t => t.FullName.Contains(keyword), "");
  66. }
  67. var treeList = new List<TreeEntity>();
  68. foreach (ModuleEntity item in data)
  69. {
  70. TreeEntity tree = new TreeEntity();
  71. bool hasChildren = data.Count(t => t.ParentId == item.ModuleId) == 0 ? false : true;
  72. tree.id = item.ModuleId;
  73. tree.text = item.FullName;
  74. tree.value = item.ModuleId;
  75. tree.isexpand = true;
  76. tree.complete = true;
  77. tree.hasChildren = hasChildren;
  78. tree.parentId = item.ParentId;
  79. tree.img = item.Icon;
  80. treeList.Add(tree);
  81. }
  82. return Content(treeList.TreeToJson());
  83. }
  84. /// <summary>
  85. /// 获取目录级功能列表
  86. /// </summary>
  87. /// <param name="keyword">关键字</param>
  88. /// <returns>返回树形Json</returns>
  89. [HttpGet]
  90. public ActionResult GetCatalogTreeJson(string keyword)
  91. {
  92. var data = moduleBLL.GetList();
  93. data = data.FindAll(t => t.IsMenu != 1);
  94. if (!string.IsNullOrEmpty(keyword))
  95. {
  96. data = data.TreeWhere(t => t.FullName.Contains(keyword), "");
  97. }
  98. var treeList = new List<TreeEntity>();
  99. foreach (ModuleEntity item in data)
  100. {
  101. TreeEntity tree = new TreeEntity();
  102. bool hasChildren = data.Count(t => t.ParentId == item.ModuleId) == 0 ? false : true;
  103. tree.id = item.ModuleId;
  104. tree.text = item.FullName;
  105. tree.value = item.ModuleId;
  106. tree.isexpand = true;
  107. tree.complete = true;
  108. tree.hasChildren = hasChildren;
  109. tree.parentId = item.ParentId;
  110. tree.img = item.Icon;
  111. treeList.Add(tree);
  112. }
  113. return Content(treeList.TreeToJson());
  114. }
  115. /// <summary>
  116. /// 功能列表
  117. /// </summary>
  118. /// <param name="parentid">节点Id</param>
  119. /// <param name="condition">查询条件</param>
  120. /// <param name="keyword">关键字</param>
  121. /// <returns>返回列表Json</returns>
  122. [HttpGet]
  123. public ActionResult GetListJson(string parentid, string condition, string keyword)
  124. {
  125. var data = moduleBLL.GetList(parentid);
  126. if (!string.IsNullOrEmpty(condition) && !string.IsNullOrEmpty(keyword))
  127. {
  128. #region 多条件查询
  129. switch (condition)
  130. {
  131. case "EnCode": //编号
  132. data = data.FindAll(t => t.EnCode.Contains(keyword));
  133. break;
  134. case "FullName": //名称
  135. data = data.FindAll(t => t.FullName.Contains(keyword));
  136. break;
  137. case "UrlAddress": //地址
  138. data = data.FindAll(t => t.UrlAddress.Contains(keyword));
  139. break;
  140. default:
  141. break;
  142. }
  143. #endregion
  144. }
  145. return Content(data.ToJson());
  146. }
  147. /// <summary>
  148. /// 功能实体 返回对象Json
  149. /// </summary>
  150. /// <param name="keyValue">主键值</param>
  151. /// <returns></returns>
  152. [HttpGet]
  153. public ActionResult GetFormJson(string keyValue)
  154. {
  155. var data = moduleBLL.GetEntity(keyValue);
  156. return Content(data.ToJson());
  157. }
  158. #endregion
  159. #region 验证数据
  160. /// <summary>
  161. /// 功能编号不能重复
  162. /// </summary>
  163. /// <param name="EnCode">编号</param>
  164. /// <param name="keyValue">主键</param>
  165. /// <returns></returns>
  166. [HttpGet]
  167. public ActionResult ExistEnCode(string EnCode, string keyValue)
  168. {
  169. bool IsOk = moduleBLL.ExistEnCode(EnCode, keyValue);
  170. return Content(IsOk.ToString());
  171. }
  172. /// <summary>
  173. /// 功能名称不能重复
  174. /// </summary>
  175. /// <param name="FullName">名称</param>
  176. /// <param name="keyValue">主键</param>
  177. /// <returns></returns>
  178. [HttpGet]
  179. public ActionResult ExistFullName(string FullName, string keyValue)
  180. {
  181. bool IsOk = moduleBLL.ExistFullName(FullName, keyValue);
  182. return Content(IsOk.ToString());
  183. }
  184. #endregion
  185. #region 提交数据
  186. /// <summary>
  187. /// 删除功能
  188. /// </summary>
  189. /// <param name="keyValue">主键值</param>
  190. /// <returns></returns>
  191. [HttpPost]
  192. [ValidateAntiForgeryToken]
  193. [AjaxOnly]
  194. [HandlerAuthorize(PermissionMode.Enforce)]
  195. public ActionResult RemoveForm(string keyValue)
  196. {
  197. moduleBLL.RemoveForm(keyValue);
  198. return Success("删除成功。");
  199. }
  200. /// <summary>
  201. /// 保存功能表单
  202. /// </summary>
  203. /// <param name="keyValue">主键值</param>
  204. /// <param name="moduleEntity">功能实体</param>
  205. /// <param name="moduleButtonList">按钮实体列表</param>
  206. /// <param name="moduleColumnList">视图实体列表</param>
  207. /// <returns></returns>
  208. [HttpPost]
  209. [ValidateAntiForgeryToken]
  210. [AjaxOnly]
  211. public ActionResult SaveForm(string keyValue, ModuleEntity moduleEntity, string moduleButtonListJson, string moduleColumnListJson)
  212. {
  213. moduleBLL.SaveForm(keyValue, moduleEntity, moduleButtonListJson, moduleColumnListJson);
  214. return Success("保存成功。");
  215. }
  216. #endregion
  217. }
  218. }