192 lines
3.6 KiB
PHP
192 lines
3.6 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
namespace Builder\View\Grid;
|
|
use Builder\View\Grid;
|
|
use Builder\View\Grid\Column\Attributes;
|
|
use Closure;
|
|
class Column
|
|
{
|
|
use Grid\Concerns\HasColumnAttributes;
|
|
/**
|
|
* @var Grid
|
|
*/
|
|
protected $grid;
|
|
|
|
// protected $name;
|
|
//
|
|
// protected $dataIndex;
|
|
//
|
|
// protected $title;
|
|
//
|
|
// protected $defaultValue;
|
|
//
|
|
// protected $formType;
|
|
//
|
|
// protected $extra;
|
|
//
|
|
// private $columnData;
|
|
/**
|
|
* @var Closure
|
|
*/
|
|
protected $displayCallbacks;
|
|
|
|
public function __construct($dataIndex, $title, $type,$default,$param)
|
|
{
|
|
$this->attributes = new Attributes();
|
|
|
|
|
|
$this->attributes->dataIndex=$dataIndex;
|
|
|
|
$this->attributes->title=$title;
|
|
|
|
$this->attributes->formType=$type;
|
|
|
|
$this->attributes->extra=$param;
|
|
|
|
// $this->dataIndex = $dataIndex;
|
|
// $this->title = $title;
|
|
// $this->formType = $type;
|
|
// $this->default = $default;
|
|
// $this->extra = $param;
|
|
// $this->initAttributes();
|
|
}
|
|
|
|
|
|
protected function initAttributes()
|
|
{
|
|
$this->attributes->title = $this->title;
|
|
$this->attributes->dataIndex = $this->dataIndex;
|
|
}
|
|
|
|
|
|
protected function formatLabel($label)
|
|
{
|
|
if ($label) {
|
|
return $label;
|
|
}
|
|
$label = ucfirst($this->title);
|
|
return (str_replace(['.', '_'], ' ', $label));
|
|
}
|
|
|
|
/**
|
|
* 设置栅格
|
|
* @param Grid $grid
|
|
*/
|
|
public function setGrid(Grid $grid)
|
|
{
|
|
$this->grid = $grid;
|
|
}
|
|
|
|
/**
|
|
* 自定义值 函数
|
|
* @param Closure $callback
|
|
* @return $this
|
|
*/
|
|
public function customValue(Closure $callback)
|
|
{
|
|
$this->displayCallbacks = $callback;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* 自定义静态参数
|
|
* @param $row
|
|
* @param $value
|
|
* @return false|mixed
|
|
*/
|
|
public function customValueUsing($row, $value)
|
|
{
|
|
return $this->displayCallbacks ? call_user_func($this->displayCallbacks, $row, $value) : $value;
|
|
}
|
|
|
|
/**
|
|
* 设置组件
|
|
* @param $component
|
|
* @return $this
|
|
* @deprecated
|
|
*/
|
|
public function displayComponent($component)
|
|
{
|
|
if ($component instanceof Closure) {
|
|
$this->displayComponentAttrs(call_user_func($component));
|
|
} else {
|
|
$this->displayComponentAttrs($component);
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* 设置组件
|
|
* @param $component
|
|
* @return $this
|
|
*/
|
|
public function component($component)
|
|
{
|
|
if ($component instanceof Closure) {
|
|
$this->displayComponentAttrs(call_user_func($component));
|
|
} else {
|
|
$this->displayComponentAttrs($component);
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
|
|
public function getAttributes()
|
|
{
|
|
return $this->attributes;
|
|
}
|
|
|
|
/**
|
|
* @return Grid
|
|
*/
|
|
public function getGrid()
|
|
{
|
|
return $this->grid;
|
|
}
|
|
|
|
/**
|
|
* @return array|string|null
|
|
*/
|
|
public function getLabel()
|
|
{
|
|
return $this->label;
|
|
}
|
|
|
|
/**
|
|
* @return mixed
|
|
*/
|
|
public function getName()
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
|
|
/**
|
|
* @return null
|
|
*/
|
|
public function getColumnKey()
|
|
{
|
|
return $this->columnKey;
|
|
}
|
|
|
|
/**
|
|
* 获取默认值
|
|
* @return mixed
|
|
*/
|
|
public function getDefaultValue()
|
|
{
|
|
return $this->defaultValue;
|
|
}
|
|
|
|
/**
|
|
* 设置默认值
|
|
* @param mixed $defaultValue
|
|
* @return $this
|
|
*/
|
|
public function defaultValue($defaultValue)
|
|
{
|
|
$this->defaultValue = $defaultValue;
|
|
return $this;
|
|
}
|
|
}
|