teacherId = $teacherId; $this->studentId = $studentId; $this->selectedPaperId = $selectedPaperId; } public function handleSubmit() { // 验证图片 if (empty($this->uploadedImages)) { Notification::make() ->title('请上传试卷图片') ->danger() ->send(); return; } $this->isUploading = true; try { // 保存图片 $savedImages = []; foreach ($this->uploadedImages as $image) { $path = $image->store('exam-papers', 'public'); $savedImages[] = [ 'path' => $path, 'original_name' => $image->getClientOriginalName(), 'size' => $image->getSize(), ]; } // 获取试卷名称 $paperTitle = '待OCR识别'; if ($this->selectedPaperId) { $paper = \App\Models\Paper::where('paper_id', $this->selectedPaperId)->first(); if ($paper) { $paperTitle = $paper->paper_name; } } // 创建 OCR 记录 $ocrRecord = \App\Models\OCRRecord::create([ 'user_id' => $this->studentId, 'student_id' => $this->studentId, // 同时设置 student_id 'paper_title' => $paperTitle, 'paper_type' => null, 'file_path' => $savedImages[0]['path'], 'image_count' => count($savedImages), 'status' => 'processing', 'analysis_id' => $this->selectedPaperId, // 存储关联的试卷ID ]); // 派发 OCR 处理任务 ProcessOCRRecord::dispatch($ocrRecord->id); Notification::make() ->title('上传成功') ->body('图片已上传,正在进行 OCR 识别...') ->success() ->send(); // 判断是否为系统生成的试卷 if ($this->selectedPaperId && str_starts_with($this->selectedPaperId, 'paper_')) { // 系统生成的试卷,跳转到专门的分析页面 $this->redirect('/admin/ocr-paper-analysis/' . $ocrRecord->id); } else { // 上传的试卷,跳转到原来的 OCR 详情页 $this->redirect('/admin/ocr-record-view/' . $ocrRecord->id); } } catch (\Exception $e) { Notification::make() ->title('上传失败') ->body($e->getMessage()) ->danger() ->send(); } finally { $this->isUploading = false; } } public function resetForm() { $this->uploadedImages = []; $this->currentOcrRecordId = null; $this->ocrStatus = null; } public function removeImage($index) { unset($this->uploadedImages[$index]); $this->uploadedImages = array_values($this->uploadedImages); } public function render() { return view('livewire.upload-exam.upload-form'); } }