Role.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. }
  65. /**
  66. * @auth {{/role/remove}}
  67. */
  68. public function delete() {
  69. if ($this->request->isPost()) {
  70. return json(RoleApi::delete($this->request->param("roleId")));
  71. }
  72. }
  73. function treelist() {
  74. $list = getTreeList(RoleApi::getList([]));
  75. $format_list = [];
  76. foreach ($list as $item) {
  77. $format_list[] = [
  78. "checked" => false,
  79. "id" => $item["id"],
  80. "isOpen" => true,
  81. "name" => $item["name"],
  82. "open" => $item["pid"] == 0 ? true : false,
  83. "pId" => $item["pid"]
  84. ];
  85. }
  86. $format_list[] = ["checked" => true, "id" => "0", "isOpen" => true, "name" => "顶级", "open" => true, "pId" => "0"];
  87. return $format_list;
  88. }
  89. }