初始化仓库
This commit is contained in:
58
admin/components/UI/Table/Column/Status.php
Normal file
58
admin/components/UI/Table/Column/Status.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace admin\components\UI\Table\Column;
|
||||
|
||||
use admin\components\UI\Widget\Badge;
|
||||
|
||||
/**
|
||||
* Class Status
|
||||
*/
|
||||
class Status implements Component
|
||||
{
|
||||
|
||||
private array $map;
|
||||
private array $color;
|
||||
private string $type;
|
||||
|
||||
/**
|
||||
* @param array $map
|
||||
* @param array $color
|
||||
* @param string $type
|
||||
*/
|
||||
public function __construct(array $map, array $color, string $type = 'badge')
|
||||
{
|
||||
$this->map = $map;
|
||||
$this->color = $color;
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $label
|
||||
* @return array
|
||||
*/
|
||||
public function render($label): array
|
||||
{
|
||||
$statusArr = [];
|
||||
foreach ($this->map as $key => $vo) {
|
||||
$statusArr[$key]['name'] = $vo;
|
||||
$statusArr[$key]['color'] = $this->color[$key] ?? 'blue';
|
||||
}
|
||||
|
||||
$node = [];
|
||||
foreach ($statusArr as $key => $vo) {
|
||||
if ($this->type === 'badge') {
|
||||
$item = (new Badge($vo['name']))->color($vo['color'])->render();
|
||||
$item['vIf'] = "rowData.record['{$label}'] == " . (is_numeric($key) ? $key : "'$key'");
|
||||
} else {
|
||||
$item = [
|
||||
'nodeName' => 'div',
|
||||
'class' => 'text-' . $vo['color'] . '-900',
|
||||
'child' => $vo['name']
|
||||
];
|
||||
}
|
||||
$node[] = $item;
|
||||
}
|
||||
return $node;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user