feat: 为主题配置器插件新增文件上传功能及相关路由配置
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -3,14 +3,15 @@
|
||||
此插件演示如何通过后台插件的方式为 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;
|
||||
- 首页轮播 Banner(支持图片上传);
|
||||
- 友情链接(friendly_link);
|
||||
- 企业荣誉(honor);
|
||||
- 企业荣誉(honor,支持图片上传);
|
||||
- 反馈类型(feedback_type);
|
||||
- 右侧浮窗(side / side_floating_window);
|
||||
- 复杂导航结构(header_nav/footer_nav)可在"高级配置 (JSON)"中维护。
|
||||
- 右侧浮窗(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` 表并写入默认配置。
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
namespace addon\theme_configurator\controller;
|
||||
|
||||
use app\event\controller\PluginAdminBaseController;
|
||||
use think\Response;
|
||||
use think\facade\Filesystem;
|
||||
|
||||
/**
|
||||
* 后台上传控制器
|
||||
*
|
||||
* 为主题配置插件提供图片上传功能
|
||||
*/
|
||||
class UploadController extends PluginAdminBaseController
|
||||
{
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function upload(): Response
|
||||
{
|
||||
try {
|
||||
// 获取上传的文件
|
||||
$file = $this->request->file('file');
|
||||
|
||||
if (!$file) {
|
||||
return json([
|
||||
'status' => 400,
|
||||
'msg' => lang_plugins('upload_no_file'),
|
||||
]);
|
||||
}
|
||||
|
||||
// 验证文件
|
||||
$validate = [
|
||||
'size' => 10 * 1024 * 1024, // 10MB
|
||||
'ext' => 'jpg,jpeg,png,gif,webp,svg',
|
||||
];
|
||||
|
||||
try {
|
||||
validate($validate)->check(['file' => $file]);
|
||||
} catch (\Exception $e) {
|
||||
return json([
|
||||
'status' => 400,
|
||||
'msg' => lang_plugins('upload_validate_failed') . ': ' . $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
|
||||
// 上传到本地服务器
|
||||
$saveName = Filesystem::disk('public')->putFile('theme', $file);
|
||||
|
||||
if (!$saveName) {
|
||||
return json([
|
||||
'status' => 400,
|
||||
'msg' => lang_plugins('upload_save_failed'),
|
||||
]);
|
||||
}
|
||||
|
||||
// 构建完整的URL路径
|
||||
$url = '/upload/' . str_replace('\\', '/', $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(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,17 @@
|
||||
<?php
|
||||
return [
|
||||
'theme_configurator_success' => '请求成功',
|
||||
'theme_configurator_save_success' => '主题配置保存成功',
|
||||
'theme_configurator_save_success' => '配置已保存',
|
||||
'theme_configurator_error' => '请求失败',
|
||||
'theme_configurator_install_success' => '主题配置插件安装成功',
|
||||
'theme_configurator_uninstall_success' => '主题配置插件卸载成功',
|
||||
'nav_plugin_addon_theme_configurator' => '主题配置',
|
||||
'auth_plugin_addon_theme_configurator' => '主题控制',
|
||||
'auth_plugin_addon_theme_configurator_save' => '保存主题配置',
|
||||
// 上传相关
|
||||
'upload_success' => '上传成功',
|
||||
'upload_failed' => '上传失败',
|
||||
'upload_no_file' => '请选择要上传的文件',
|
||||
'upload_validate_failed' => '文件验证失败',
|
||||
'upload_save_failed' => '文件保存失败',
|
||||
];
|
||||
|
||||
@@ -13,6 +13,15 @@ Route::group('console/v1', function () {
|
||||
|
||||
// 后台配置接口
|
||||
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',
|
||||
|
||||
Reference in New Issue
Block a user