Skip to content

Commit

Permalink
feat(admin): 关于我们管理
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaiyuxin103 committed Nov 25, 2024
1 parent 47bdbe3 commit 836d9cc
Show file tree
Hide file tree
Showing 19 changed files with 540 additions and 0 deletions.
39 changes: 39 additions & 0 deletions _ide_helper_models.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,43 @@
*/


namespace App\Models{
/**
*
*
* @property int $id
* @property string $name
* @property string|null $slug
* @property string $content
* @property bool $state
* @property int $sort
* @property int $user_id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property \Illuminate\Support\Carbon|null $deleted_at
* @property-read \App\Models\User|null $user
* @method static \Illuminate\Database\Eloquent\Builder|About newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|About newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|About onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|About query()
* @method static \Illuminate\Database\Eloquent\Builder|About whereContent($value)
* @method static \Illuminate\Database\Eloquent\Builder|About whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|About whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|About whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|About whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|About whereSlug($value)
* @method static \Illuminate\Database\Eloquent\Builder|About whereSort($value)
* @method static \Illuminate\Database\Eloquent\Builder|About whereState($value)
* @method static \Illuminate\Database\Eloquent\Builder|About whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|About whereUserId($value)
* @method static \Illuminate\Database\Eloquent\Builder|About withTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|About withoutTrashed()
* @mixin \Eloquent
*/
#[\AllowDynamicProperties]
class IdeHelperAbout {}
}

namespace App\Models{
/**
*
Expand Down Expand Up @@ -273,6 +310,8 @@ class IdeHelperTeamInvitation {}
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property \Illuminate\Support\Carbon|null $deleted_at
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\About> $abouts
* @property-read int|null $abouts_count
* @property-read mixed $alias
* @property-read \App\Models\Team|null $currentTeam
* @property-read mixed $format_gender
Expand Down
211 changes: 211 additions & 0 deletions app/Filament/Resources/AboutResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources;

use AmidEsfahani\FilamentTinyEditor\TinyEditor;
use App\Filament\Resources\AboutResource\Pages;
use App\Models\About;
use App\Models\User;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Filters\TrashedFilter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Support\Str;

class AboutResource extends Resource
{
protected static ?string $model = About::class;

protected static ?string $slug = 'abouts';

protected static ?string $navigationIcon = 'heroicon-o-information-circle';

protected static ?int $navigationSort = 2;

public static function getLabel(): ?string
{
return trans('labels.abouts');
}

public static function getBreadcrumb(): string
{
return trans('breadcrumbs.abouts');
}

public static function getNavigationLabel(): string
{
return trans('menus.abouts');
}

public static function getNavigationGroup(): ?string
{
return trans('labels.texts');
}

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255)
->reactive()
->afterStateUpdated(fn ($state, callable $set) => $set('slug', Str::slug($state)))
->label(trans('fields.name')),
Forms\Components\TextInput::make('slug')
->readOnly()
->required()
->maxLength(255)
->unique(About::class, 'slug', fn ($record) => $record)
->label(trans('fields.slug')),
TinyEditor::make('content')
->columnSpanFull()
->fileAttachmentsDisk(config('filament.default_filesystem_disk'))
->fileAttachmentsDirectory('landings')
->required()
->label(trans('fields.content')),
Forms\Components\Section::make()
->columns()
->schema([
Forms\Components\Toggle::make('state')
->required()
->default(true)
->label(trans('fields.state')),
Forms\Components\TextInput::make('sort')
->required()
->numeric()
->default(0)
->label(trans('fields.sort')),
]),
Forms\Components\Placeholder::make('created_at')
->label('Created Date')
->content(fn (?About $record): string => $record?->created_at?->diffForHumans() ?? '-')
->label(trans('fields.created_at')),
Forms\Components\Placeholder::make('updated_at')
->label('Last Modified Date')
->content(fn (?About $record): string => $record?->updated_at?->diffForHumans() ?? '-')
->label(trans('fields.updated_at')),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('index')
->rowIndex()
->toggleable(isToggledHiddenByDefault: true)
->label(trans('fields.index')),
Tables\Columns\TextColumn::make('id')
->sortable()
->searchable()
->toggleable(isToggledHiddenByDefault: true)
->label(trans('fields.id')),
Tables\Columns\TextColumn::make('name')
->searchable()
->label(trans('fields.name')),
Tables\Columns\TextColumn::make('slug')
->searchable()
->label(trans('fields.slug')),
Tables\Columns\IconColumn::make('state')
->boolean()
->label(trans('fields.state')),
Tables\Columns\TextColumn::make('sort')
->numeric()
->sortable()
->label(trans('fields.sort')),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true)
->label(trans('fields.created_at')),
Tables\Columns\TextColumn::make('updated_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true)
->label(trans('fields.updated_at')),
Tables\Columns\TextColumn::make('deleted_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true)
->label(trans('fields.deleted_at')),
])
->filters([
Tables\Filters\SelectFilter::make('id')
->options(About::pluck('id', 'id'))
->searchable()
->label(trans('fields.id')),
Tables\Filters\SelectFilter::make('user_id')
->options(User::pluck('id', 'id'))
->searchable()
->label(trans('fields.user')),
Tables\Filters\TernaryFilter::make('state')
->label(trans('fields.state')),
TrashedFilter::make(),
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
Tables\Actions\RestoreAction::make(),
Tables\Actions\ForceDeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
]),
]);
}

public static function getPages(): array
{
return [
'index' => Pages\ListAbouts::route('/'),
'create' => Pages\CreateAbout::route('/create'),
'view' => Pages\ViewAbout::route('/{record}'),
'edit' => Pages\EditAbout::route('/{record}/edit'),
];
}

public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}

public static function getGlobalSearchEloquentQuery(): Builder
{
return parent::getGlobalSearchEloquentQuery()->with(['user']);
}

public static function getGloballySearchableAttributes(): array
{
return ['name', 'slug', 'user.name'];
}

/**
* @param Model&About $record
* @return array|string[]
*/
public static function getGlobalSearchResultDetails(Model $record): array
{
$details = [];

if ($record->user) {
$details['User'] = $record->user->name;
}

return $details;
}
}
30 changes: 30 additions & 0 deletions app/Filament/Resources/AboutResource/Pages/CreateAbout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\AboutResource\Pages;

use App\Filament\Resources\AboutResource;
use Filament\Resources\Pages\CreateRecord;

class CreateAbout extends CreateRecord
{
protected static string $resource = AboutResource::class;

protected function getHeaderActions(): array
{
return [];
}

protected function getRedirectUrl(): string
{
return $this->getResource()::getUrl();
}

protected function mutateFormDataBeforeCreate(array $data): array
{
data_set($data, 'user_id', auth()->id());

return $data;
}
}
29 changes: 29 additions & 0 deletions app/Filament/Resources/AboutResource/Pages/EditAbout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\AboutResource\Pages;

use App\Filament\Resources\AboutResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;

class EditAbout extends EditRecord
{
protected static string $resource = AboutResource::class;

protected function getHeaderActions(): array
{
return [
Actions\ViewAction::make(),
Actions\DeleteAction::make(),
Actions\ForceDeleteAction::make(),
Actions\RestoreAction::make(),
];
}

protected function getRedirectUrl(): string
{
return $this->getResource()::getUrl('view', ['record' => $this->getRecord()]);
}
}
21 changes: 21 additions & 0 deletions app/Filament/Resources/AboutResource/Pages/ListAbouts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\AboutResource\Pages;

use App\Filament\Resources\AboutResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;

class ListAbouts extends ListRecords
{
protected static string $resource = AboutResource::class;

protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}
21 changes: 21 additions & 0 deletions app/Filament/Resources/AboutResource/Pages/ViewAbout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\AboutResource\Pages;

use App\Filament\Resources\AboutResource;
use Filament\Actions;
use Filament\Resources\Pages\ViewRecord;

class ViewAbout extends ViewRecord
{
protected static string $resource = AboutResource::class;

protected function getHeaderActions(): array
{
return [
Actions\EditAction::make(),
];
}
}
Loading

0 comments on commit 836d9cc

Please sign in to comment.