113 lines
4.6 KiB
PHP
113 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages;
|
|
|
|
use App\Models\Setting;
|
|
use Filament\Actions\Action;
|
|
use Filament\Schemas\Components\Section;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Components\Toggle;
|
|
use Filament\Forms\Concerns\InteractsWithForms;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Pages\Page;
|
|
use Filament\Schemas\Schema;
|
|
|
|
class BlogSettings extends Page
|
|
{
|
|
use InteractsWithForms;
|
|
|
|
protected static \UnitEnum|string|null $navigationGroup = '管理';
|
|
|
|
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-cog-6-tooth';
|
|
|
|
protected static ?string $navigationLabel = '博客设置';
|
|
|
|
protected string $view = 'filament.pages.blog-settings';
|
|
|
|
public array $data = [];
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->form->fill([
|
|
'site_name' => Setting::get('site_name', config('blog.name')),
|
|
'site_description' => Setting::get('site_description', config('blog.description')),
|
|
'site_icp' => Setting::get('site_icp', config('blog.icp')),
|
|
'active_theme' => Setting::get('active_theme', config('themes.default')),
|
|
'per_page' => Setting::get('per_page', config('blog.per_page')),
|
|
'comment_audit' => Setting::get('comment_audit', '0'),
|
|
'comment_min_len' => Setting::get('comment_min_len', config('blog.comment_min_len')),
|
|
'comment_max_len' => Setting::get('comment_max_len', config('blog.comment_max_len')),
|
|
'comment_post_space' => Setting::get('comment_post_space', config('blog.comment_post_space')),
|
|
'rss_num' => Setting::get('rss_num', config('blog.rss_num')),
|
|
'seo_default_keywords' => Setting::get('seo_default_keywords', ''),
|
|
'seo_default_description' => Setting::get('seo_default_description', ''),
|
|
'site_closed' => Setting::get('site_closed', '0'),
|
|
'site_closed_note' => Setting::get('site_closed_note', ''),
|
|
]);
|
|
}
|
|
|
|
public function form(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->components([
|
|
Section::make('站点信息')
|
|
->schema([
|
|
TextInput::make('site_name')->label('站点名称')->required(),
|
|
TextInput::make('site_description')->label('站点描述')->columnSpanFull(),
|
|
TextInput::make('site_icp')->label('ICP 备案号'),
|
|
]),
|
|
Section::make('主题')
|
|
->schema([
|
|
Select::make('active_theme')
|
|
->label('激活主题')
|
|
->options(collect(app(\App\Blog\Support\ThemeManager::class)->all())->pluck('title', 'name')),
|
|
]),
|
|
Section::make('列表与订阅')
|
|
->schema([
|
|
TextInput::make('per_page')->label('每页文章数')->numeric(),
|
|
TextInput::make('rss_num')->label('RSS 文章数')->numeric(),
|
|
]),
|
|
Section::make('评论')
|
|
->columns(2)
|
|
->schema([
|
|
Toggle::make('comment_audit')->label('新评论需审核')->default(false),
|
|
TextInput::make('comment_min_len')->label('评论最短字数')->numeric(),
|
|
TextInput::make('comment_max_len')->label('评论最长字数')->numeric(),
|
|
TextInput::make('comment_post_space')->label('评论间隔(秒)')->numeric(),
|
|
]),
|
|
Section::make('SEO 默认值')
|
|
->schema([
|
|
TextInput::make('seo_default_keywords')->label('默认关键词'),
|
|
TextInput::make('seo_default_description')->label('默认描述')->columnSpanFull(),
|
|
]),
|
|
Section::make('维护')
|
|
->schema([
|
|
Toggle::make('site_closed')->label('关闭站点')->default(false),
|
|
TextInput::make('site_closed_note')->label('关闭说明'),
|
|
]),
|
|
])
|
|
->statePath('data');
|
|
}
|
|
|
|
public function save(): void
|
|
{
|
|
$data = $this->form->getState();
|
|
|
|
foreach ($data as $key => $value) {
|
|
Setting::set($key, is_bool($value) ? (string) (int) $value : (string) $value);
|
|
}
|
|
|
|
Notification::make()->title('设置已保存')->success()->send();
|
|
}
|
|
|
|
protected function getFormActions(): array
|
|
{
|
|
return [
|
|
Action::make('save')
|
|
->label('保存设置')
|
|
->submit('save'),
|
|
];
|
|
}
|
|
}
|