feat: 实现操作日志管理界面
- ActivityLogResource: Filament 资源类 - 只读模式(禁用创建、编辑、删除) - 表格列:时间、用户、操作类型、对象、详情 - 按时间倒序排序 - 支持多维度筛选(时间范围、操作类型、用户、对象类型) - 集成导出功能(Excel/CSV) - ViewActivityLog: 日志详情页面 - 完整的变更信息展示 - JSON diff 对比视图 - 支持查看原始 JSON 数据 - activity-log-diff.blade.php: Diff 对比组件 - 字段级别的变更对比 - 使用颜色区分新旧值(绿色/红色) - 支持 JSON 数据格式化显示
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ActivityLogResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ActivityLogResource;
|
||||
use Filament\Infolists;
|
||||
use Filament\Infolists\Infolist;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewActivityLog extends ViewRecord
|
||||
{
|
||||
protected static string $resource = ActivityLogResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
// 不允许编辑和删除操作
|
||||
];
|
||||
}
|
||||
|
||||
public function infolist(Infolist $infolist): Infolist
|
||||
{
|
||||
return $infolist
|
||||
->schema([
|
||||
Infolists\Components\Section::make('基本信息')
|
||||
->schema([
|
||||
Infolists\Components\TextEntry::make('created_at')
|
||||
->label('操作时间')
|
||||
->dateTime('Y-m-d H:i:s'),
|
||||
|
||||
Infolists\Components\TextEntry::make('causer.name')
|
||||
->label('操作用户')
|
||||
->default('系统'),
|
||||
|
||||
Infolists\Components\TextEntry::make('description')
|
||||
->label('操作类型')
|
||||
->badge()
|
||||
->color(fn (string $state): string => match ($state) {
|
||||
'created' => 'success',
|
||||
'updated' => 'info',
|
||||
'deleted' => 'danger',
|
||||
default => 'gray',
|
||||
})
|
||||
->formatStateUsing(fn (string $state): string => match ($state) {
|
||||
'created' => '创建',
|
||||
'updated' => '更新',
|
||||
'deleted' => '删除',
|
||||
default => $state,
|
||||
}),
|
||||
|
||||
Infolists\Components\TextEntry::make('subject_type')
|
||||
->label('操作对象类型')
|
||||
->formatStateUsing(function (?string $state): string {
|
||||
if (!$state) {
|
||||
return '-';
|
||||
}
|
||||
$className = class_basename($state);
|
||||
return match ($className) {
|
||||
'SystemSetting' => '系统设置',
|
||||
'User' => '用户',
|
||||
'Document' => '文档',
|
||||
'Group' => '分组',
|
||||
'Terminal' => '终端',
|
||||
'SopTemplate' => 'SOP模板',
|
||||
default => $className,
|
||||
};
|
||||
}),
|
||||
|
||||
Infolists\Components\TextEntry::make('subject_id')
|
||||
->label('对象ID'),
|
||||
|
||||
Infolists\Components\TextEntry::make('log_name')
|
||||
->label('日志名称')
|
||||
->default('default'),
|
||||
])
|
||||
->columns(2),
|
||||
|
||||
Infolists\Components\Section::make('变更详情')
|
||||
->schema([
|
||||
Infolists\Components\ViewEntry::make('properties')
|
||||
->label('')
|
||||
->view('filament.infolists.components.activity-log-diff')
|
||||
->columnSpanFull()
|
||||
->visible(fn ($record) => !empty($record->properties)),
|
||||
])
|
||||
->collapsible(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user