|
@@ -41,8 +41,12 @@ const _sfc_main = {
|
|
|
// 当前题目详情
|
|
|
isSubmitting: false,
|
|
|
// 是否正在提交答案
|
|
|
- openQuestionAnswer: ""
|
|
|
+ openQuestionAnswer: "",
|
|
|
// 存储开放问题的答案
|
|
|
+ currentAnswer: null,
|
|
|
+ // 存储当前答案以便提交
|
|
|
+ questionStartTime: null
|
|
|
+ // 存储问题开始时间
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
@@ -152,6 +156,7 @@ const _sfc_main = {
|
|
|
startTimer() {
|
|
|
if (this.questions.length === 0)
|
|
|
return;
|
|
|
+ this.questionStartTime = /* @__PURE__ */ new Date();
|
|
|
let seconds = 30;
|
|
|
this.timerInterval = setInterval(() => {
|
|
|
seconds--;
|
|
@@ -206,17 +211,25 @@ const _sfc_main = {
|
|
|
}
|
|
|
this.showResult = true;
|
|
|
},
|
|
|
- nextQuestion() {
|
|
|
+ nextQuestion(data) {
|
|
|
if (!this.showResult) {
|
|
|
this.checkAnswer();
|
|
|
return;
|
|
|
}
|
|
|
- this.saveAnswer();
|
|
|
- if (this.currentQuestionIndex >= this.questions.length - 1) {
|
|
|
- this.showEndModal = true;
|
|
|
- return;
|
|
|
- }
|
|
|
- this.goToNextQuestion();
|
|
|
+ this.saveAnswer(data);
|
|
|
+ this.submitCurrentAnswer(data).then(() => {
|
|
|
+ if (this.currentQuestionIndex >= this.questions.length - 1) {
|
|
|
+ this.showEndModal = true;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.goToNextQuestion();
|
|
|
+ }).catch((error) => {
|
|
|
+ console.error("提交答案失败:", error);
|
|
|
+ common_vendor.index.showToast({
|
|
|
+ title: "提交答案失败,请重试",
|
|
|
+ icon: "none"
|
|
|
+ });
|
|
|
+ });
|
|
|
},
|
|
|
// 保存当前题目的答案
|
|
|
saveAnswer() {
|
|
@@ -225,13 +238,17 @@ const _sfc_main = {
|
|
|
answer = {
|
|
|
questionId: this.currentQuestion.id,
|
|
|
questionType: this.currentQuestion.questionType,
|
|
|
- answer: this.openQuestionAnswer
|
|
|
+ answer: this.openQuestionAnswer,
|
|
|
+ answerDuration: this.getAnswerDuration()
|
|
|
+ // 添加答题时长
|
|
|
};
|
|
|
} else {
|
|
|
answer = {
|
|
|
questionId: this.currentQuestion.id,
|
|
|
questionType: this.currentQuestion.questionType,
|
|
|
- answer: this.currentQuestion.questionType === 1 ? this.selectedOption : this.selectedOptions
|
|
|
+ answer: this.currentQuestion.questionType === 1 ? this.selectedOption : this.selectedOptions,
|
|
|
+ answerDuration: this.getAnswerDuration()
|
|
|
+ // 添加答题时长
|
|
|
};
|
|
|
}
|
|
|
const existingIndex = this.answers.findIndex((a) => a.questionId === answer.questionId);
|
|
@@ -240,38 +257,60 @@ const _sfc_main = {
|
|
|
} else {
|
|
|
this.answers.push(answer);
|
|
|
}
|
|
|
+ this.currentAnswer = answer;
|
|
|
console.log("已保存答案:", this.answers);
|
|
|
},
|
|
|
- // 提交所有答案
|
|
|
- async submitAllAnswers() {
|
|
|
- if (this.isSubmitting)
|
|
|
+ // 获取答题时长(秒)
|
|
|
+ getAnswerDuration() {
|
|
|
+ const remainingTimeArr = this.remainingTime.split(":");
|
|
|
+ const remainingSeconds = parseInt(remainingTimeArr[0]) * 60 + parseInt(remainingTimeArr[1]);
|
|
|
+ return 30 - remainingSeconds;
|
|
|
+ },
|
|
|
+ // 提交当前答案
|
|
|
+ async submitCurrentAnswer() {
|
|
|
+ if (!this.currentAnswer)
|
|
|
return;
|
|
|
try {
|
|
|
- this.isSubmitting = true;
|
|
|
common_vendor.index.showLoading({
|
|
|
title: "正在提交答案..."
|
|
|
});
|
|
|
+ let answerContent = "";
|
|
|
+ if (this.currentAnswer.questionType === 0) {
|
|
|
+ answerContent = this.currentAnswer.answer;
|
|
|
+ } else if (this.currentAnswer.questionType === 1) {
|
|
|
+ const selectedIndex = this.currentAnswer.answer;
|
|
|
+ const selectedOption = this.currentQuestion.options[selectedIndex];
|
|
|
+ answerContent = selectedOption.id ? selectedOption.id.toString() : selectedIndex.toString();
|
|
|
+ } else if (this.currentAnswer.questionType === 2) {
|
|
|
+ const selectedIndices = this.currentAnswer.answer;
|
|
|
+ const selectedOptionIds = selectedIndices.map((index) => {
|
|
|
+ const option = this.currentQuestion.options[index];
|
|
|
+ return option.id ? option.id : index;
|
|
|
+ });
|
|
|
+ answerContent = selectedOptionIds.join(",");
|
|
|
+ }
|
|
|
const submitData = {
|
|
|
- interviewId: this.interviewId,
|
|
|
- answers: this.answers
|
|
|
+ application_id: 1,
|
|
|
+ // 或者使用其他合适的ID
|
|
|
+ question_id: this.currentAnswer.questionId,
|
|
|
+ answer_content: answerContent,
|
|
|
+ answer_duration: this.currentAnswer.answerDuration || 0,
|
|
|
+ // 如果需要tenant_id,请在这里添加
|
|
|
+ tenant_id: 1
|
|
|
};
|
|
|
- await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
|
+ console.log("提交数据:", submitData);
|
|
|
+ const res2 = await this.$http.post("http://192.168.66.187:8083/api/job/submit_answer", submitData);
|
|
|
+ console.log("提交答案响应:", res2);
|
|
|
common_vendor.index.hideLoading();
|
|
|
- common_vendor.index.showToast({
|
|
|
- title: "提交成功",
|
|
|
- icon: "success"
|
|
|
- });
|
|
|
- setTimeout(() => {
|
|
|
- this.back();
|
|
|
- }, 1500);
|
|
|
+ return res2;
|
|
|
} catch (error) {
|
|
|
console.error("提交答案失败:", error);
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
common_vendor.index.showToast({
|
|
|
title: "提交答案失败,请重试",
|
|
|
icon: "none"
|
|
|
});
|
|
|
- } finally {
|
|
|
- this.isSubmitting = false;
|
|
|
+ throw error;
|
|
|
}
|
|
|
},
|
|
|
// 修改 goToNextQuestion 方法,添加 async 关键字
|
|
@@ -446,7 +485,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
o: common_vendor.t($options.currentQuestion.questionType === 1 ? "●" : "☐")
|
|
|
}, {
|
|
|
p: common_vendor.t($data.showResult ? "下一题" : "提交答案"),
|
|
|
- q: common_vendor.o((...args) => $options.nextQuestion && $options.nextQuestion(...args)),
|
|
|
+ q: common_vendor.o(($event) => $options.nextQuestion(_ctx.option)),
|
|
|
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 ? {
|