Role.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 treelist() {
  77. $list = getTreeList(RoleApi::getList([]));
  78. $format_list = [];
  79. foreach ($list as $item) {
  80. $format_list[] = [
  81. "checked" => false,
  82. "id" => $item["id"],
  83. "isOpen" => true,
  84. "name" => $item["name"],
  85. "open" => $item["pid"] == 0 ? true : false,
  86. "pId" => $item["pid"]
  87. ];
  88. }
  89. $format_list[] = ["checked" => true, "id" => "0", "isOpen" => true, "name" => "顶级", "open" => true, "pId" => "0"];
  90. return $format_list;
  91. }
  92. }