Menu.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 Add()
  19. {
  20. $param = $this->request->only([
  21. 'menu_name',
  22. 'menu_url' => '',
  23. 'menu_route' => '',
  24. 'menu_code' => '',
  25. 'menu_img' => '',
  26. 'pid' => 0,
  27. 'private' => '',
  28. 'weight' => '',
  29. ], 'post');
  30. $val = Validate::rule(Config::get('validate_rules.menuAdd'));
  31. if (!$val->check($param)) throw new ValidateException($val->getError());
  32. return MenuLogic::Add($param);
  33. }
  34. //编辑菜单
  35. public function Edit()
  36. {
  37. $param = $this->request->only([
  38. 'id',
  39. 'menu_name',
  40. 'menu_url' => '',
  41. 'menu_route' => '',
  42. 'menu_code' => '',
  43. 'menu_img' => '',
  44. 'pid' => 0,
  45. 'private' => '',
  46. 'weight' => '',
  47. 'is_show' => AdminMenuModel::$show
  48. ], 'post');
  49. $val = Validate::rule(Config::get('validate_rules.menuEdit'));
  50. if (!$val->check($param)) throw new ValidateException($val->getError());
  51. return MenuLogic::Edit($param);
  52. }
  53. //删除菜单
  54. public function Delete()
  55. {
  56. $id = $this->request->post('id/d', 0);
  57. return MenuLogic::Delete($id);
  58. }
  59. //启禁用菜单
  60. public function Status()
  61. {
  62. $param = $this->request->only(['id', 'status'], 'post');
  63. $val = Validate::rule(Config::get('validate_rules.status'));
  64. if (!$val->check($param)) throw new ValidateException($val->getError());
  65. return MenuLogic::Status($param);
  66. }
  67. }