81 lines
2.0 KiB
PHP
81 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace admin\components\UI\Table\Column;
|
|
|
|
use admin\components\UI\Tools;
|
|
|
|
/**
|
|
* Class Link
|
|
*/
|
|
class Link implements Component
|
|
{
|
|
|
|
private array $link;
|
|
private array $fields;
|
|
|
|
/**
|
|
* @param array $fields
|
|
* @return $this
|
|
*/
|
|
public function fields(array $fields = []): Link
|
|
{
|
|
$this->fields = $fields;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* 添加条目
|
|
* @param string $name
|
|
* @param string $route
|
|
* @param array $params
|
|
* @param bool $absolute
|
|
* @return \backend\components\UI\Widget\Link
|
|
*/
|
|
public function add(string $name, string $route, array $params = [], bool $absolute = false): \backend\components\UI\Widget\Link
|
|
{
|
|
$link = new \backend\components\UI\Widget\Link($name, $route, $params, $absolute);
|
|
$link->fields($this->fields);
|
|
$link = $link->model('rowData.record');
|
|
$this->link[] = $link;
|
|
return $link;
|
|
}
|
|
|
|
/**
|
|
* @param $label
|
|
* @return array
|
|
*/
|
|
public function render($label): array
|
|
{
|
|
$link = [];
|
|
foreach ($this->link as $class) {
|
|
$type = $class->getType();
|
|
$data = $class->render();
|
|
|
|
if (($type === 'ajax' || $type === 'dialog') && (!isset($data['vBind:before']) || !isset($data['before']))) {
|
|
$data['vBind:before'] = "() => rowData.record.__loading = true";
|
|
}
|
|
|
|
if (($type === 'ajax' || $type === 'dialog') && (!isset($data['vBind:after']) || !isset($data['after']))) {
|
|
$data['vBind:after'] = "() => rowData.record.__loading = false";
|
|
}
|
|
|
|
$link[] = [
|
|
'nodeName' => 'span',
|
|
'child' => $data
|
|
];
|
|
}
|
|
|
|
$link = array_filter($link);
|
|
return [
|
|
'nodeName' => 'a-spin',
|
|
'vBind:loading' => 'rowData.record.__loading',
|
|
'child' => [
|
|
'nodeName' => 'div',
|
|
'class' => 'inline-flex gap-2',
|
|
'child' => $link
|
|
]
|
|
];
|
|
}
|
|
|
|
}
|