Skip to content

Commit

Permalink
feat(admin): 利用規約管理
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaiyuxin103 committed Dec 17, 2024
1 parent c8356e1 commit acb0716
Show file tree
Hide file tree
Showing 18 changed files with 509 additions and 0 deletions.
36 changes: 36 additions & 0 deletions _ide_helper_models.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,42 @@ class IdeHelperTeam {}
class IdeHelperTeamInvitation {}
}

namespace App\Models{
/**
*
*
* @property int $id
* @property string $name 名称
* @property string|null $slug 标识
* @property string|null $description 描述
* @property string $content 内容
* @property bool $state 状态
* @property int $sort 排序
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property \Illuminate\Support\Carbon|null $deleted_at
* @method static \Illuminate\Database\Eloquent\Builder|Term newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Term newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Term onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|Term query()
* @method static \Illuminate\Database\Eloquent\Builder|Term whereContent($value)
* @method static \Illuminate\Database\Eloquent\Builder|Term whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Term whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Term whereDescription($value)
* @method static \Illuminate\Database\Eloquent\Builder|Term whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Term whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|Term whereSlug($value)
* @method static \Illuminate\Database\Eloquent\Builder|Term whereSort($value)
* @method static \Illuminate\Database\Eloquent\Builder|Term whereState($value)
* @method static \Illuminate\Database\Eloquent\Builder|Term whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Term withTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|Term withoutTrashed()
* @mixin \Eloquent
*/
#[\AllowDynamicProperties]
class IdeHelperTerm {}
}

namespace App\Models{
/**
*
Expand Down
192 changes: 192 additions & 0 deletions app/Filament/Resources/TermResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources;

use AmidEsfahani\FilamentTinyEditor\TinyEditor;
use App\Filament\Resources\TermResource\Pages;
use App\Models\Privacy;
use App\Models\Term;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Support\Enums\IconPosition;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Support\Str;

class TermResource extends Resource
{
protected static ?string $model = Term::class;

protected static ?string $navigationIcon = 'heroicon-o-queue-list';

protected static ?int $navigationSort = 8;

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

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

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

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

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->maxLength(255)
->reactive()
->afterStateUpdated(fn ($state, callable $set) => $set('slug', Str::slug($state)))
->label(trans('fields.name')),
Forms\Components\TextInput::make('description')
->maxLength(255)
->label(trans('fields.description')),
Forms\Components\TextInput::make('slug')
->readOnly()
->required()
->maxLength(255)
->unique(Privacy::class, 'slug', fn ($record) => $record)
->label(trans('fields.slug')),
TinyEditor::make('content')
->required()
->columnSpanFull()
->fileAttachmentsDisk(config('filament.default_filesystem_disk'))
->fileAttachmentsDirectory('privacies')
->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')
->content(fn (?Term $record): string => $record?->created_at?->diffForHumans() ?? '-')
->label(trans('fields.created_at')),
Forms\Components\Placeholder::make('updated_at')
->content(fn (?Term $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(isIndividual: true)
->label(trans('fields.name')),
Tables\Columns\TextColumn::make('description')
->searchable(isIndividual: true)
->label(trans('fields.description')),
Tables\Columns\TextColumn::make('slug')
->searchable(isIndividual: true)
->copyable()
->icon('heroicon-o-clipboard-document')
->iconPosition(IconPosition::After)
->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(Term::pluck('id', 'id'))
->searchable()
->label(trans('fields.id')),
Tables\Filters\TernaryFilter::make('state')
->label(trans('fields.state')),
Tables\Filters\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 getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListTerms::route('/'),
'create' => Pages\CreateTerm::route('/create'),
'view' => Pages\ViewTerm::route('/{record}'),
'edit' => Pages\EditTerm::route('/{record}/edit'),
];
}

public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}
}
18 changes: 18 additions & 0 deletions app/Filament/Resources/TermResource/Pages/CreateTerm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\TermResource\Pages;

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

class CreateTerm extends CreateRecord
{
protected static string $resource = TermResource::class;

protected function getRedirectUrl(): string
{
return $this->getResource()::getUrl();
}
}
29 changes: 29 additions & 0 deletions app/Filament/Resources/TermResource/Pages/EditTerm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\TermResource\Pages;

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

class EditTerm extends EditRecord
{
protected static string $resource = TermResource::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/TermResource/Pages/ListTerms.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\TermResource\Pages;

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

class ListTerms extends ListRecords
{
protected static string $resource = TermResource::class;

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

declare(strict_types=1);

namespace App\Filament\Resources\TermResource\Pages;

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

class ViewTerm extends ViewRecord
{
protected static string $resource = TermResource::class;

protected function getHeaderActions(): array
{
return [
Actions\EditAction::make(),
];
}
}
37 changes: 37 additions & 0 deletions app/Models/Term.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace App\Models;

/**
* @mixin IdeHelperTerm
*/
class Term extends Model
{
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'name',
'slug',
'content',
'state',
'sort',
'description',
];

/**
* Get the attributes that should be cast.
*
* @return array<string,string>
*/
protected function casts(): array
{
return [
'state' => 'boolean',
];
}
}
Loading

0 comments on commit acb0716

Please sign in to comment.