Role.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\common\AdminController;
  4. use app\admin\api\RoleApi;
  5. /**
  6. * Description of Role
  7. *
  8. * @author sgq
  9. */
  10. class Role extends AdminController {
  11. /**
  12. * @auth {{/role}}
  13. * @return type
  14. */
  15. public function index() {
  16. return view();
  17. }
  18. /**
  19. * @auth {{/role/list}}
  20. * @return type
  21. */
  22. public function list() {
  23. $list = RoleApi::getList($this->request->param());
  24. return json($list);
  25. }
  26. /**
  27. * @auth {{/role/add}}
  28. * @return type
  29. */
  30. public function add() {
  31. if ($this->request->isPost()) {
  32. return json(RoleApi::create($this->request->param()));
  33. }
  34. return view();
  35. }
  36. /**
  37. * @auth {{/role/edit}}
  38. * @return type
  39. */
  40. public function edit() {
  41. if ($this->request->isPost()) {
  42. return json(RoleApi::update($this->request->param()));
  43. }
  44. $id = $this->request->param("id");
  45. return view("", ["role" => RoleApi::getOne($id)]);
  46. }
  47. /**
  48. * @auth {{/role/role_edit}}
  49. */
  50. public function role_edit() {
  51. }
  52. /**
  53. * @auth {{/role/role_assign}}
  54. * @return type
  55. */
  56. public function assign() {
  57. $role = RoleApi::getOne($this->request->param("id"));
  58. return view("", ["role" => $role]);
  59. }
  60. /**
  61. * @auth {{/role/setAuthority}}
  62. */
  63. public function set_authority() {
  64. if ($this->request->isPost()) {
  65. return json(RoleApi::set_authority($this->request["roleId"], $this->request["ids"]));
  66. }
  67. }
  68. /**
  69. * @auth {{/role/remove}}
  70. */
  71. public function delete() {
  72. if ($this->request->isPost()) {
  73. return json(RoleApi::delete($this->request->param("roleId")));
  74. }
  75. }
  76. function roleTreeListByUserId() {
  77. $userId = $this->request->param("userId");
  78. $user = \app\admin\api\UserApi::getOne($userId);
  79. $roleIds = array_filter(explode(",", $user["roleid"]));
  80. $list = getTreeList(RoleApi::getList([]));
  81. $format_list = [];
  82. foreach ($list as $item) {
  83. $format_list[] = [
  84. "checked" => in_array($item["id"], $roleIds) ? true : false,
  85. "id" => $item["id"],
  86. "isOpen" => true,
  87. "name" => $item["name"],
  88. "open" => $item["pid"] == 0 ? true : false,
  89. "pId" => $item["pid"]
  90. ];
  91. }
  92. return $format_list;
  93. }
  94. function treelist() {
  95. $list = getTreeList(RoleApi::getList([]));
  96. $format_list = [];
  97. foreach ($list as $item) {
  98. $format_list[] = [
  99. "checked" => false,
  100. "id" => $item["id"],
  101. "isOpen" => true,
  102. "name" => $item["name"],
  103. "open" => $item["pid"] == 0 ? true : false,
  104. "pId" => $item["pid"]
  105. ];
  106. }
  107. $format_list[] = ["checked" => true, "id" => "0", "isOpen" => true, "name" => "顶级", "open" => true, "pId" => "0"];
  108. return $format_list;
  109. }
  110. }