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.
62 lines
1.5 KiB
62 lines
1.5 KiB
<?php |
|
/** |
|
* Date: 2020/10/12 12:57 |
|
* User: chenlong <vip_chenlong@163.com> |
|
*/ |
|
|
|
namespace sdModule\layui\defaultForm\formUnit; |
|
|
|
|
|
use think\facade\Db; |
|
|
|
class Upload extends UnitBase |
|
{ |
|
public ?string $default = ''; |
|
|
|
public function getHtml(string $attr) |
|
{ |
|
return <<<HTML |
|
<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>选择文件 |
|
</button> |
|
</div> |
|
<div class="layui-upload-list"> |
|
<table class="layui-table {$this->name}-table-xc"> |
|
<tbody></tbody> |
|
</table> |
|
</div> |
|
</div> |
|
HTML; |
|
} |
|
|
|
/** |
|
* @return mixed|string |
|
*/ |
|
public function getJs() |
|
{ |
|
return <<<JS |
|
window.{$this->name} = custom.fileUpload(layui.jquery, layui.upload, '{$this->name}', "{$this->select_data['type']}"); |
|
defaultData.{$this->name} = function(){ |
|
{$this->name}.defaults({$this->getData()}); |
|
}; |
|
JS; |
|
} |
|
|
|
/** |
|
* 获取对应的默认值 |
|
* @return false|string |
|
*/ |
|
private function getData() |
|
{ |
|
try { |
|
$data = Db::name('resource')->whereIn('id', $this->default) |
|
->field('tag,id')->select(); |
|
return json_encode($data, JSON_UNESCAPED_UNICODE); |
|
} catch (\Exception $exception) { |
|
return json_encode([]); |
|
} |
|
} |
|
}
|
|
|