feat: post cover filter + admin AI cover action, restyle page-cache admin
- 抽 CoverGenerator 服务(covers:generate 与后台共用),内部强制同步产出 card 转换 - 文章列表:新增封面状态图标列、「有/无封面/完全无图」筛选、行内「生成封面」AI 操作 - 页面缓存:统计改为原生 StatsOverviewWidget(缓存页数/总大小/命中率/时长), 缓存明细表重排(表头、悬停、URL 截断、图标删除按钮、空状态)
This commit is contained in:
@@ -4,17 +4,21 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Posts\Tables;
|
||||
|
||||
use App\Blog\Services\CoverGenerator;
|
||||
use App\Models\Post;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Enums\FiltersLayout;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class PostsTable
|
||||
{
|
||||
@@ -46,6 +50,16 @@ class PostsTable
|
||||
'draft' => 'warning',
|
||||
default => 'gray',
|
||||
}),
|
||||
IconColumn::make('cover_state')
|
||||
->label('封面')
|
||||
->boolean()
|
||||
->trueIcon('heroicon-o-photo')
|
||||
->falseIcon('heroicon-o-x-mark')
|
||||
->trueColor('success')
|
||||
->falseColor('gray')
|
||||
->state(fn (Post $record): bool => $record->coverImageUrl() !== null)
|
||||
->tooltip(fn (Post $record): string => $record->coverImageUrl() !== null ? '已有封面' : '无封面,可用「生成封面」AI 补一张')
|
||||
->toggleable(),
|
||||
TextColumn::make('sticky_level')
|
||||
->label('置顶')
|
||||
->badge()
|
||||
@@ -90,10 +104,50 @@ class PostsTable
|
||||
SelectFilter::make('sticky_level')
|
||||
->label('置顶')
|
||||
->options(Post::stickyLevelOptions()),
|
||||
SelectFilter::make('cover_status')
|
||||
->label('封面')
|
||||
->options([
|
||||
'with' => '有封面',
|
||||
'without' => '无封面',
|
||||
'no_image' => '完全无图(正文/附件也没有)',
|
||||
])
|
||||
->query(fn (Builder $query, array $data): Builder => match ($data['value'] ?? null) {
|
||||
'with' => $query->where(fn (Builder $q) => $q
|
||||
->whereNotNull('cover_media_id')
|
||||
->orWhereHas('media', fn (Builder $m) => $m->where('collection_name', 'cover'))),
|
||||
'without' => $query
|
||||
->whereNull('cover_media_id')
|
||||
->whereDoesntHave('media', fn (Builder $m) => $m->where('collection_name', 'cover')),
|
||||
'no_image' => $query
|
||||
->whereNull('cover_media_id')
|
||||
->whereDoesntHave('media', fn (Builder $m) => $m->where(fn (Builder $x) => $x
|
||||
->where('collection_name', 'cover')
|
||||
->orWhere(fn (Builder $y) => $y
|
||||
->where('collection_name', 'attachments')
|
||||
->where('mime_type', 'like', 'image/%'))))
|
||||
->where('content', 'not like', '%<img%')
|
||||
->where('content', 'not like', '%](http%'),
|
||||
default => $query,
|
||||
}),
|
||||
], FiltersLayout::AboveContent)
|
||||
->filtersFormColumns(3)
|
||||
->filtersFormWidth(Width::ThreeExtraLarge)
|
||||
->recordActions([
|
||||
Action::make('generateCover')
|
||||
->label('生成封面')
|
||||
->icon('heroicon-o-photo')
|
||||
->color('gray')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('AI 生成封面')
|
||||
->modalDescription(fn (Post $record): string => "根据《{$record->title}》的标题和摘要生成一张封面图,约需 20 秒,请耐心等待。")
|
||||
->action(function (Post $record): void {
|
||||
try {
|
||||
app(CoverGenerator::class)->generateFor($record);
|
||||
Notification::make()->title('封面已生成')->success()->send();
|
||||
} catch (\Throwable $e) {
|
||||
Notification::make()->title('生成失败')->body($e->getMessage())->danger()->send();
|
||||
}
|
||||
}),
|
||||
Action::make('preview')
|
||||
->label('预览')
|
||||
->url(fn (Post $record): string => $record->url)
|
||||
|
||||
Reference in New Issue
Block a user