hyperf-view/builder/View/Components/Widgets/Category.php

87 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Builder\View\Components\Widgets;
use Hyperf\Database\Model\Model as Eloquent;
use Builder\View\Components\Component;
use Builder\View\Grid\BatchActions;
use Builder\View\Grid\Column;
use Builder\View\Grid\Concerns\HasDefaultSort;
use Builder\View\Grid\Concerns\HasFilter;
use Builder\View\Grid\Concerns\HasGridAttributes;
use Builder\View\Grid\Concerns\HasPageAttributes;
use Builder\View\Grid\Concerns\HasQuickSearch;
use Builder\View\Grid\Filter;
use Builder\View\Grid\Model;
use Builder\View\Grid\Table\Attributes;
use Builder\View\Grid\Toolbars;
class Category extends Component
{
use HasGridAttributes, HasPageAttributes, HasDefaultSort, HasQuickSearch, HasFilter;
protected $componentName = "Tree";
protected $header;
protected $bodyStyle;
protected $content;
/**
* @var Model
*/
protected $model;
/**
* 组件字段
* @var Column[]
*/
protected $columns = [];
protected $rows;
/**
* 组件字段属性
* @var array
*/
protected $columnAttributes = [];
/**
* @var string
*/
protected $keyName = 'id';
/**
* @var bool
*/
protected $tree = false;
/**
* 表格数据来源
* @var string
*/
protected $dataUrl;
protected $customData;
protected $isGetData = false;
private $actions;
private $batchActions;
private $toolbars;
private $top;
private $bottom;
public function __construct(Eloquent $model = null)
{
$this->attributes = new Attributes();
$this->dataUrl = admin_api_url(request()->path()).'/list';
$this->model = new Model($model, $this);
if ($model) {
$this->keyName = $model->getKeyName();
$this->defaultSort($model->getKeyName(), "asc");
}
$this->isGetData = request('get_data') == "true";
$this->toolbars = new Toolbars($this);
$this->batchActions = new BatchActions();
$this->filter = new Filter($this->model);
}
public static function make()
{
return new Category();
}
}