| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace app\controller\common;
- use app\extra\basic\Base;
- use app\extra\tools\DataExtend;
- use app\middleware\AuthMiddleware;
- use app\model\system\SystemMenu;
- use app\service\system\MenuService;
- use DI\Attribute\Inject;
- use LinFly\Annotation\Attributes\Route\Controller;
- use LinFly\Annotation\Attributes\Route\GetMapping;
- use LinFly\Annotation\Attributes\Route\Middleware;
- use LinFly\Annotation\Attributes\Route\PostMapping;
- use support\Request;
- use support\Response;
- #[Controller(prefix: "/api/menu"),Middleware(AuthMiddleware::class)]
- class Menu extends Base
- {
- #[Inject]
- protected MenuService $service;
- /**
- * 获取菜单
- */
- #[GetMapping("list")]
- public function getMenuList(Request $request): Response
- {
- try {
- $param = $this->_valid([
- "form.default" => $request->user['type'],
- "type.default" => 1
- ]);
- $hide = 0;
- $menu = $this->service->getMenuList($request->user['is_super'],$hide,$param['form']);
- $permissionsData = [];
- foreach ($menu as $val) {
- if ($val['type'] == 'button') {
- $permissionsData[] = $val['name'];
- }
- }
- $menu = $this->filterMenu(DataExtend::arr2tree($menu),$param['type']);
- if($param['type'] == 1) {
- $permissions = $permissionsData;
- $dashboardGrid = [];
- return successTrans("success.data",compact('menu','permissions','dashboardGrid'));
- }
- return successTrans("success.data",$menu);
- } catch (\Throwable $throwable) {
- echo $throwable->getFile()."\n";
- echo $throwable->getLine()."\n";
- return error($throwable->getMessage());
- }
- }
- /**
- * 更新
- * @param Request $request
- * @return Response
- */
- #[PostMapping("save")]
- public function saveMenuData(Request $request): Response
- {
- try {
- $state = (new SystemMenu)->setAutoData($request->post());
- if(!$state) return errorTrans("error.data");
- return successTrans("success.data");
- } catch (\Throwable $throwable) {
- return error($throwable->getMessage());
- }
- }
- }
|