103 lines
2.7 KiB
PHP
103 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Traits;
|
|
|
|
use Illuminate\Contracts\Support\Renderable;
|
|
|
|
trait WithUploads
|
|
{
|
|
|
|
/**
|
|
* Notes : 单张封面图上传
|
|
*
|
|
* @Date : 2021/4/25 2:06 下午
|
|
* @Author : < Jason.C >
|
|
* @param \Encore\Admin\Form $form
|
|
* @param string $filed
|
|
* @param string $label
|
|
*/
|
|
public function cover(Renderable $form, string $filed = 'cover', string $label = '封面图片')
|
|
{
|
|
$cover = $form->image($filed, $label)
|
|
->move('images/'.date('Y/m/d'))
|
|
->uniqueName()
|
|
->removable()
|
|
->retainable();
|
|
|
|
$waterConfig = config('admin.image_water');
|
|
|
|
if (! empty($waterConfig)) {
|
|
$cover->insert(...$waterConfig);
|
|
}
|
|
|
|
$coverThumb = config('admin.cover_thumb');
|
|
|
|
if (! empty($coverThumb)) {
|
|
$cover->thumbnail($coverThumb);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Notes: 上传视频
|
|
*
|
|
* @Author: 玄尘
|
|
* @Date: 2022/9/30 9:44
|
|
* @param Renderable $form
|
|
* @param string $filed
|
|
* @param string $label
|
|
*/
|
|
public function video(Renderable $form, string $filed = 'path', string $label = '视频')
|
|
{
|
|
$form->file($filed, $label)
|
|
->move('videos/'.date('Y/m/d'))
|
|
->uniqueName()
|
|
->removable()
|
|
->downloadable()
|
|
->retainable();
|
|
}
|
|
|
|
/**
|
|
* Notes : 统一的多图上传
|
|
*
|
|
* @Date : 2021/4/25 2:06 下午
|
|
* @Author : < Jason.C >
|
|
* @param \Encore\Admin\Form $form
|
|
* @param string $filed
|
|
* @param string $label
|
|
*/
|
|
public function pictures(Renderable $form, string $filed = 'pictures', string $label = '多图轮播')
|
|
{
|
|
$pictures = $form->multipleImage($filed, $label)
|
|
->move('images/'.date('Y/m/d'))
|
|
->uniqueName()
|
|
->removable()
|
|
->retainable();
|
|
|
|
// 多图如果开启排序的话,会报错,暂时没由解决办法 ->sortable()
|
|
$waterConfig = config('admin.image_water');
|
|
|
|
if (! empty($waterConfig)) {
|
|
$pictures->insert(...$waterConfig);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Notes : 统一的附件上传
|
|
*
|
|
* @Date : 2021/4/25 3:03 下午
|
|
* @Author : < Jason.C >
|
|
* @param \Illuminate\Contracts\Support\Renderable $form
|
|
* @param string $filed
|
|
* @param string $label
|
|
*/
|
|
public function attachments(Renderable $form, string $filed = 'attachments', string $label = '内容附件')
|
|
{
|
|
$form->multipleFile($filed, $label)
|
|
->move('attachments/'.date('Y/m/d'))
|
|
->uniqueName()
|
|
->removable()
|
|
->retainable()
|
|
->sortable();
|
|
}
|
|
|
|
} |