From b9e4064725b0c0ebed18f866d78fceaf5a90a46e Mon Sep 17 00:00:00 2001 From: "allen.yan" Date: Mon, 12 May 2025 16:56:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=93=8D=E4=BD=9C=E8=A8=98=E9=8C=84=20?= =?UTF-8?q?=E6=9F=A5=E8=A9=A2=E5=8A=9F=E8=83=BD=E8=A3=9C=E4=B8=8A=20?= =?UTF-8?q?=E6=AA=94=E6=A1=88=E4=B8=8B=E8=BC=89=E5=95=8F=E9=A1=8C=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=2020250512?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 10244 -> 10244 bytes app/Livewire/Admin/ActivityLogTable.php | 51 +++++++++++++++++------- app/Livewire/Admin/ArtistTable.php | 4 +- app/Livewire/Admin/BranchTable.php | 3 +- app/Livewire/Admin/SongTable.php | 4 +- app/Livewire/Admin/UserTable.php | 7 ++-- app/Models/User.php | 3 +- 7 files changed, 47 insertions(+), 25 deletions(-) diff --git a/.DS_Store b/.DS_Store index e28070c433ad99821cc161fb14df5658dfadcb60..92ed48d27371b7970cea20c067ba4968c675b67d 100644 GIT binary patch delta 27 jcmZn(XbISGQJj%s^CfX^Mn=ZX_ar{^F)~cPByI!%iDL;x delta 27 jcmZn(XbISGQJj%+^CfX^Mn;Cs_ar{^F)~iRByI!%iEjx; diff --git a/app/Livewire/Admin/ActivityLogTable.php b/app/Livewire/Admin/ActivityLogTable.php index 1dd0b4a..ad22c8b 100644 --- a/app/Livewire/Admin/ActivityLogTable.php +++ b/app/Livewire/Admin/ActivityLogTable.php @@ -10,24 +10,43 @@ use PowerComponents\LivewirePowerGrid\Facades\Filter; use PowerComponents\LivewirePowerGrid\Facades\PowerGrid; use PowerComponents\LivewirePowerGrid\PowerGridFields; use PowerComponents\LivewirePowerGrid\PowerGridComponent; +use PowerComponents\LivewirePowerGrid\Traits\WithExport; +use PowerComponents\LivewirePowerGrid\Components\SetUp\Exportable; use Spatie\Activitylog\Models\Activity; final class ActivityLogTable extends PowerGridComponent { + use WithExport; public string $tableName = 'activity-log-table'; + public bool $canDownload; + + public bool $showFilters = false; + public function boot(): void + { + config(['livewire-powergrid.filter' => 'outside']); + //權限設定 + $this->canDownload=true; + } public function setUp(): array { - $this->showCheckBox(); - - return [ - PowerGrid::header() - ->showSearchInput(), - PowerGrid::footer() - ->showPerPage() - ->showRecordCount(), - ]; + if($this->canDownload ){ + $this->showCheckBox(); + } + $actions = []; + if($this->canDownload){ + $actions[]=PowerGrid::exportable(fileName: $this->tableName.'-file') + ->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV); + } + $header = PowerGrid::header() + ->withoutLoading() + ->showToggleColumns(); + //->showSoftDeletes() + //->showSearchInput() + $actions[]=$header; + $actions[]=PowerGrid::footer()->showPerPage()->showRecordCount(); + return $actions; } public function datasource(): Builder @@ -50,8 +69,7 @@ final class ActivityLogTable extends PowerGridComponent ->add('subject_type') ->add('subject_id') ->add('description') - ->add('log_name') - ->add('changes', function (Activity $model) { + ->add('changes_str', function (Activity $model) { $old = $model->properties['old'] ?? []; $new = $model->properties['attributes'] ?? []; @@ -64,7 +82,7 @@ final class ActivityLogTable extends PowerGridComponent $changes[] = "{$key}: {$oldValue} → {$newValue}"; } } - + //dd(implode('
', $changes)); return implode('
', $changes); }) ; @@ -75,12 +93,11 @@ final class ActivityLogTable extends PowerGridComponent { $column=[]; $column[]=Column::make('時間', 'created_at_formatted', 'created_at')->sortable()->searchable(); - $column[]=Column::make('操作者', 'causer.name')->sortable()->searchable()->bodyAttribute('whitespace-nowrap'); + $column[]=Column::make('操作者', 'causer_name')->sortable()->searchable()->bodyAttribute('whitespace-nowrap'); $column[]=Column::make('模型', 'subject_type_label')->sortable()->searchable(); $column[]=Column::make('模型 ID', 'subject_id')->sortable()->searchable(); $column[]=Column::make('動作', 'description')->sortable()->searchable(); - $column[]=Column::make('變更內容', 'changes')->sortable(false)->searchable(false)->bodyAttribute('whitespace-normal text-sm text-gray-700'); - $column[]=Column::make('Log 名稱', 'log_name')->sortable()->searchable(); + $column[]=Column::make('變更內容', 'changes_str')->sortable(false)->searchable(false)->bodyAttribute('whitespace-normal text-sm text-gray-700'); return $column; } @@ -88,6 +105,10 @@ final class ActivityLogTable extends PowerGridComponent { return [ Filter::datetimepicker('created_at'), + Filter::inputText('causer_name')->placeholder('操作者'), + Filter::inputText('subject_type_label')->placeholder('模型'), + Filter::number('subject_id'), + Filter::inputText('description')->placeholder('動作'), ]; } diff --git a/app/Livewire/Admin/ArtistTable.php b/app/Livewire/Admin/ArtistTable.php index e4f39dd..d0fc154 100644 --- a/app/Livewire/Admin/ArtistTable.php +++ b/app/Livewire/Admin/ArtistTable.php @@ -23,7 +23,7 @@ use WireUi\Traits\WireUiActions; final class ArtistTable extends PowerGridComponent { - use WireUiActions; + use WithExport, WireUiActions; public string $tableName = 'artist-table'; public bool $canCreate; @@ -54,7 +54,7 @@ final class ArtistTable extends PowerGridComponent $actions = []; if($this->canDownload){ - $actions[]=PowerGrid::exportable(fileName: 'artist-file') + $actions[]=PowerGrid::exportable(fileName: $this->tableName.'-file') ->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV); } $header = PowerGrid::header() diff --git a/app/Livewire/Admin/BranchTable.php b/app/Livewire/Admin/BranchTable.php index aa31261..e09e442 100644 --- a/app/Livewire/Admin/BranchTable.php +++ b/app/Livewire/Admin/BranchTable.php @@ -22,6 +22,7 @@ use WireUi\Traits\WireUiActions; final class BranchTable extends PowerGridComponent { + use WithExport, WireUiActions; public string $tableName = 'branch-table'; public bool $canCreate; public bool $canEdit; @@ -47,7 +48,7 @@ final class BranchTable extends PowerGridComponent } $actions = []; if($this->canDownload){ - $actions[]=PowerGrid::exportable(fileName: 'branch-file') + $actions[]=PowerGrid::exportable(fileName: $this->tableName.'-file') ->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV); } $header = PowerGrid::header() diff --git a/app/Livewire/Admin/SongTable.php b/app/Livewire/Admin/SongTable.php index 1792d5e..3b816e9 100644 --- a/app/Livewire/Admin/SongTable.php +++ b/app/Livewire/Admin/SongTable.php @@ -24,7 +24,7 @@ use WireUi\Traits\WireUiActions; final class SongTable extends PowerGridComponent { - use WireUiActions; + use WithExport, WireUiActions; public string $tableName = 'song-table'; public bool $canCreate; @@ -54,7 +54,7 @@ final class SongTable extends PowerGridComponent } $actions = []; if($this->canDownload){ - $actions[]=PowerGrid::exportable(fileName: 'song-file') + $actions[]=PowerGrid::exportable(fileName: $this->tableName.'-file') ->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV); } $header = PowerGrid::header()->showSoftDeletes()->showToggleColumns(); diff --git a/app/Livewire/Admin/UserTable.php b/app/Livewire/Admin/UserTable.php index 10bb107..248d583 100644 --- a/app/Livewire/Admin/UserTable.php +++ b/app/Livewire/Admin/UserTable.php @@ -15,7 +15,7 @@ use PowerComponents\LivewirePowerGrid\Facades\Filter; use PowerComponents\LivewirePowerGrid\Facades\PowerGrid; use PowerComponents\LivewirePowerGrid\PowerGridFields; use PowerComponents\LivewirePowerGrid\PowerGridComponent; -//use PowerComponents\LivewirePowerGrid\Traits\WithExport; +use PowerComponents\LivewirePowerGrid\Traits\WithExport; use PowerComponents\LivewirePowerGrid\Components\SetUp\Exportable; use PowerComponents\LivewirePowerGrid\Facades\Rule; use Livewire\Attributes\On; @@ -23,8 +23,7 @@ use WireUi\Traits\WireUiActions; final class UserTable extends PowerGridComponent { - use WireUiActions; - //use WithExport ; + use WithExport, WireUiActions; public string $tableName = 'user-table'; @@ -51,7 +50,7 @@ final class UserTable extends PowerGridComponent $this->showCheckBox(); } $actions = []; - $actions[] =PowerGrid::exportable(fileName: 'user-file') + $actions[] =PowerGrid::exportable(fileName: $this->tableName.'-file') ->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV); $header = PowerGrid::header() ->showToggleColumns(); diff --git a/app/Models/User.php b/app/Models/User.php index c6057b0..584a10e 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -8,11 +8,12 @@ use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Spatie\Permission\Traits\HasRoles; use App\Traits\LogsModelActivity; +use Spatie\Activitylog\Traits\CausesActivity; class User extends Authenticatable { /** @use HasFactory<\Database\Factories\UserFactory> */ - use HasFactory, Notifiable, HasRoles, LogsModelActivity; + use HasFactory, Notifiable, HasRoles, LogsModelActivity,CausesActivity; /** * The attributes that are mass assignable.