| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace App\Filament\Pages;
- 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 is_file($this->latestPdfPath());
- }
- #[Computed(cache: false)]
- public function latestPdfMtime(): ?string
- {
- $p = $this->latestPdfPath();
- return is_file($p) ? 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 latestPdfPath(): string
- {
- return storage_path('app/reports/teacher-weekly-stats-latest.pdf');
- }
- 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();
- }),
- ];
- }
- }
|