modal = Modal::make() ->lg() ->class('grid-modal', true); if ($title instanceof LazyRenderable) { $table = $title; $title = null; } $this->title($title); $this->body($table); } /** * 设置异步表格实例. * * @param LazyRenderable|null $renderable * * @return $this */ public function body(?LazyRenderable $renderable) { if (! $renderable) { return $this; } $this->table = AsyncTable::make($renderable, false)->simple(); $this->modal->body($this->table); return $this; } /** * 设置或获取ID. * * @param string|null $id * * @return |string */ public function id(string $id = null) { $result = $this->modal->id($id); if ($id === null) { return $result; } return $this; } /** * 监听弹窗异步渲染完成事件. * * @param string $script * * @return $this */ public function onLoad(string $script) { $this->loadScript .= $script.';'; return $this; } /** * {@inheritdoc} */ public function html() { if ($this->runScript) { $this->modal->onShow($this->table->getLoadScript()); } if ($this->loadScript) { $this->table->onLoad($this->loadScript); } $this->table->runScript($this->runScript); $this->modal->runScript($this->runScript); return $this->modal->render(); } /** * {@inheritdoc} */ public function getScript() { return parent::getScript() .$this->modal->getScript() .$this->table->getScript(); } /** * @return Modal */ public function getModal() { return $this->modal; } /** * @return AsyncTable */ public function getTable() { return $this->table; } public static function __callStatic($method, $arguments) { return static::make()->$method(...$arguments); } public function __call($method, $parameters) { if (in_array($method, $this->allowMethods, true)) { $result = $this->modal->$method(...$parameters); if (in_array($method, ['getElementSelector'], true)) { return $result; } return $this; } throw new \Exception( sprintf('Call to undefined method "%s::%s"', static::class, $method) ); } }