search) { $query->where('paper_name', 'like', '%' . $this->search . '%'); } // 应用状态过滤 if ($this->statusFilter) { $query->where('status', $this->statusFilter); } // 应用难度过滤 if ($this->difficultyFilter) { $query->where('difficulty_category', $this->difficultyFilter); } // 分页 $total = $query->count(); $papers = $query->withCount('questions') ->orderBy('created_at', 'desc') ->skip(($this->currentPage - 1) * $this->perPage) ->take($this->perPage) ->get() ->map(function ($paper) { return [ 'id' => $paper->paper_id, 'paper_name' => $paper->paper_name, 'question_count' => $paper->questions_count, // 使用实际的题目数量 'total_score' => $paper->total_score, 'difficulty_category' => $paper->difficulty_category, 'status' => $paper->status, 'created_at' => $paper->created_at, ]; }) ->toArray(); return [ 'data' => $papers, 'meta' => [ 'page' => $this->currentPage, 'per_page' => $this->perPage, 'total' => $total, 'total_pages' => ceil($total / $this->perPage), ] ]; } catch (\Exception $e) { \Illuminate\Support\Facades\Log::error('获取试卷列表失败', ['error' => $e->getMessage()]); return [ 'data' => [], 'meta' => ['page' => 1, 'per_page' => 20, 'total' => 0, 'total_pages' => 0] ]; } } #[Computed(cache: false)] public function meta(): array { $examsData = $this->exams(); return $examsData['meta'] ?? ['page' => 1, 'per_page' => 20, 'total' => 0, 'total_pages' => 0]; } public function updatedCurrentPage() { $this->reset('selectedExamId', 'selectedExamDetail'); } public function viewExamDetail(string $examId) { $this->selectedExamId = $examId; $this->loadExamDetail(); } protected function loadExamDetail() { if (!$this->selectedExamId) { return; } // 从本地数据库获取试卷详情,而不是外部API $paper = \App\Models\Paper::with(['questions' => function($query) { $query->orderBy('question_number'); }])->find($this->selectedExamId); if ($paper) { $this->selectedExamDetail = [ 'paper_id' => $paper->paper_id, 'paper_name' => $paper->paper_name, 'question_count' => $paper->questions->count(), // 使用实际题目数量 'total_score' => $paper->total_score, 'difficulty_category' => $paper->difficulty_category, 'status' => $paper->status, 'created_at' => $paper->created_at, 'updated_at' => $paper->updated_at, 'questions' => $paper->questions->map(function($question) { return [ 'id' => $question->id, 'question_number' => $question->question_number, 'question_bank_id' => $question->question_bank_id, 'question_type' => $question->question_type, 'score' => $question->score, 'knowledge_point' => $question->knowledge_point, 'difficulty' => $question->difficulty, ]; })->toArray(), ]; } else { $this->selectedExamDetail = []; } } public function exportPdf(string $examId) { $questionBankService = app(QuestionBankService::class); $pdfUrl = $questionBankService->exportExamToPdf($examId); if ($pdfUrl) { // TODO: 实际下载PDF Notification::make() ->title('PDF导出成功') ->body('试卷已导出为PDF格式') ->success() ->send(); } else { Notification::make() ->title('PDF导出失败') ->body('无法导出试卷,请稍后重试') ->danger() ->send(); } } public function duplicateExam(array $examData) { // 复制试卷配置,用于快速生成类似试卷 $learningService = app(\App\Services\LearningAnalyticsService::class); // 提取试卷配置 $examConfig = [ 'paper_name' => $examData['paper_name'] . ' (副本)', 'total_questions' => $examData['question_count'], 'difficulty_category' => $examData['difficulty_category'] ?? '基础', 'question_type_ratio' => [ '选择题' => 40, '填空题' => 30, '解答题' => 30, ], 'difficulty_ratio' => [ '基础' => 50, '中等' => 35, '拔高' => 15, ], ]; // TODO: 跳转到智能出卷页面并预填充配置 // 这里可以通过session传递配置,或者使用URL参数 Notification::make() ->title('试卷配置已复制') ->body('请前往智能出卷页面查看并使用该配置') ->success() ->send(); } public function deleteExam(string $examId) { // TODO: 实现删除试卷功能 // 需要在QuestionBankService中添加deleteExam方法 Notification::make() ->title('删除成功') ->body('试卷记录已删除') ->success() ->send(); $this->reset('selectedExamId', 'selectedExamDetail'); } public function getStatusColor(string $status): string { return match($status) { 'draft' => 'ghost', 'completed' => 'success', 'graded' => 'primary', default => 'ghost', }; } public function getStatusLabel(string $status): string { return match($status) { 'draft' => '草稿', 'completed' => '已完成', 'graded' => '已评分', default => '未知', }; } public function getDifficultyColor(string $difficulty): string { return match($difficulty) { '基础' => 'success', '进阶' => 'warning', '竞赛' => 'error', default => 'ghost', }; } }