mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 09:39:10 +08:00
update: custom theme
This commit is contained in:
parent
32bb9fccb5
commit
a0ebcb948b
47
app/Http/Controllers/Admin/ThemeController.php
Normal file
47
app/Http/Controllers/Admin/ThemeController.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Support\Facades\File;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class ThemeController extends Controller
|
||||||
|
{
|
||||||
|
public function getThemes()
|
||||||
|
{
|
||||||
|
$path = public_path('theme/');
|
||||||
|
$files = array_map(function ($item) use ($path) {
|
||||||
|
return str_replace($path, '', $item);
|
||||||
|
}, glob($path . '*'));
|
||||||
|
$themeConfigs = [];
|
||||||
|
foreach ($files as $file) {
|
||||||
|
$themeConfigFile = $path . "{$file}/config.php";
|
||||||
|
if (!File::exists($themeConfigFile)) continue;
|
||||||
|
$themeConfig = include($themeConfigFile);
|
||||||
|
if (!isset($themeConfig['configs']) || !is_array($themeConfig)) continue;
|
||||||
|
$themeConfigs[$file] = $themeConfig;
|
||||||
|
}
|
||||||
|
return response([
|
||||||
|
'data' => $themeConfigs
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function saveThemeConfig(Request $request)
|
||||||
|
{
|
||||||
|
$path = public_path('theme/');
|
||||||
|
$files = array_map(function ($item) use ($path) {
|
||||||
|
return str_replace($path, '', $item);
|
||||||
|
}, glob($path . '*'));
|
||||||
|
$payload = $request->validate([
|
||||||
|
'name' => 'required|in:' . join(',', $files),
|
||||||
|
'configs' => 'required|array'
|
||||||
|
]);
|
||||||
|
$themeConfigFile = public_path("theme/{$payload['name']}/config.php");
|
||||||
|
if (!File::exists($themeConfigFile)) abort(500, '主题不存在');
|
||||||
|
$themeConfig = include($themeConfigFile);
|
||||||
|
$validateFields = array_column($themeConfig['configs'], 'field_name');
|
||||||
|
dd($validateFields);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -114,6 +114,9 @@ class AdminRoute
|
|||||||
$router->post('/payment/show', 'Admin\\PaymentController@show');
|
$router->post('/payment/show', 'Admin\\PaymentController@show');
|
||||||
// System
|
// System
|
||||||
$router->get ('/system/getStatus', 'Admin\\SystemController@getStatus');
|
$router->get ('/system/getStatus', 'Admin\\SystemController@getStatus');
|
||||||
|
// Theme
|
||||||
|
$router->get ('/theme/getThemes', 'Admin\\ThemeController@getThemes');
|
||||||
|
$router->post('/theme/saveThemeConfig', 'Admin\\ThemeController@saveThemeConfig');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
public/theme/v2board/config.php
Normal file
17
public/theme/v2board/config.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'name' => 'V2board',
|
||||||
|
'description' => '这是一个描述',
|
||||||
|
'version' => '1.5.6',
|
||||||
|
'configs' => [
|
||||||
|
[
|
||||||
|
'field_name' => 'theme', // 字段名
|
||||||
|
'description' => '这是一个字段主题', // 描述
|
||||||
|
'field_type' => 'select', // 字段类型: select,input,switch
|
||||||
|
'select_options' => [ // [filed_type]_options
|
||||||
|
'奶绿'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
Loading…
Reference in New Issue
Block a user