Menu.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\common\AdminController;
  4. use app\common\api\MenuApi;
  5. /**
  6. * Description of Menu
  7. *
  8. * @author sgq
  9. */
  10. class Menu extends AdminController {
  11. /**
  12. * @auth {{/menu}}
  13. * @return type
  14. */
  15. function index() {
  16. return view();
  17. }
  18. /**
  19. * @auth {{/menu/list}}
  20. * @return type
  21. */
  22. function list() {
  23. if ($this->request->isPost()) {
  24. return json([]);
  25. }
  26. }
  27. /**
  28. * @auth {{/menu/add}}
  29. * @return type
  30. */
  31. function add() {
  32. if ($this->request->isPost()) {
  33. try {
  34. $params = $this->request->param();
  35. validate(\app\admin\validate\Menu::class)->check($params);
  36. if (MenuApi::save($this->request->param())) {
  37. return json(["msg" => "添加成功"]);
  38. }
  39. return json(["msg" => "添加失败"]);
  40. } catch (\think\Exception $e) {
  41. return json(["msg" => $e->getMessage()]);
  42. }
  43. }
  44. return view();
  45. }
  46. /**
  47. * @auth {{/menu/edit}}
  48. * @return type
  49. */
  50. function edit() {
  51. if ($this->request->isPost()) {
  52. try {
  53. $params = $this->request->param();
  54. if (!$params["id"])
  55. return json(["msg" => "没有选择菜单"]);
  56. validate(\app\admin\validate\Menu::class)->check($params);
  57. if (MenuApi::save($this->request->param())) {
  58. return json(["msg" => "修改成功"]);
  59. }
  60. return json(["msg" => "修改失败"]);
  61. } catch (\think\Exception $e) {
  62. return json(["msg" => $e->getMessage()]);
  63. }
  64. }
  65. return view();
  66. }
  67. /**
  68. * @auth {{/menu/remove}}
  69. * @return type
  70. */
  71. function delete() {
  72. if ($this->request->isPost()) {
  73. return json([]);
  74. }
  75. }
  76. function selectMenuTreeList() {
  77. $list = \app\common\api\MenuApi::getAllMenus("id,code,pcode,name,num,levels,ismenu");
  78. foreach ($list as $key => $item) {
  79. if ($item["pcode"] == "0") {
  80. $list[$key]["open"] = true;
  81. }
  82. }
  83. $format_list[] = ["code" => 0, "pcode" => "", "name" => "顶级", "open" => true, "children" => $list];
  84. return $format_list;
  85. }
  86. /**
  87. * 树形
  88. * @return type
  89. */
  90. function treelist() {
  91. $id = $this->request->param("id");
  92. $list = getTreeList(\app\common\api\MenuApi::getPrivilagesByRoleid($id));
  93. $format_list = [];
  94. foreach ($list as $item) {
  95. $format_list[] = [
  96. "checked" => $item["checked"],
  97. "id" => $item["id"],
  98. "isOpen" => true,
  99. "name" => $item["name"],
  100. "open" => $item["pid"] == 0 ? true : false,
  101. "pId" => $item["pid"]
  102. ];
  103. }
  104. return $format_list;
  105. }
  106. }