初始化仓库
This commit is contained in:
121
admin/components/UI/Form/Text.php
Normal file
121
admin/components/UI/Form/Text.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace admin\components\UI\Form;
|
||||
|
||||
use admin\components\UI\Widget\Icon;
|
||||
|
||||
/**
|
||||
* 输入框
|
||||
* @package backend\components\UI\Form
|
||||
*/
|
||||
class Text extends Element implements Component
|
||||
{
|
||||
protected string $type = 'text';
|
||||
protected array $before = [];
|
||||
protected array $after = [];
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $field
|
||||
* @param string $has
|
||||
*/
|
||||
public function __construct(string $name, string $field, string $has = '')
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->field = $field;
|
||||
$this->has = $has;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文本类型
|
||||
* @param $name
|
||||
* @return $this
|
||||
*/
|
||||
public function type($name): self
|
||||
{
|
||||
$this->type = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 前置图标
|
||||
* @param $content
|
||||
* @return $this
|
||||
*/
|
||||
public function beforeIcon($content): self
|
||||
{
|
||||
$this->before = (new Icon($content))->attr('vSlot:prepend', '')->getRender();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 后置图标
|
||||
* @param $content
|
||||
* @return $this
|
||||
*/
|
||||
public function afterIcon($content): self
|
||||
{
|
||||
$this->after = (new Icon($content))->attr('vSlot:append', '')->getRender();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 前置文本
|
||||
* @param $content
|
||||
* @return $this
|
||||
*/
|
||||
public function beforeText($content): self
|
||||
{
|
||||
$this->before = [
|
||||
'vSlot:prepend' => '',
|
||||
'nodeName' => 'span',
|
||||
'child' => $content
|
||||
];
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 后置文本
|
||||
* @param $content
|
||||
* @return $this
|
||||
*/
|
||||
public function afterText($content): self
|
||||
{
|
||||
$this->after = [
|
||||
'vSlot:append' => '',
|
||||
'nodeName' => 'span',
|
||||
'child' => $content
|
||||
];
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function render(): array
|
||||
{
|
||||
|
||||
$child = [];
|
||||
if ($this->before || $this->after) {
|
||||
$child = [
|
||||
$this->before,
|
||||
$this->after
|
||||
];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'nodeName' => 'a-input',
|
||||
'vModel:modelValue' => $this->getModelField(),
|
||||
'child' => $child,
|
||||
'placeholder' => '请输入' . $this->name
|
||||
];
|
||||
|
||||
if($this->replace != ''){
|
||||
$data['vStringReplace'] = $this->replace;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user