From 46d751cd3307ded4e7e229437bde54a29c7551f2 Mon Sep 17 00:00:00 2001 From: yiqiu Date: Sun, 28 Dec 2025 13:12:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/addon/theme_configurator/README.md | 22 ++-- .../controller/UploadController.php | 101 ------------------ plugins/addon/theme_configurator/route.php | 13 +-- 3 files changed, 14 insertions(+), 122 deletions(-) delete mode 100644 plugins/addon/theme_configurator/controller/UploadController.php diff --git a/plugins/addon/theme_configurator/README.md b/plugins/addon/theme_configurator/README.md index 99a8eda..25f6bc3 100644 --- a/plugins/addon/theme_configurator/README.md +++ b/plugins/addon/theme_configurator/README.md @@ -3,17 +3,17 @@ 此插件演示如何通过后台插件的方式为 BlackFruit-UI 主题提供可配置能力,支持设置导航、页脚、站点信息、SEO、首页轮播、友情链接、荣誉资质、反馈类型以及右侧浮窗,并提供 `/console/v1/theme/config` 接口与前端联动。 ## 功能 -- **图片上传**: 插件自带独立的上传接口 `POST /{DIR_ADMIN}/v1/upload`,支持jpg、png、gif、webp、svg等格式,最大10MB -- 后台界面(`template/admin/index.html`)通过表单 + JSON 的方式维护主题参数: - - SEO、站点基础信息(企业名称、电话、备案、协议链接、产品链接等); - - 首页轮播 Banner(支持图片上传); - - 友情链接(friendly_link); - - 企业荣誉(honor,支持图片上传); - - 反馈类型(feedback_type); - - 右侧浮窗(side / side_floating_window,支持图标上传); - - 复杂导航结构(header_nav/footer_nav)可在"高级配置 (JSON)"中维护,子菜单支持图标上传。 -- 接口 `GET/POST /{DIR_ADMIN}/v1/theme/config` 提供配置读取与保存; -- 前台接口 `GET /console/v1/theme/config` 输出与 `/console/v1/common` 同结构的数据,BlackFruit-UI 可以直接接入; +- **图片上传**: 依赖业务系统的全局上传接口 `/{DIR_ADMIN}/v1/upload` 和 `/console/v1/upload`,与官方示例插件保持一致 +- 后台界面(`template/admin/index.html`)通过表单 + JSON 的方式维护主题参数: + - SEO、站点基础信息(企业名称、电话、备案、协议链接、产品链接等); + - 首页轮播 Banner(支持图片上传); + - 友情链接(friendly_link); + - 企业荣誉(honor,支持图片上传); + - 反馈类型(feedback_type); + - 右侧浮窗(side / side_floating_window,支持图标上传); + - 复杂导航结构(header_nav/footer_nav)可在"高级配置 (JSON)"中维护,子菜单支持图标上传。 +- 接口 `GET/POST /{DIR_ADMIN}/v1/theme/config` 提供配置读取与保存; +- 前台接口 `GET /console/v1/theme/config` 输出与 `/console/v1/common` 同结构的数据,BlackFruit-UI 可以直接接入; - 插件安装时创建 `addon_theme_configurator` 表并写入默认配置。 ## 目录 diff --git a/plugins/addon/theme_configurator/controller/UploadController.php b/plugins/addon/theme_configurator/controller/UploadController.php deleted file mode 100644 index 7a062ab..0000000 --- a/plugins/addon/theme_configurator/controller/UploadController.php +++ /dev/null @@ -1,101 +0,0 @@ -request->file('file'); - - if (!$file) { - return json([ - 'status' => 400, - 'msg' => lang_plugins('upload_no_file'), - ]); - } - - // 验证文件类型和大小 - $fileExt = strtolower($file->extension()); - $fileSize = $file->getSize(); - - $allowedExts = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg']; - $maxSize = 10 * 1024 * 1024; // 10MB - - if (!in_array($fileExt, $allowedExts)) { - return json([ - 'status' => 400, - 'msg' => lang_plugins('upload_validate_failed') . ': ' . '仅支持 jpg, jpeg, png, gif, webp, svg 格式', - ]); - } - - if ($fileSize > $maxSize) { - return json([ - 'status' => 400, - 'msg' => lang_plugins('upload_validate_failed') . ': ' . '文件大小不能超过 10MB', - ]); - } - - // 构建保存路径 - $uploadPath = root_path('public') . 'upload' . DIRECTORY_SEPARATOR . 'theme'; - $dateDir = date('Ymd'); - $savePath = $uploadPath . DIRECTORY_SEPARATOR . $dateDir; - - // 创建目录 - if (!is_dir($savePath)) { - if (!mkdir($savePath, 0755, true)) { - return json([ - 'status' => 400, - 'msg' => lang_plugins('upload_save_failed') . ': 无法创建上传目录', - ]); - } - } - - // 生成唯一文件名 - $fileName = md5(uniqid() . microtime()) . '.' . $fileExt; - $fullPath = $savePath . DIRECTORY_SEPARATOR . $fileName; - - // 移动文件 - if (!$file->move($savePath, $fileName)) { - return json([ - 'status' => 400, - 'msg' => lang_plugins('upload_save_failed'), - ]); - } - - // 构建URL路径 - $saveName = 'theme/' . $dateDir . '/' . $fileName; - $url = '/upload/' . $saveName; - - return json([ - 'status' => 200, - 'msg' => lang_plugins('upload_success'), - 'data' => [ - 'save_name' => $saveName, - 'url' => $url, - 'image_url' => $url, - ], - ]); - - } catch (\Exception $e) { - return json([ - 'status' => 500, - 'msg' => lang_plugins('upload_failed') . ': ' . $e->getMessage(), - ]); - } - } -} diff --git a/plugins/addon/theme_configurator/route.php b/plugins/addon/theme_configurator/route.php index 42569b0..6b9fa34 100644 --- a/plugins/addon/theme_configurator/route.php +++ b/plugins/addon/theme_configurator/route.php @@ -1,7 +1,7 @@ append([ @@ -12,16 +12,9 @@ Route::group('console/v1', function () { })->middleware(\app\http\middleware\ParamFilter::class); // 后台配置接口 +// 注意:上传功能使用业务系统的全局上传接口 /{DIR_ADMIN}/v1/upload +// 不在插件内实现,参考官方示例插件 idcsmart_ticket 的做法 Route::group(DIR_ADMIN . '/v1', function () { - // 文件上传接口 - Route::post('upload', "\\addon\\theme_configurator\\controller\\UploadController@upload") - ->append([ - '_plugin' => 'theme_configurator', - '_controller' => 'upload', - '_action' => 'upload', - ]) - ->middleware(\app\http\middleware\CheckAdmin::class); - Route::get('theme/config', "\\addon\\theme_configurator\\controller\\ThemeController@config") ->append([ '_plugin' => 'theme_configurator',