114 lines
3.0 KiB
PHP
114 lines
3.0 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
namespace Builder\View\Grid\Concerns;
|
|
trait HasPageAttributes
|
|
{
|
|
|
|
protected $hidePage = false;
|
|
|
|
/**
|
|
*顶部栏按钮
|
|
* @var array
|
|
*/
|
|
protected $top_buttons = [];
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function isHidePage(): bool
|
|
{
|
|
return $this->hidePage;
|
|
}
|
|
/**
|
|
* 隐藏分页
|
|
* @return $this
|
|
*/
|
|
public function hidePage()
|
|
{
|
|
$this->hidePage = true;
|
|
if ($this->model) {
|
|
$this->model->usePaginate(false);
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* 一次性添加多个顶部按钮
|
|
* @param array|string $buttons 按钮类型
|
|
* 例如:
|
|
* $builder->addTopButtons('add');
|
|
* $builder->addTopButtons('add,delete');
|
|
* $builder->addTopButtons(['add', 'delete']);
|
|
* @param array $buttons
|
|
* @return $this
|
|
*/
|
|
public function addTopButtons($buttons = [])
|
|
{
|
|
if (!empty($buttons)) {
|
|
$buttons = is_array($buttons) ? $buttons : explode(',', $buttons);
|
|
foreach ($buttons as $key => $value) {
|
|
if (is_numeric($key)) {
|
|
$this->addTopButton($value);
|
|
} else {
|
|
$this->addTopButton($key, $value);
|
|
}
|
|
}
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
/***
|
|
* 添加顶部按钮
|
|
* @param string $type 'add,edit,delete,recovery,import,export'
|
|
* @param array $attribute
|
|
* @param false $pop
|
|
*/
|
|
public function addTopButton($type, $attribute = [], $pop = false)
|
|
{
|
|
$btn=[
|
|
'show' => true,
|
|
'icon' => '',
|
|
'class' => '',
|
|
'href' => request()->path()
|
|
];
|
|
switch ($type) {
|
|
case 'add':
|
|
$btn['text']='新增';
|
|
$btn['btnType']='add';
|
|
break;
|
|
case 'edit':
|
|
$btn['text']='编辑';
|
|
$btn['btnType']='edit';
|
|
break;
|
|
case 'delete':
|
|
$btn['text']='删除';
|
|
$btn['btnType']='delete';
|
|
break;
|
|
case 'recovery':
|
|
$btn['text']='恢复';
|
|
$btn['btnType']='recovery';
|
|
break;
|
|
case 'enable':
|
|
$btn['text']='启用';
|
|
$btn['btnType']='enable';
|
|
break;
|
|
case 'import':
|
|
$btn['text']='导入';
|
|
$btn['url']=$btn['href'];
|
|
$btn['templateUrl']=$btn['href'];
|
|
$btn['btnType']='import';
|
|
break;
|
|
case 'export':
|
|
$btn['text']='导出';
|
|
$btn['btnType']='export';
|
|
$btn['url']=$btn['href'];
|
|
break;
|
|
}
|
|
// 合并自定义属性
|
|
if ($attribute && is_array($attribute)) {
|
|
$btn = array_merge($btn, $attribute);
|
|
}
|
|
$this->top_buttons[$type] = $btn;
|
|
return $this;
|
|
}
|
|
}
|