75 lines
1.6 KiB
PHP
75 lines
1.6 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
namespace Builder\View\Grid;
|
|
use Builder\View\Grid\BatchActions\DeleteAction;
|
|
class BatchActions
|
|
{
|
|
protected $actions = [];
|
|
protected $addActions = [];
|
|
private $hideDeleteAction = false;
|
|
protected $deleteAction;
|
|
protected $keys = "selectionKeys";
|
|
|
|
public function __construct()
|
|
{
|
|
$this->deleteAction = DeleteAction::make();
|
|
}
|
|
|
|
/**
|
|
* 添加自定义Action
|
|
* @param $action
|
|
* @return $this
|
|
*/
|
|
public function add($action)
|
|
{
|
|
if ($action instanceof \Closure) {
|
|
$this->addActions = collect($this->addActions)->push(call_user_func($action))->all();
|
|
} else {
|
|
$this->addActions = collect($this->addActions)->push($action)->all();
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
|
|
public function deleteAction()
|
|
{
|
|
return $this->deleteAction;
|
|
}
|
|
|
|
/**
|
|
* 隐藏删除操作
|
|
* @return $this
|
|
*/
|
|
public function hideDeleteAction()
|
|
{
|
|
$this->hideDeleteAction = true;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* 获取当前Grid选择keys
|
|
* @return string
|
|
*/
|
|
public function getKeys(): string
|
|
{
|
|
return $this->keys;
|
|
}
|
|
|
|
|
|
/**
|
|
* 编译自定义操作栏
|
|
* @return \Hyperf\Utils\Collection
|
|
*/
|
|
public function builderActions()
|
|
{
|
|
$actions = collect($this->actions);
|
|
if (!$this->hideDeleteAction) {
|
|
$actions->push($this->deleteAction);
|
|
}
|
|
foreach ($this->addActions as $addAction) {
|
|
$actions->push($addAction);
|
|
}
|
|
return $actions;
|
|
}
|
|
}
|