|
@@ -33,8 +33,16 @@ const _sfc_main = {
|
|
|
// 添加加载状态
|
|
|
loadError: false,
|
|
|
// 添加加载错误状态
|
|
|
- errorMessage: ""
|
|
|
+ errorMessage: "",
|
|
|
// 添加错误消息
|
|
|
+ answers: [],
|
|
|
+ // 存储用户的所有答案
|
|
|
+ currentQuestionDetail: null,
|
|
|
+ // 当前题目详情
|
|
|
+ isSubmitting: false,
|
|
|
+ // 是否正在提交答案
|
|
|
+ openQuestionAnswer: ""
|
|
|
+ // 存储开放问题的答案
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
@@ -63,30 +71,28 @@ const _sfc_main = {
|
|
|
async fetchInterviewList() {
|
|
|
try {
|
|
|
this.loading = true;
|
|
|
- const res = await api_user.getInterviewList();
|
|
|
- console.log(res);
|
|
|
- this.interviewId = res.items[0].id;
|
|
|
- this.fetchInterviewData();
|
|
|
+ const res2 = await api_user.getInterviewList();
|
|
|
+ console.log(res2);
|
|
|
+ this.interviewId = res2.items;
|
|
|
+ this.fetchInterviewData(res2.items);
|
|
|
} catch (error) {
|
|
|
console.error("获取面试列表失败:", error);
|
|
|
this.handleLoadError("获取面试列表失败");
|
|
|
}
|
|
|
},
|
|
|
// 获取面试详情数据
|
|
|
- async fetchInterviewData() {
|
|
|
+ async fetchInterviewData(data) {
|
|
|
try {
|
|
|
this.loading = true;
|
|
|
- const res = await api_user.getInterviewDetail({ id: this.interviewId });
|
|
|
- console.log("API返回数据:", res);
|
|
|
- if (res && Array.isArray(res.items)) {
|
|
|
- this.questions = res.items.map((q, index) => ({
|
|
|
+ if (data && Array.isArray(data)) {
|
|
|
+ this.questions = data.map((q, index) => ({
|
|
|
id: q.id || index + 1,
|
|
|
text: q.question || "未知问题",
|
|
|
options: q.options || [],
|
|
|
correctAnswer: q.correctAnswer || 0,
|
|
|
isImportant: q.is_system || false,
|
|
|
explanation: q.explanation || "",
|
|
|
- questionType: q.question_form || 1,
|
|
|
+ questionType: q.question_form,
|
|
|
questionTypeName: q.question_form_name || "单选题",
|
|
|
correctAnswers: q.correct_answers || [],
|
|
|
difficulty: q.difficulty || 1,
|
|
@@ -118,7 +124,7 @@ const _sfc_main = {
|
|
|
correctAnswer: data.correctAnswer || 0,
|
|
|
isImportant: data.is_system || false,
|
|
|
explanation: data.explanation || "",
|
|
|
- questionType: data.question_form || 1,
|
|
|
+ questionType: data.question_form,
|
|
|
// 1-单选题,2-多选题
|
|
|
questionTypeName: data.question_form_name || "单选题",
|
|
|
correctAnswers: data.correct_answers || [],
|
|
@@ -174,7 +180,7 @@ const _sfc_main = {
|
|
|
} else {
|
|
|
this.selectedOptions.push(index);
|
|
|
}
|
|
|
- } else {
|
|
|
+ } else if (this.currentQuestion.questionType === 1) {
|
|
|
this.selectedOption = index;
|
|
|
}
|
|
|
this.playAiSpeaking();
|
|
@@ -185,7 +191,9 @@ const _sfc_main = {
|
|
|
console.error("当前问题不存在");
|
|
|
return;
|
|
|
}
|
|
|
- if (this.currentQuestion.questionType === 2) {
|
|
|
+ if (this.currentQuestion.questionType === 0) {
|
|
|
+ this.isAnswerCorrect = true;
|
|
|
+ } else if (this.currentQuestion.questionType === 2) {
|
|
|
const sortedSelected = [...this.selectedOptions].sort();
|
|
|
const sortedCorrect = [...this.currentQuestion.correctAnswers].sort();
|
|
|
if (sortedSelected.length !== sortedCorrect.length) {
|
|
@@ -196,53 +204,126 @@ const _sfc_main = {
|
|
|
} else {
|
|
|
this.isAnswerCorrect = this.selectedOption === this.currentQuestion.correctAnswer;
|
|
|
}
|
|
|
- if (this.isAnswerCorrect) {
|
|
|
- this.score++;
|
|
|
- }
|
|
|
this.showResult = true;
|
|
|
- if (this.currentQuestionIndex === this.questions.length - 1) {
|
|
|
- setTimeout(() => {
|
|
|
- this.interviewCompleted = false;
|
|
|
- }, 1500);
|
|
|
+ },
|
|
|
+ nextQuestion() {
|
|
|
+ if (!this.showResult) {
|
|
|
+ this.checkAnswer();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.saveAnswer();
|
|
|
+ if (this.currentQuestionIndex >= this.questions.length - 1) {
|
|
|
+ this.showEndModal = true;
|
|
|
return;
|
|
|
}
|
|
|
- setTimeout(() => {
|
|
|
- this.goToNextQuestion();
|
|
|
- }, 1500);
|
|
|
+ this.goToNextQuestion();
|
|
|
},
|
|
|
- nextQuestion() {
|
|
|
- if (this.currentQuestion.questionType === 2) {
|
|
|
- if (this.selectedOptions.length > 0 && !this.showResult) {
|
|
|
- this.checkAnswer();
|
|
|
- }
|
|
|
+ // 保存当前题目的答案
|
|
|
+ saveAnswer() {
|
|
|
+ let answer;
|
|
|
+ if (this.currentQuestion.questionType === 0) {
|
|
|
+ answer = {
|
|
|
+ questionId: this.currentQuestion.id,
|
|
|
+ questionType: this.currentQuestion.questionType,
|
|
|
+ answer: this.openQuestionAnswer
|
|
|
+ };
|
|
|
} else {
|
|
|
- if (this.selectedOption !== null && !this.showResult) {
|
|
|
- this.checkAnswer();
|
|
|
- } else if (this.showResult) {
|
|
|
- this.goToNextQuestion();
|
|
|
- }
|
|
|
+ answer = {
|
|
|
+ questionId: this.currentQuestion.id,
|
|
|
+ questionType: this.currentQuestion.questionType,
|
|
|
+ answer: this.currentQuestion.questionType === 1 ? this.selectedOption : this.selectedOptions
|
|
|
+ };
|
|
|
+ }
|
|
|
+ const existingIndex = this.answers.findIndex((a) => a.questionId === answer.questionId);
|
|
|
+ if (existingIndex > -1) {
|
|
|
+ this.answers[existingIndex] = answer;
|
|
|
+ } else {
|
|
|
+ this.answers.push(answer);
|
|
|
}
|
|
|
+ console.log("已保存答案:", this.answers);
|
|
|
},
|
|
|
- // 新增方法,处理进入下一题的逻辑
|
|
|
- goToNextQuestion() {
|
|
|
+ // 提交所有答案
|
|
|
+ async submitAllAnswers() {
|
|
|
+ if (this.isSubmitting)
|
|
|
+ return;
|
|
|
+ try {
|
|
|
+ this.isSubmitting = true;
|
|
|
+ common_vendor.index.showLoading({
|
|
|
+ title: "正在提交答案..."
|
|
|
+ });
|
|
|
+ const submitData = {
|
|
|
+ interviewId: this.interviewId,
|
|
|
+ answers: this.answers
|
|
|
+ };
|
|
|
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ common_vendor.index.showToast({
|
|
|
+ title: "提交成功",
|
|
|
+ icon: "success"
|
|
|
+ });
|
|
|
+ setTimeout(() => {
|
|
|
+ this.back();
|
|
|
+ }, 1500);
|
|
|
+ } catch (error) {
|
|
|
+ console.error("提交答案失败:", error);
|
|
|
+ common_vendor.index.showToast({
|
|
|
+ title: "提交答案失败,请重试",
|
|
|
+ icon: "none"
|
|
|
+ });
|
|
|
+ } finally {
|
|
|
+ this.isSubmitting = false;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 修改 goToNextQuestion 方法,添加 async 关键字
|
|
|
+ async goToNextQuestion() {
|
|
|
this.showResult = false;
|
|
|
this.selectedOption = null;
|
|
|
this.selectedOptions = [];
|
|
|
+ this.openQuestionAnswer = "";
|
|
|
this.currentQuestionIndex++;
|
|
|
- if (this.currentQuestionIndex >= this.questions.length) {
|
|
|
- this.showEndModal = true;
|
|
|
- this.interviewCompleted = false;
|
|
|
- if (this.timerInterval) {
|
|
|
- clearInterval(this.timerInterval);
|
|
|
- }
|
|
|
+ if (this.questions[this.currentQuestionIndex]) {
|
|
|
+ this.progressWidth = (this.currentQuestionIndex + 1) / this.questions.length * 100;
|
|
|
+ this.resetTimer();
|
|
|
+ this.playAiSpeaking();
|
|
|
+ setTimeout(() => {
|
|
|
+ this.pauseAiSpeaking();
|
|
|
+ }, 2e3);
|
|
|
return;
|
|
|
}
|
|
|
- this.resetTimer();
|
|
|
- this.progressWidth = (this.currentQuestionIndex + 1) / this.questions.length * 100;
|
|
|
- this.playAiSpeaking();
|
|
|
- setTimeout(() => {
|
|
|
- this.pauseAiSpeaking();
|
|
|
- }, 2e3);
|
|
|
+ try {
|
|
|
+ this.loading = true;
|
|
|
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
|
+ const res2 = {
|
|
|
+ /* 模拟的题目数据 */
|
|
|
+ };
|
|
|
+ if (res2) {
|
|
|
+ const formattedQuestion = {
|
|
|
+ id: res2.id || this.currentQuestionIndex + 1,
|
|
|
+ text: res2.question || "未知问题",
|
|
|
+ options: res2.options || [],
|
|
|
+ correctAnswer: res2.correctAnswer || 0,
|
|
|
+ isImportant: res2.is_system || false,
|
|
|
+ explanation: res2.explanation || "",
|
|
|
+ questionType: res2.question_form || 1,
|
|
|
+ questionTypeName: res2.question_form_name || "单选题",
|
|
|
+ correctAnswers: res2.correct_answers || [],
|
|
|
+ difficulty: res2.difficulty || 1,
|
|
|
+ difficultyName: res2.difficulty_name || "初级"
|
|
|
+ };
|
|
|
+ this.questions.push(formattedQuestion);
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error("获取题目详情失败:", error);
|
|
|
+ common_vendor.index.showToast({
|
|
|
+ title: "获取题目失败,请重试",
|
|
|
+ icon: "none"
|
|
|
+ });
|
|
|
+ this.currentQuestionIndex--;
|
|
|
+ } finally {
|
|
|
+ this.loading = false;
|
|
|
+ this.progressWidth = (this.currentQuestionIndex + 1) / this.questions.length * 100;
|
|
|
+ this.resetTimer();
|
|
|
+ }
|
|
|
},
|
|
|
toggleSettings() {
|
|
|
common_vendor.index.showToast({
|
|
@@ -346,7 +427,13 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
}, $options.currentQuestion.isImportant ? {} : {}, {
|
|
|
h: common_vendor.t($options.currentQuestion.questionTypeName),
|
|
|
i: common_vendor.t($options.currentQuestion.text),
|
|
|
- j: common_vendor.f($options.currentQuestion.options, (option, index, i0) => {
|
|
|
+ j: $options.currentQuestion.questionType == 0
|
|
|
+ }, $options.currentQuestion.questionType == 0 ? {
|
|
|
+ k: $data.openQuestionAnswer,
|
|
|
+ l: common_vendor.o(($event) => $data.openQuestionAnswer = $event.detail.value),
|
|
|
+ m: common_vendor.t($data.openQuestionAnswer.length)
|
|
|
+ } : {
|
|
|
+ n: common_vendor.f($options.currentQuestion.options, (option, index, i0) => {
|
|
|
return {
|
|
|
a: common_vendor.t(option.option_text || (typeof option === "string" ? option : JSON.stringify(option))),
|
|
|
b: index,
|
|
@@ -356,16 +443,13 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
f: common_vendor.o(($event) => $options.selectOption(index), index)
|
|
|
};
|
|
|
}),
|
|
|
- k: common_vendor.t($data.remainingTime),
|
|
|
- l: common_vendor.t($data.showResult ? "下一题" : "提交答案"),
|
|
|
- m: common_vendor.o((...args) => $options.nextQuestion && $options.nextQuestion(...args)),
|
|
|
- n: $options.currentQuestion.questionType === 1 ? $data.selectedOption === null : $data.selectedOptions.length === 0,
|
|
|
- o: $data.showEndModal
|
|
|
+ o: common_vendor.t($options.currentQuestion.questionType === 1 ? "●" : "☐")
|
|
|
+ }, {
|
|
|
+ p: common_vendor.t($data.showResult ? "下一题" : "提交答案"),
|
|
|
+ q: common_vendor.o((...args) => $options.nextQuestion && $options.nextQuestion(...args)),
|
|
|
+ r: $options.currentQuestion.questionType === 0 && $data.openQuestionAnswer.trim() === "" || $options.currentQuestion.questionType === 1 && $data.selectedOption === null || $options.currentQuestion.questionType === 2 && $data.selectedOptions.length === 0,
|
|
|
+ s: $data.showEndModal
|
|
|
}, $data.showEndModal ? {
|
|
|
- p: common_vendor.t($data.score),
|
|
|
- q: common_vendor.t($data.totalQuestions),
|
|
|
- r: common_vendor.t($data.score),
|
|
|
- s: common_vendor.t($data.totalQuestions),
|
|
|
t: common_vendor.o((...args) => $options.restartTest && $options.restartTest(...args)),
|
|
|
v: common_vendor.o((...args) => $options.back && $options.back(...args))
|
|
|
} : {}, {
|