完善功能
This commit is contained in:
@@ -11,6 +11,7 @@ use Filament\Forms\Components\Toggle;
|
||||
use Filament\Forms\Concerns\InteractsWithForms;
|
||||
use Filament\Forms\Contracts\HasForms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
|
||||
class SiteSettings extends Page implements HasForms
|
||||
@@ -51,7 +52,7 @@ class SiteSettings extends Page implements HasForms
|
||||
Section::make('首页配置')
|
||||
->schema([
|
||||
TextInput::make('home_featured_limit')->label('热门推荐数量')->numeric()->required(),
|
||||
TextInput::make('home_new_limit')->label('新加产品数量')->numeric()->required(),
|
||||
TextInput::make('home_new_limit')->label('新增产品数量')->numeric()->required(),
|
||||
TextInput::make('home_category_limit')->label('分类展示数量')->numeric()->required(),
|
||||
])->columns(3),
|
||||
Section::make('列表配置')
|
||||
@@ -96,7 +97,10 @@ class SiteSettings extends Page implements HasForms
|
||||
SiteSetting::updateOrCreate(['key' => $key], ['value' => $value]);
|
||||
}
|
||||
|
||||
$this->notify('success', '保存成功');
|
||||
Notification::make()
|
||||
->title('保存成功')
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
|
||||
private function getSettings(): array
|
||||
|
||||
165
web10/app/Filament/Resources/AdResource.php
Normal file
165
web10/app/Filament/Resources/AdResource.php
Normal file
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\AdResource\Pages;
|
||||
use App\Models\Ad;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class AdResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Ad::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-megaphone';
|
||||
protected static ?string $navigationLabel = '广告';
|
||||
protected static ?string $navigationGroup = '运营管理';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Section::make('基础信息')
|
||||
->schema([
|
||||
Select::make('ad_slot_id')
|
||||
->label('投放位')
|
||||
->relationship('adSlot', 'name')
|
||||
->searchable()
|
||||
->preload()
|
||||
->required(),
|
||||
TextInput::make('title')
|
||||
->label('标题')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
FileUpload::make('image')
|
||||
->label('图片')
|
||||
->disk('public')
|
||||
->directory('ads')
|
||||
->image()
|
||||
->imagePreviewHeight('120')
|
||||
->nullable(),
|
||||
Textarea::make('description')
|
||||
->label('描述')
|
||||
->rows(3)
|
||||
->nullable(),
|
||||
])->columns(2),
|
||||
Section::make('链接与关联')
|
||||
->schema([
|
||||
Select::make('product_id')
|
||||
->label('关联产品')
|
||||
->relationship('product', 'name')
|
||||
->searchable()
|
||||
->preload()
|
||||
->nullable()
|
||||
->rules(['required_without:link_url']),
|
||||
TextInput::make('link_url')
|
||||
->label('外部链接')
|
||||
->helperText('关联产品与外部链接二选一')
|
||||
->maxLength(255)
|
||||
->url()
|
||||
->nullable()
|
||||
->rules(['required_without:product_id']),
|
||||
Select::make('link_target')
|
||||
->label('打开方式')
|
||||
->options([
|
||||
'_blank' => '新窗口',
|
||||
'_self' => '当前窗口',
|
||||
])
|
||||
->default('_blank'),
|
||||
])->columns(2),
|
||||
Section::make('投放与状态')
|
||||
->schema([
|
||||
DateTimePicker::make('starts_at')
|
||||
->label('开始时间')
|
||||
->nullable(),
|
||||
DateTimePicker::make('ends_at')
|
||||
->label('结束时间')
|
||||
->nullable(),
|
||||
Toggle::make('is_active')
|
||||
->label('启用')
|
||||
->default(true),
|
||||
TextInput::make('sort')
|
||||
->label('排序')
|
||||
->numeric()
|
||||
->default(0),
|
||||
])->columns(2),
|
||||
Section::make('统计')
|
||||
->schema([
|
||||
TextInput::make('view_count')
|
||||
->label('展示量')
|
||||
->numeric()
|
||||
->disabled()
|
||||
->dehydrated(false),
|
||||
TextInput::make('click_count')
|
||||
->label('点击量')
|
||||
->numeric()
|
||||
->disabled()
|
||||
->dehydrated(false),
|
||||
])->columns(2),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->reorderable('sort')
|
||||
->defaultSort('sort')
|
||||
->columns([
|
||||
TextColumn::make('adSlot.name')->label('投放位')->sortable(),
|
||||
TextColumn::make('title')->label('标题')->searchable(),
|
||||
IconColumn::make('is_active')->label('启用')->boolean(),
|
||||
TextColumn::make('sort')->label('排序')->sortable(),
|
||||
TextColumn::make('view_count')->label('展示')->sortable(),
|
||||
TextColumn::make('click_count')->label('点击')->sortable(),
|
||||
TextColumn::make('starts_at')->label('开始时间')->dateTime(),
|
||||
TextColumn::make('ends_at')->label('结束时间')->dateTime(),
|
||||
TextColumn::make('created_at')->label('创建时间')->dateTime(),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\SelectFilter::make('ad_slot_id')
|
||||
->label('投放位')
|
||||
->relationship('adSlot', 'name'),
|
||||
Tables\Filters\TernaryFilter::make('is_active')
|
||||
->label('启用'),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->emptyStateActions([
|
||||
Tables\Actions\CreateAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListAds::route('/'),
|
||||
'create' => Pages\CreateAd::route('/create'),
|
||||
'edit' => Pages\EditAd::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
11
web10/app/Filament/Resources/AdResource/Pages/CreateAd.php
Normal file
11
web10/app/Filament/Resources/AdResource/Pages/CreateAd.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\AdResource\Pages;
|
||||
|
||||
use App\Filament\Resources\AdResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateAd extends CreateRecord
|
||||
{
|
||||
protected static string $resource = AdResource::class;
|
||||
}
|
||||
11
web10/app/Filament/Resources/AdResource/Pages/EditAd.php
Normal file
11
web10/app/Filament/Resources/AdResource/Pages/EditAd.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\AdResource\Pages;
|
||||
|
||||
use App\Filament\Resources\AdResource;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditAd extends EditRecord
|
||||
{
|
||||
protected static string $resource = AdResource::class;
|
||||
}
|
||||
11
web10/app/Filament/Resources/AdResource/Pages/ListAds.php
Normal file
11
web10/app/Filament/Resources/AdResource/Pages/ListAds.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\AdResource\Pages;
|
||||
|
||||
use App\Filament\Resources\AdResource;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListAds extends ListRecords
|
||||
{
|
||||
protected static string $resource = AdResource::class;
|
||||
}
|
||||
110
web10/app/Filament/Resources/AdSlotResource.php
Normal file
110
web10/app/Filament/Resources/AdSlotResource.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\AdSlotResource\Pages;
|
||||
use App\Models\AdSlot;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class AdSlotResource extends Resource
|
||||
{
|
||||
protected static ?string $model = AdSlot::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-megaphone';
|
||||
protected static ?string $navigationLabel = '推广位';
|
||||
protected static ?string $navigationGroup = '运营管理';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Section::make('基础信息')
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->label('名称')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
TextInput::make('key')
|
||||
->label('标识键')
|
||||
->helperText('前端模板使用 slotKey 识别')
|
||||
->required()
|
||||
->maxLength(64)
|
||||
->unique(ignoreRecord: true),
|
||||
Textarea::make('description')
|
||||
->label('描述')
|
||||
->rows(2)
|
||||
->nullable(),
|
||||
])->columns(2),
|
||||
Section::make('配置')
|
||||
->schema([
|
||||
Toggle::make('is_active')
|
||||
->label('启用')
|
||||
->default(true),
|
||||
TextInput::make('max_items')
|
||||
->label('最大展示数')
|
||||
->numeric()
|
||||
->default(3),
|
||||
TextInput::make('sort')
|
||||
->label('排序')
|
||||
->numeric()
|
||||
->default(0),
|
||||
])->columns(3),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->reorderable('sort')
|
||||
->defaultSort('sort')
|
||||
->columns([
|
||||
TextColumn::make('name')->label('名称')->searchable()->sortable(),
|
||||
TextColumn::make('key')->label('标识键')->searchable(),
|
||||
IconColumn::make('is_active')->label('启用')->boolean(),
|
||||
TextColumn::make('max_items')->label('最大展示')->sortable(),
|
||||
TextColumn::make('ads_count')->label('广告数量')->counts('ads'),
|
||||
TextColumn::make('sort')->label('排序')->sortable(),
|
||||
TextColumn::make('created_at')->label('创建时间')->dateTime(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->emptyStateActions([
|
||||
Tables\Actions\CreateAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListAdSlots::route('/'),
|
||||
'create' => Pages\CreateAdSlot::route('/create'),
|
||||
'edit' => Pages\EditAdSlot::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\AdSlotResource\Pages;
|
||||
|
||||
use App\Filament\Resources\AdSlotResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateAdSlot extends CreateRecord
|
||||
{
|
||||
protected static string $resource = AdSlotResource::class;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\AdSlotResource\Pages;
|
||||
|
||||
use App\Filament\Resources\AdSlotResource;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditAdSlot extends EditRecord
|
||||
{
|
||||
protected static string $resource = AdSlotResource::class;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\AdSlotResource\Pages;
|
||||
|
||||
use App\Filament\Resources\AdSlotResource;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListAdSlots extends ListRecords
|
||||
{
|
||||
protected static string $resource = AdSlotResource::class;
|
||||
}
|
||||
40
web10/app/Filament/Widgets/OverviewStats.php
Normal file
40
web10/app/Filament/Widgets/OverviewStats.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Ad;
|
||||
use App\Models\Article;
|
||||
use App\Models\Comment;
|
||||
use App\Models\ContentViewLog;
|
||||
use App\Models\Product;
|
||||
use Filament\Widgets\StatsOverviewWidget;
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class OverviewStats extends StatsOverviewWidget
|
||||
{
|
||||
protected function getStats(): array
|
||||
{
|
||||
$today = now()->toDateString();
|
||||
$todayViews = Schema::hasTable('content_view_logs')
|
||||
? ContentViewLog::where('viewed_on', $today)->count()
|
||||
: 0;
|
||||
|
||||
$productClicks = Schema::hasTable('products')
|
||||
? Product::sum('click_count')
|
||||
: 0;
|
||||
|
||||
$adClicks = Schema::hasTable('ads')
|
||||
? Ad::sum('click_count')
|
||||
: 0;
|
||||
|
||||
return [
|
||||
Stat::make('产品总数', Schema::hasTable('products') ? Product::count() : 0),
|
||||
Stat::make('文章总数', Schema::hasTable('articles') ? Article::count() : 0),
|
||||
Stat::make('今日访问', $todayViews),
|
||||
Stat::make('待审评论', Schema::hasTable('comments') ? Comment::where('status', 'pending')->count() : 0),
|
||||
Stat::make('官网点击', $productClicks),
|
||||
Stat::make('推广点击', $adClicks),
|
||||
];
|
||||
}
|
||||
}
|
||||
34
web10/app/Filament/Widgets/TopArticlesWidget.php
Normal file
34
web10/app/Filament/Widgets/TopArticlesWidget.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Article;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Widgets\TableWidget;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class TopArticlesWidget extends TableWidget
|
||||
{
|
||||
protected int | string | array $columnSpan = 'full';
|
||||
|
||||
protected function getTableHeading(): string
|
||||
{
|
||||
return '热门文章';
|
||||
}
|
||||
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return Article::query()
|
||||
->orderByDesc('view_count')
|
||||
->orderByDesc('published_at');
|
||||
}
|
||||
|
||||
protected function getTableColumns(): array
|
||||
{
|
||||
return [
|
||||
TextColumn::make('title')->label('文章')->searchable()->limit(40),
|
||||
TextColumn::make('view_count')->label('浏览')->sortable(),
|
||||
TextColumn::make('published_at')->label('发布时间')->dateTime(),
|
||||
];
|
||||
}
|
||||
}
|
||||
35
web10/app/Filament/Widgets/TopProductsWidget.php
Normal file
35
web10/app/Filament/Widgets/TopProductsWidget.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Product;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Widgets\TableWidget;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class TopProductsWidget extends TableWidget
|
||||
{
|
||||
protected int | string | array $columnSpan = 'full';
|
||||
|
||||
protected function getTableHeading(): string
|
||||
{
|
||||
return '热门产品';
|
||||
}
|
||||
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return Product::query()
|
||||
->orderByDesc('hot_score')
|
||||
->orderByDesc('view_count');
|
||||
}
|
||||
|
||||
protected function getTableColumns(): array
|
||||
{
|
||||
return [
|
||||
TextColumn::make('name')->label('产品')->searchable()->limit(30),
|
||||
TextColumn::make('hot_score')->label('热度')->sortable(),
|
||||
TextColumn::make('view_count')->label('浏览')->sortable(),
|
||||
TextColumn::make('click_count')->label('点击')->sortable(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user