新增附件事件

This commit is contained in:
JaguarJack 2020-06-01 21:25:46 +08:00
parent 39c0ec4c48
commit fe6ea82014
3 changed files with 67 additions and 36 deletions

View File

@ -0,0 +1,17 @@
<?php
namespace catchAdmin\system\events;
use catchAdmin\system\model\Attachments;
class AttachmentEvent
{
public function handle($params)
{
$file = $params['file'];
unset($params['file']);
Attachments::store($params, $file);
}
}

View File

@ -89,6 +89,10 @@ return [
'operateLog' => [ 'operateLog' => [
OperateLogEvent::class, OperateLogEvent::class,
], ],
// 附件操作
'attachment' => [
\catchAdmin\system\events\AttachmentEvent::class,
],
// 路由加载 // 路由加载
'RouteLoaded' => [ 'RouteLoaded' => [
LoadModuleRoutes::class LoadModuleRoutes::class

View File

@ -63,10 +63,12 @@ class CatchUpload
if ($path) { if ($path) {
$url = self::getCloudDomain($this->getDriver()) . $path; $url = self::getCloudDomain($this->getDriver()) . $path;
Attachments::create(array_merge([ event('attachment', [
'path' => $path, 'path' => $path,
'url' => $url, 'url' => $url,
], $this->data($file))); 'driver' => $this->getDriver(),
'file' => $file,
]);
return $url; return $url;
} }
@ -215,7 +217,12 @@ class CatchUpload
return $this; return $this;
} }
/**
* 初始化配置
*
* @time 2020年06月01日
* @return void
*/
protected function initUploadConfig() protected function initUploadConfig()
{ {
$configModel = app(Config::class); $configModel = app(Config::class);
@ -224,7 +231,9 @@ class CatchUpload
if ($upload) { if ($upload) {
$disk = app()->config->get('filesystem.disks'); $disk = app()->config->get('filesystem.disks');
$uploadConfigs = $configModel->getConfig($upload->id); $uploadConfigs = $configModel->getConfig($upload->id);
if (!empty($uploadConfigs)) {
// 读取上传可配置数据 // 读取上传可配置数据
foreach ($uploadConfigs as $key => &$config) { foreach ($uploadConfigs as $key => &$config) {
// $disk[$key]['type'] = $key; // $disk[$key]['type'] = $key;
@ -246,7 +255,7 @@ class CatchUpload
} }
// 合并数组 // 合并数组
array_walk($disk, function (&$item, $key) use ($uploadConfigs){ array_walk($disk, function (&$item, $key) use ($uploadConfigs) {
if (!in_array($key, ['public', 'local'])) { if (!in_array($key, ['public', 'local'])) {
if ($uploadConfigs[$key] ?? false) { if ($uploadConfigs[$key] ?? false) {
foreach ($uploadConfigs[$key] as $k => $value) { foreach ($uploadConfigs[$key] as $k => $value) {
@ -261,6 +270,7 @@ class CatchUpload
], 'filesystem'); ], 'filesystem');
} }
} }
}
/** /**
* 获取云存储的域名 * 获取云存储的域名