1
0
mirror of https://github.com/cjango/dcat-vue.git synced 2025-12-07 15:10:04 +08:00

新增(覆盖)tags表单组件

This commit is contained in:
weiwait
2022-07-16 11:10:16 +08:00
parent dbf77d7fe9
commit e071e0355a
6 changed files with 803 additions and 312 deletions

77
src/Field/Tag.php Normal file
View File

@@ -0,0 +1,77 @@
<?php
namespace Weiwait\DcatVue\Field;
use Dcat\Admin\Form\Field;
use Dcat\Admin\Support\Helper;
class Tag extends Field\Tags
{
protected $view = 'weiwait.dcat-vue::tag';
public function render()
{
/****************************** parent ************************************/
$value = Helper::array($this->value());
if ($this->options instanceof \Closure) {
$this->options(
$this->options->call($this->values(), $value, $this)
);
}
if ($this->keyAsValue) {
$options = $value + $this->options;
} else {
$options = array_unique(array_merge($value, (array) $this->options));
}
$this->addVariables([
'options' => $options,
'keyAsValue' => $this->keyAsValue,
]);
/****************************** end parent ************************************/
/****************************** field ************************************/
if (!$this->shouldRender()) {
return '';
}
$this->setDefaultClass();
$this->callComposing();
$this->withScript();
/****************************** end field ************************************/
$this->withProvides();
$this->addVariables([
'provides' => $this->variables(),
]);
return view($this->view(), $this->variables());
}
protected function formatAttributes()
{
return $this->attributes;
}
protected function withProvides()
{
$this->addVariables([
'component' => 'Tag',
]);
}
public function max(int $max): self
{
$this->addVariables(['max' => $max]);
return $this;
}
}