Menu.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\logic\MenuLogic;
  4. use app\BaseController;
  5. use app\model\AdminMenuModel;
  6. use think\exception\ValidateException;
  7. use think\facade\Config;
  8. use think\facade\Validate;
  9. //【菜单】
  10. class Menu extends BaseController
  11. {
  12. //获取用户菜单列表
  13. public function list()
  14. {
  15. return MenuLogic::list();
  16. }
  17. //获取全部菜单
  18. public function all()
  19. {
  20. return MenuLogic::all();
  21. }
  22. //添加菜单
  23. public function add()
  24. {
  25. $param = $this->request->only([
  26. 'menu_name',
  27. 'menu_url' => '',
  28. 'menu_route' => '',
  29. 'menu_type' => AdminMenuModel::$type_1,
  30. 'menu_img' => '',
  31. 'pid' => 0,
  32. 'private' => '',
  33. 'weight' => '',
  34. ], 'post');
  35. $val = Validate::rule(Config::get('validate_rules.menuAdd'));
  36. if (!$val->check($param)) throw new ValidateException($val->getError());
  37. return MenuLogic::add($param);
  38. }
  39. //编辑菜单
  40. public function edit()
  41. {
  42. $param = $this->request->only([
  43. 'id',
  44. 'menu_name',
  45. 'menu_url' => '',
  46. 'menu_route' => '',
  47. 'menu_type' => '',
  48. 'menu_img' => '',
  49. 'pid' => 0,
  50. 'private' => '',
  51. 'weight' => '',
  52. ], 'post');
  53. $val = Validate::rule(Config::get('validate_rules.menuEdit'));
  54. if (!$val->check($param)) throw new ValidateException($val->getError());
  55. return MenuLogic::edit($param);
  56. }
  57. //删除菜单
  58. public function delete()
  59. {
  60. $id = $this->request->post('id/d', 0);
  61. return MenuLogic::delete($id);
  62. }
  63. //启禁用菜单
  64. public function status()
  65. {
  66. $param = $this->request->only(['id', 'status'], 'post');
  67. $val = Validate::rule(Config::get('validate_rules.status'));
  68. if (!$val->check($param)) throw new ValidateException($val->getError());
  69. return MenuLogic::status($param);
  70. }
  71. }