| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace Dcat\Admin\Grid;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Support\LazyRenderable as Renderable;
- abstract class LazyRenderable extends Renderable
- {
- /**
- * 是否启用简化模式.
- *
- * @var bool
- */
- protected $simple = false;
- /**
- * 创建表格.
- *
- * @return Grid
- */
- abstract public function grid(): Grid;
- /**
- * {@inheritdoc}
- */
- public function render()
- {
- $class = $this->allowSimpleMode() ? 'simple-grid' : null;
- return <<<HTML
- <div class="$class">{$this->prepare($this->grid())->render()}</div>
- HTML;
- }
- /**
- * 是否启用简化模式.
- *
- * @param bool $value
- *
- * @return $this
- */
- public function simple(bool $value = true)
- {
- return $this->payload(['_simple_' => $value]);
- }
- /**
- * @param Grid $grid
- *
- * @return Grid
- */
- protected function prepare(Grid $grid)
- {
- if (! $grid->getName()) {
- $grid->setName($this->getDefaultName());
- }
- if ($this->allowSimpleMode()) {
- $grid->disableCreateButton();
- $grid->disablePerPages();
- $grid->disableBatchDelete();
- $grid->disableRefreshButton();
- $grid->filter()
- ->panel()
- ->view('admin::filter.tile-container');
- $grid->rowSelector()->click();
- }
- return $grid;
- }
- /**
- * 判断是否启用简化模式.
- *
- * @return bool
- */
- public function allowSimpleMode()
- {
- return $this->simple || $this->_simple_;
- }
- /**
- * 获取默认名称.
- *
- * @return string
- */
- protected function getDefaultName()
- {
- return strtolower(str_replace('\\', '-', static::class));
- }
- }
|