From 2a7d6fd9aa893df0d47fdc951feaea9d9f4cfd89 Mon Sep 17 00:00:00 2001 From: "allen.yan" Date: Tue, 6 May 2025 13:04:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E6=AD=8C=E6=89=8B=E7=8B=80?= =?UTF-8?q?=E6=85=8B=2020250506?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Imports/ArtistDataImport.php | 4 +++- app/Livewire/Admin/ArtistForm.php | 1 + app/Livewire/Admin/ArtistTable.php | 3 +++ app/Models/Artist.php | 1 + .../migrations/2025_04_23_031625_create_artists_table.php | 1 + resources/lang/zh-tw/artists.php | 1 + resources/views/livewire/admin/artist-form.blade.php | 1 + 7 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Imports/ArtistDataImport.php b/app/Imports/ArtistDataImport.php index 3330ba2..0862372 100644 --- a/app/Imports/ArtistDataImport.php +++ b/app/Imports/ArtistDataImport.php @@ -23,6 +23,7 @@ class ArtistDataImport implements ToModel, WithHeadingRow { $name = trim($row['名稱'] ?? ''); $category = trim($row['類別'] ?? '未定義'); + $enable = trim($row['狀態'] ?? 1); if (empty($name)) { $this->failCount++; return null; @@ -31,7 +32,8 @@ class ArtistDataImport implements ToModel, WithHeadingRow try { Artist::firstOrCreate( ['name' => $name], - ['category' => ArtistCategory::tryFrom($category) ?? ArtistCategory::Unset] + ['category' => ArtistCategory::tryFrom($category) ?? ArtistCategory::Unset], + ['enable' => $enable], ); $this->successCount++; } catch (\Throwable $e) { diff --git a/app/Livewire/Admin/ArtistForm.php b/app/Livewire/Admin/ArtistForm.php index a1a793f..b216d93 100644 --- a/app/Livewire/Admin/ArtistForm.php +++ b/app/Livewire/Admin/ArtistForm.php @@ -23,6 +23,7 @@ class ArtistForm extends Component public array $fields = [ 'category' =>'unset', 'name' =>'', + 'enable' => true, ]; public $selectedCategory = []; // 表單中選到的權限 diff --git a/app/Livewire/Admin/ArtistTable.php b/app/Livewire/Admin/ArtistTable.php index 3142cfb..dc1ebeb 100644 --- a/app/Livewire/Admin/ArtistTable.php +++ b/app/Livewire/Admin/ArtistTable.php @@ -114,6 +114,7 @@ final class ArtistTable extends PowerGridComponent ->add('phonetic_abbr') ->add('pinyin_abbr') ->add('strokes_abbr') + ->add('enable') ->add('created_at_formatted', fn (Artist $model) => Carbon::parse($model->created_at)->format('Y-m-d H:i:s')); } @@ -133,6 +134,7 @@ final class ArtistTable extends PowerGridComponent $column[]=Column::make(__('artists.name.phinetic'), 'phonetic_abbr')->sortable()->searchable(); $column[]=Column::make(__('artists.name.pinyin'), 'pinyin_abbr')->sortable()->searchable(); $column[]=Column::make(__('artists.name.strokes'), 'strokes_abbr')->sortable()->searchable(); + $column[]=Column::make(__('artists.enable'), 'enable')->toggleable(hasPermission: $this->canEdit, trueLabel: 'yes', falseLabel: 'no'); $column[]=Column::make('Created at', 'created_at_formatted', 'created_at')->sortable()->hidden(true, false); $column[]=Column::action(__('artists.actions')); @@ -182,6 +184,7 @@ final class ArtistTable extends PowerGridComponent Filter::inputText('phonetic_abbr')->placeholder(__('artists.name.phinetic')), Filter::inputText('pinyin_abbr')->placeholder(__('artists.name.pinyin')), Filter::number('strokes_abbr')->thousands('.')->decimal(','), + Filter::boolean('enable')->label('✅', '❌'), Filter::datetimepicker('created_at'), ]; } diff --git a/app/Models/Artist.php b/app/Models/Artist.php index d9b5716..e02bfbe 100644 --- a/app/Models/Artist.php +++ b/app/Models/Artist.php @@ -20,6 +20,7 @@ class Artist extends Model 'phonetic_abbr', 'pinyin_abbr', 'strokes_abbr', + 'enable', ]; protected function casts(): array diff --git a/database/migrations/2025_04_23_031625_create_artists_table.php b/database/migrations/2025_04_23_031625_create_artists_table.php index 83e5546..5777a35 100644 --- a/database/migrations/2025_04_23_031625_create_artists_table.php +++ b/database/migrations/2025_04_23_031625_create_artists_table.php @@ -19,6 +19,7 @@ return new class extends Migration $table->string('phonetic_abbr')->comment('歌星注音'); $table->string('pinyin_abbr')->comment('歌星拼音'); $table->integer('strokes_abbr')->comment('歌星筆劃'); + $table->tinyInteger('enable')->default(1)->comment('狀態'); // 1,可看,0,不可看 $table->timestamps(); }); } diff --git a/resources/lang/zh-tw/artists.php b/resources/lang/zh-tw/artists.php index eca254d..b6cd0b8 100644 --- a/resources/lang/zh-tw/artists.php +++ b/resources/lang/zh-tw/artists.php @@ -17,6 +17,7 @@ return [ 'name.phinetic' => '注音', 'name.pinyin' => '拼音', 'name.strokes' => '筆劃', + 'enable' => '狀態', 'select_category' =>'選擇類別', diff --git a/resources/views/livewire/admin/artist-form.blade.php b/resources/views/livewire/admin/artist-form.blade.php index 3114986..6e22796 100644 --- a/resources/views/livewire/admin/artist-form.blade.php +++ b/resources/views/livewire/admin/artist-form.blade.php @@ -9,6 +9,7 @@ option-value="value" /> +