| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- namespace App\Filament\Pages;
- use App\Models\OCRRecord;
- use App\Services\ExamPaperService;
- use App\Jobs\RegradeOCRSubmission;
- use App\Filament\Traits\HasUserRole;
- use Filament\Pages\Page;
- use Filament\Notifications\Notification;
- use Livewire\Attributes\Computed;
- class OCRPaperGrading extends Page
- {
- use HasUserRole;
- protected static ?string $navigationLabel = 'OCR智能阅卷';
- protected static ?string $title = 'OCR试卷智能阅卷系统';
- protected static ?string $slug = 'ocr-paper-grading';
- public static function getNavigationIcon(): ?string
- {
- return 'heroicon-o-document-duplicate';
- }
- public static function getNavigationGroup(): ?string
- {
- return 'OCR+AI系统';
- }
- protected string $view = 'filament.pages.ocr-paper-grading';
- // 选择相关
- public ?string $teacherId = null;
- public ?string $studentId = null;
- public ?string $selectedPaperId = null;
- // 处理状态
- public ?int $selectedRecordId = null;
- public ?OCRRecord $selectedRecord = null;
- public function mount(): void
- {
- $this->initializeUserRole();
- if ($this->isTeacher) {
- $teacherId = $this->getCurrentTeacherId();
- if ($teacherId) {
- $this->teacherId = $teacherId;
- }
- }
- }
- #[Computed]
- public function teachers(): array
- {
- return app(ExamPaperService::class)->getTeachers(
- $this->isTeacher ? $this->getCurrentTeacherId() : null
- );
- }
- #[Computed]
- public function students(): array
- {
- return app(ExamPaperService::class)->getStudents($this->teacherId);
- }
- #[Computed]
- public function studentPapers(): array
- {
- return app(ExamPaperService::class)->getStudentPapers($this->studentId);
- }
- #[Computed]
- public function selectedPaperQuestions(): array
- {
- return app(ExamPaperService::class)->getPaperQuestions($this->selectedPaperId);
- }
- public function updatedTeacherId($value): void
- {
- $this->studentId = null;
- $this->selectedPaperId = null;
- }
- public function updatedStudentId($value): void
- {
- $this->selectedPaperId = null;
- }
- /**
- * 查看OCR记录
- */
- public function viewRecord(int $recordId): void
- {
- $this->selectedRecordId = $recordId;
- $this->selectedRecord = OCRRecord::with('questions')->findOrFail($recordId);
- }
- /**
- * 手动重新判分
- */
- public function regrade(int $recordId): void
- {
- RegradeOCRSubmission::dispatch($recordId);
- Notification::make()
- ->title('已触发重新判分')
- ->body('请稍后刷新查看结果')
- ->success()
- ->send();
- }
- /**
- * 获取最近的OCR记录
- */
- public function getRecentRecords(): \Illuminate\Database\Eloquent\Collection
- {
- return OCRRecord::with('questions')
- ->orderBy('created_at', 'desc')
- ->limit(10)
- ->get();
- }
- }
|