| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace App\Filament\Pages;
- use App\Support\TeacherWeeklyStatsReportPaths;
- use Filament\Actions\Action;
- use Filament\Notifications\Notification;
- use Filament\Pages\Page;
- use Illuminate\Support\Facades\Artisan;
- use Livewire\Attributes\Computed;
- use UnitEnum;
- class TeacherWeeklyStatsReport extends Page
- {
- protected static ?string $title = '老师周报统计';
- protected static ?string $navigationLabel = '老师周报统计';
- protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-document-chart-bar';
- protected static string|UnitEnum|null $navigationGroup = '其他';
- protected static ?int $navigationSort = 95;
- protected string $view = 'filament.pages.teacher-weekly-stats-report';
- #[Computed(cache: false)]
- public function hasLatestPdf(): bool
- {
- return TeacherWeeklyStatsReportPaths::resolveLatestPdfPath() !== null;
- }
- #[Computed(cache: false)]
- public function latestPdfBasename(): ?string
- {
- $p = TeacherWeeklyStatsReportPaths::resolveLatestPdfPath();
- return $p !== null ? basename($p) : null;
- }
- #[Computed(cache: false)]
- public function latestPdfMtime(): ?string
- {
- $p = TeacherWeeklyStatsReportPaths::resolveLatestPdfPath();
- return $p !== null ? date('Y-m-d H:i:s', filemtime($p)) : null;
- }
- #[Computed(cache: false)]
- public function pdfOpenUrl(): string
- {
- return route('filament.admin.reports.teacher-weekly-stats.open');
- }
- protected function getHeaderActions(): array
- {
- return [
- Action::make('regenerate')
- ->label('生成 / 刷新周报 PDF')
- ->icon('heroicon-o-arrow-path')
- ->action(function (): void {
- $code = Artisan::call('report:teacher-weekly-pdf');
- if ($code !== 0) {
- Notification::make()
- ->title('生成失败')
- ->danger()
- ->body('请查看日志或终端输出')
- ->send();
- return;
- }
- $this->dispatch('$refresh');
- Notification::make()
- ->title('周报已生成')
- ->success()
- ->send();
- }),
- ];
- }
- }
|