insertField = ['name', 'value', 'desc']; $this->updateField = ['id', 'name', 'value', 'desc']; $this->notRequest = ['status', 'color', 'pid']; $this->service = RoleService::getInstance(); } /** * 获取角色菜单ID * @Method GET * @return JsonResponse * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ public function getMenuIdsByRoleIds(): JsonResponse { $roleId = request()->get('role_id', null); return jok( $this->service->getMenuIdsByRoleIds($roleId) ); } /** * 保存角色菜单 * @Method POST * @return JsonResponse * @throws Exception */ public function saveRoleMenu(): JsonResponse { $this->insertField = ['role_id', 'menu_id']; $this->checkRequiredFields(request()->post()); $roleId = request()->post('role_id'); $menuIds = request()->post('menu_id', []); return jok( $this->service->saveRoleMenu($roleId, $menuIds) ); } /** * 接口授权树:按控制器分组的全部可授权接口 * @Method GET */ public function endpointTree(): JsonResponse { return jok($this->service->endpointTree(), '获取成功'); } /** * 角色已授权的接口 id * @Method GET * @throws Exception */ public function getEndpointIdsByRoleIds(): JsonResponse { return jok($this->service->getEndpointIdsByRoleId(request()->get('role_id'))); } /** * 保存角色接口授权 * @Method POST * @throws Exception */ public function saveRoleEndpoint(): JsonResponse { $this->insertField = ['role_id']; $this->checkRequiredFields(request()->post()); return jok( $this->service->saveRoleEndpoint( (int) request()->post('role_id'), (array) request()->post('endpoint_id', []) ) ); } /** * 启用 / 停用角色 * @Method POST * @throws Exception */ public function status(): JsonResponse { $this->insertField = ['id', 'status']; $params = $this->checkRequiredFields(request()->post()); return jok($this->service->status($params['id'], $params['status']), '操作成功'); } }