Menu.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_code' => '',
  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_code' => '',
  48. 'menu_img' => '',
  49. 'pid' => 0,
  50. 'private' => '',
  51. 'weight' => '',
  52. 'is_show' => AdminMenuModel::$show
  53. ], 'post');
  54. $val = Validate::rule(Config::get('validate_rules.menuEdit'));
  55. if (!$val->check($param)) throw new ValidateException($val->getError());
  56. return MenuLogic::Edit($param);
  57. }
  58. //删除菜单
  59. public function Delete()
  60. {
  61. $id = $this->request->post('id/d', 0);
  62. return MenuLogic::Delete($id);
  63. }
  64. //启禁用菜单
  65. public function Status()
  66. {
  67. $param = $this->request->only(['id', 'status'], 'post');
  68. $val = Validate::rule(Config::get('validate_rules.status'));
  69. if (!$val->check($param)) throw new ValidateException($val->getError());
  70. return MenuLogic::Status($param);
  71. }
  72. }