selectedQuestionId || ! Schema::hasTable('questions')) { return null; } return Question::query()->find($this->selectedQuestionId); } public function selectQuestion(int $id): void { if ($id <= 0) { return; } if (! in_array($id, $this->tuningQuestionIds, true)) { Notification::make()->title('该题不在当前列表中')->warning()->send(); return; } $this->selectedQuestionId = $id; $q = Question::query()->find($id); if ($q) { $d = max(0.0, min(0.9, round((float) ($q->difficulty ?? 0.5), 2))); $this->difficultyInput = number_format($d, 2, '.', ''); } } public function saveDifficulty(): void { if (! $this->selectedQuestionId) { Notification::make()->title('请先选择题目')->warning()->send(); return; } if (! in_array($this->selectedQuestionId, $this->tuningQuestionIds, true)) { Notification::make()->title('该题不在当前列表中')->warning()->send(); return; } $raw = trim($this->difficultyInput); if ($raw === '' || ! is_numeric($raw)) { Notification::make()->title('难度格式不正确')->danger()->send(); return; } $value = round((float) $raw, 2); if ($value < 0.0 || $value > 0.9) { Notification::make()->title('难度须在 0.00~0.90 之间')->danger()->send(); return; } Question::query()->where('id', $this->selectedQuestionId)->update([ 'difficulty' => $value, ]); $this->difficultyInput = number_format($value, 2, '.', ''); Notification::make() ->title('已更新 difficulty') ->body(sprintf('question_id: %d · difficulty: %s', $this->selectedQuestionId, $this->difficultyInput)) ->success() ->send(); $this->dispatch('$refresh'); } public function clearTuningList(): void { session()->forget(QuestionTemReviewService::SESSION_TUNING_QUESTION_IDS); $this->selectedQuestionId = null; $this->difficultyInput = '0.50'; Notification::make()->title('已清空列表记录(仅本会话)')->success()->send(); $this->dispatch('$refresh'); } public function removeFromList(int $questionId): void { $ids = array_values(array_filter($this->tuningQuestionIds, fn (int $x) => $x !== $questionId)); session([QuestionTemReviewService::SESSION_TUNING_QUESTION_IDS => $ids]); if ($this->selectedQuestionId === $questionId) { $this->selectedQuestionId = null; $this->difficultyInput = '0.50'; } $this->dispatch('$refresh'); } }