Menu.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\sys;
  12. use app\dict\sys\MenuDict;
  13. use app\dict\sys\MenuTypeDict;
  14. use app\dict\sys\MethodDict;
  15. use app\service\admin\install\InstallSystemService;
  16. use app\service\admin\sys\MenuService;
  17. use core\base\BaseAdminController;
  18. use think\db\exception\DbException;
  19. use think\Response;
  20. class Menu extends BaseAdminController
  21. {
  22. /**
  23. * 菜单列表(todo 限制只有平台端可以访问)
  24. * @return Response
  25. */
  26. public function lists($app_type)
  27. {
  28. return success((new MenuService())->getAllMenuList($app_type, 'all', 1));
  29. }
  30. /**
  31. * 菜单信息
  32. * @param $app_type
  33. * @param $menu_key
  34. * @return Response
  35. */
  36. public function info($app_type, $menu_key)
  37. {
  38. return success((new MenuService())->get($app_type, $menu_key));
  39. }
  40. /**
  41. * 新增菜单接口
  42. * @return Response
  43. */
  44. public function add()
  45. {
  46. $data = $this->request->params([
  47. ['app_type', ''],
  48. ['menu_name', ''],
  49. ['menu_type', 0],
  50. ['menu_key', ''],
  51. ['parent_key', ''],
  52. ['icon', ''],
  53. ['api_url', ''],
  54. ['view_path', ''],
  55. ['router_path', ''],
  56. ['methods', ''],
  57. ['sort', 0],
  58. ['status', MenuDict::ON],
  59. ['is_show', 0],
  60. ['addon', ''],
  61. ['menu_short_name','']
  62. ]);
  63. $this->validate($data, 'app\validate\sys\Menu.add');
  64. (new MenuService())->add($data);
  65. return success('ADD_SUCCESS');
  66. }
  67. /**
  68. * 菜单或接口更新
  69. */
  70. public function edit($app_type, $menu_key)
  71. {
  72. $data = $this->request->params([
  73. ['menu_name', ''],
  74. ['parent_key', ''],
  75. ['menu_type', 0],
  76. ['icon', ''],
  77. ['api_url', ''],
  78. ['router_path', ''],
  79. ['view_path', ''],
  80. ['methods', ''],
  81. ['sort', 0],
  82. ['status', MenuDict::ON],
  83. ['is_show', 0],
  84. ['addon', ''],
  85. ['menu_short_name','']
  86. ]);
  87. $this->validate($data, 'app\validate\sys\Menu.edit');
  88. (new MenuService())->edit($app_type, $menu_key, $data);
  89. return success('EDIT_SUCCESS');
  90. }
  91. /**
  92. * 获取菜单类型静态资源
  93. * @return Response
  94. */
  95. public function getMenuType()
  96. {
  97. return success(MenuTypeDict::getMenuType());
  98. }
  99. /**
  100. * 获取请求方式
  101. * @return Response
  102. */
  103. public function getMethodType()
  104. {
  105. return success(MethodDict::getMethodType());
  106. }
  107. /**
  108. * 删除菜单
  109. * @param $app_type
  110. * @param $menu_key
  111. * @return Response
  112. * @throws DbException
  113. */
  114. public function del($app_type, $menu_key)
  115. {
  116. (new MenuService())->del($app_type, $menu_key);
  117. return success('DELETE_SUCCESS');
  118. }
  119. public function refreshMenu()
  120. {
  121. (new InstallSystemService())->install();
  122. return success('SUCCESS');
  123. }
  124. /**
  125. * 查询菜单信息
  126. */
  127. public function getSystem()
  128. {
  129. return success( (new MenuService())->getSystemMenu('all', 1));
  130. }
  131. /**
  132. * 查询应用权限信息
  133. */
  134. public function getAddonMenu($app_key)
  135. {
  136. return success( (new MenuService())->getAddonMenu($app_key,'all', 1));
  137. }
  138. /**
  139. * 查询菜单类型为目录的菜单
  140. * @param $addon
  141. * @return Response
  142. */
  143. public function getMenuByTypeDir($addon = 'system') {
  144. return success( (new MenuService())->getMenuByTypeDir($addon));
  145. }
  146. }