纽威
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.

61 lines
2.5 KiB

3 years ago
  1. using NFine.Application.SystemManage;
  2. using NFine.Code;
  3. using NFine.Domain.Entity.SystemManage;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Web.Mvc;
  7. namespace NFine.Web.Areas.SystemManage.Controllers
  8. {
  9. public class RoleAuthorizeController : ControllerBase
  10. {
  11. private RoleAuthorizeApp roleAuthorizeApp = new RoleAuthorizeApp();
  12. private ModuleApp moduleApp = new ModuleApp();
  13. private ModuleButtonApp moduleButtonApp = new ModuleButtonApp();
  14. public ActionResult GetPermissionTree(string roleId)
  15. {
  16. var moduledata = moduleApp.GetList();
  17. var buttondata = moduleButtonApp.GetList();
  18. var authorizedata = new List<RoleAuthorizeEntity>();
  19. if (!string.IsNullOrEmpty(roleId))
  20. {
  21. authorizedata = roleAuthorizeApp.GetList(roleId);
  22. }
  23. var treeList = new List<TreeViewModel>();
  24. foreach (ModuleEntity item in moduledata)
  25. {
  26. TreeViewModel tree = new TreeViewModel();
  27. bool hasChildren = moduledata.Count(t => t.F_ParentId == item.F_Id) == 0 ? false : true;
  28. tree.id = item.F_Id;
  29. tree.text = item.F_FullName;
  30. tree.value = item.F_EnCode;
  31. tree.parentId = item.F_ParentId;
  32. tree.isexpand = true;
  33. tree.complete = true;
  34. tree.showcheck = true;
  35. tree.checkstate = authorizedata.Count(t => t.F_ItemId == item.F_Id);
  36. tree.hasChildren = true;
  37. tree.img = item.F_Icon == "" ? "" : item.F_Icon;
  38. treeList.Add(tree);
  39. }
  40. foreach (ModuleButtonEntity item in buttondata)
  41. {
  42. TreeViewModel tree = new TreeViewModel();
  43. bool hasChildren = buttondata.Count(t => t.F_ParentId == item.F_Id) == 0 ? false : true;
  44. tree.id = item.F_Id;
  45. tree.text = item.F_FullName;
  46. tree.value = item.F_EnCode;
  47. tree.parentId = item.F_ParentId == "0" ? item.F_ModuleId : item.F_ParentId;
  48. tree.isexpand = true;
  49. tree.complete = true;
  50. tree.showcheck = true;
  51. tree.checkstate = authorizedata.Count(t => t.F_ItemId == item.F_Id);
  52. tree.hasChildren = hasChildren;
  53. tree.img = item.F_Icon == "" ? "" : item.F_Icon;
  54. treeList.Add(tree);
  55. }
  56. return Content(treeList.TreeViewJson());
  57. }
  58. }
  59. }