response)) { $this->response = new Response(); } return $this->response; } /** * @return string */ public function method() { return $this->method; } /** * @return array */ protected function parameters() { return []; } /** * Confirm message of action. * * @return string|void */ public function confirm() { } /** * @return mixed */ public function makeCalledClass() { return str_replace('\\', '_', get_called_class()); } /** * @return string */ public function handlerRoute() { return route('dcat.api.action'); } /** * @return void */ protected function addHandlerScript() { $data = json_encode($this->parameters()); $script = <<selector()}', event: '{$this->event}', method: '{$this->method()}', key: '{$this->getKey()}', url: '{$this->handlerRoute()}', data: {$data}, calledClass: '{$this->makeCalledClass()}', before: {$this->actionScript()}, html: {$this->handleHtmlResponse()}, success: {$this->resolverScript()}, error: {$this->rejectScript()}, }); JS; Admin::script($script); Admin::js('@admin/dcat/extra/grid-row-action.js'); } /** * @return string */ protected function actionScript() { // 发起请求之前回调,返回false可以中断请求 return <<<'JS' function (data, target) { } JS; } /** * @return string */ protected function resolverScript() { // 请求成功回调,返回false可以中断默认的成功处理逻辑 return <<<'JS' function (target, results) {} JS; } /** * @return string */ protected function handleHtmlResponse() { return <<<'JS' function (target, html, data) { // 处理返回的HTML代码 target.html(html); } JS; } /** * @return string */ protected function rejectScript() { // // 请求出错回调,返回false可以中断默认的错误处理逻辑 return <<<'JS' function (target, results) {} JS; } /** * @return Response */ public function failedAuthorization() { return $this->response()->error(__('admin.deny')); } }