You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
139 lines
3.1 KiB
139 lines
3.1 KiB
3 years ago
|
<?php
|
||
|
/**
|
||
|
*
|
||
|
* FormText.php
|
||
|
* User: ChenLong
|
||
|
* DateTime: 2020/3/11 14:40
|
||
|
*/
|
||
|
|
||
|
|
||
|
namespace sdModule\makeAdminBasics\htmlUnit;
|
||
|
|
||
|
|
||
|
use sdModule\makeAdminBasics\Basics;
|
||
|
use sdModule\makeAdminBasics\ConfigHelper;
|
||
|
|
||
|
/**
|
||
|
* 多图
|
||
|
* Class FormText
|
||
|
* @package sdModule\makeAdminBasics\htmlUnit
|
||
|
*/
|
||
|
class FormImages implements FormUnitInterface
|
||
|
{
|
||
|
|
||
|
/**
|
||
|
* @var string
|
||
|
*/
|
||
|
private $label;
|
||
|
|
||
|
/**
|
||
|
* @var string
|
||
|
*/
|
||
|
private $name;
|
||
|
|
||
|
/**
|
||
|
* @var
|
||
|
*/
|
||
|
private $default;
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* FormText constructor.
|
||
|
* @param string $label
|
||
|
* @param string $name
|
||
|
*/
|
||
|
public function __construct(string $label, string $name)
|
||
|
{
|
||
|
$this->label = $label;
|
||
|
$this->name = $name;
|
||
|
JsFacade::registerLayUIModule('upload');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获取html
|
||
|
* @return mixed|string
|
||
|
*/
|
||
|
public function getHtml()
|
||
|
{
|
||
|
return <<<HTML
|
||
|
|
||
|
<div class="layui-form-item">{$this->getLabel()}
|
||
|
<div class="layui-input-block">{$this->getForm()}</div>
|
||
|
</div>
|
||
|
|
||
|
HTML;
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获取label
|
||
|
* @return string
|
||
|
*/
|
||
|
private function getLabel()
|
||
|
{
|
||
|
return Basics::indentAndLineFeed(4, Basics::BEFORE) . "<label class=\"layui-form-label\">{$this->label}</label>";
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获取表单html文本
|
||
|
* @return string
|
||
|
*/
|
||
|
private function getForm()
|
||
|
{
|
||
|
JsFacade::layUICode($this->upLoadJs());
|
||
|
JsFacade::resetCode($this->resetCode());
|
||
|
$html = <<<IMG
|
||
|
|
||
|
<div class="layui-upload">
|
||
|
<input type="hidden" name="{$this->name}">
|
||
|
<div class="layui-btn-group">
|
||
|
<button type="button" class="layui-btn" id="{$this->name}">
|
||
|
<i class="layui-icon layui-icon-upload"></i>{:lang('Select Image')}</button>
|
||
|
<button type="button" class="layui-btn layui-btn-normal" id="{$this->name}-select">
|
||
|
<i class="layui-icon layui-icon-picture"></i>{:lang('System picture')}</button>
|
||
|
</div>
|
||
|
<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
|
||
|
{:lang('preview')}:
|
||
|
<div class="layui-upload-list" id="{$this->name}-show" style="overflow: hidden"></div>
|
||
|
</blockquote>
|
||
|
</div>
|
||
|
IMG;
|
||
|
return $html . Basics::indentAndLineFeed(4, Basics::BEFORE);
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* 多图上传的 js文件
|
||
|
* @return string
|
||
|
*/
|
||
|
private function upLoadJs()
|
||
|
{
|
||
|
return <<<JST
|
||
|
|
||
|
window.{$this->name} = custom.moreUpload($, '{$this->name}', upload).init();
|
||
|
JST;
|
||
|
}
|
||
|
|
||
|
private function resetCode()
|
||
|
{
|
||
|
$init = $this->default ? "'{\$data.{$this->name}}'.split(',')" : '';
|
||
|
return <<<JST
|
||
|
|
||
|
{$this->name}.init($init);
|
||
|
JST;
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 设置默认值
|
||
|
* @param $value
|
||
|
* @return mixed
|
||
|
*/
|
||
|
public function setDefault($value)
|
||
|
{
|
||
|
$value and $this->default = $value;
|
||
|
return $this;
|
||
|
}
|
||
|
}
|
||
|
|