初始化仓库
This commit is contained in:
67
admin/components/UI/Form/Toggle.php
Normal file
67
admin/components/UI/Form/Toggle.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace admin\components\UI\Form;
|
||||
|
||||
/**
|
||||
* 开关切换
|
||||
* @package backend\components\UI\Form
|
||||
*/
|
||||
class Toggle extends Element implements Component
|
||||
{
|
||||
private $checkedValue = 1;
|
||||
private $uncheckedValue = 0;
|
||||
|
||||
/**
|
||||
* Toggle constructor.
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function render(): array
|
||||
{
|
||||
$data = [
|
||||
'nodeName' => 'a-switch',
|
||||
'vModel:modelValue' => $this->getModelField(),
|
||||
'checkedValue' => $this->checkedValue,
|
||||
'uncheckedValue' => $this->uncheckedValue
|
||||
];
|
||||
|
||||
if($this->replace != ''){
|
||||
$data['vStringReplace'] = $this->replace;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开关数据
|
||||
* @param string|number|boolean $checkedValue
|
||||
* @param string|number|boolean $uncheckedValue
|
||||
* @return $this
|
||||
*/
|
||||
public function data($checkedValue,$uncheckedValue){
|
||||
$this->checkedValue = $checkedValue;
|
||||
$this->uncheckedValue = $uncheckedValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return int
|
||||
*/
|
||||
public function dataInput($data): int
|
||||
{
|
||||
return $data ? 1 : 0;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user