|
@@ -313,9 +313,21 @@ const _sfc_main = {
|
|
|
this.submitCurrentAnswer().then(() => {
|
|
|
setTimeout(() => {
|
|
|
if (this.currentQuestionIndex >= this.questions.length - 1) {
|
|
|
- common_vendor.index.navigateTo({
|
|
|
- url: "/pages/interview-question/interview-question"
|
|
|
- });
|
|
|
+ if (this.currentGroupIndex < this.questionGroups.length - 1) {
|
|
|
+ this.showContinueButton = true;
|
|
|
+ setTimeout(() => {
|
|
|
+ this.scrollTop = 0;
|
|
|
+ this.$nextTick(() => {
|
|
|
+ setTimeout(() => {
|
|
|
+ this.scrollTop = 1e4;
|
|
|
+ }, 100);
|
|
|
+ });
|
|
|
+ }, 200);
|
|
|
+ } else {
|
|
|
+ common_vendor.index.navigateTo({
|
|
|
+ url: "/pages/interview-question/interview-question"
|
|
|
+ });
|
|
|
+ }
|
|
|
} else {
|
|
|
this.goToNextQuestion();
|
|
|
}
|
|
@@ -324,141 +336,22 @@ const _sfc_main = {
|
|
|
console.error("提交答案失败:", error);
|
|
|
setTimeout(() => {
|
|
|
if (this.currentQuestionIndex >= this.questions.length - 1) {
|
|
|
- common_vendor.index.navigateTo({
|
|
|
- url: "/pages/interview-question/interview-question"
|
|
|
- });
|
|
|
+ if (this.currentGroupIndex < this.questionGroups.length - 1) {
|
|
|
+ this.showContinueButton = true;
|
|
|
+ setTimeout(() => {
|
|
|
+ this.scrollTop = 1e4;
|
|
|
+ }, 200);
|
|
|
+ } else {
|
|
|
+ common_vendor.index.navigateTo({
|
|
|
+ url: "/pages/interview-question/interview-question"
|
|
|
+ });
|
|
|
+ }
|
|
|
} else {
|
|
|
this.goToNextQuestion();
|
|
|
}
|
|
|
}, 1e3);
|
|
|
});
|
|
|
},
|
|
|
- // 保存当前题目的答案
|
|
|
- saveAnswer() {
|
|
|
- let answer;
|
|
|
- if (this.currentQuestion.questionType === 0) {
|
|
|
- answer = {
|
|
|
- questionId: this.currentQuestion.id,
|
|
|
- questionType: this.currentQuestion.questionType,
|
|
|
- answer: this.openQuestionAnswer,
|
|
|
- answerDuration: this.getAnswerDuration()
|
|
|
- // 添加答题时长
|
|
|
- };
|
|
|
- } else if (this.currentQuestion.questionType === 1 || this.currentQuestion.questionType === 3 || this.currentQuestion.questionType === 4) {
|
|
|
- answer = {
|
|
|
- questionId: this.currentQuestion.id,
|
|
|
- questionType: this.currentQuestion.questionType,
|
|
|
- answer: this.selectedOption,
|
|
|
- answerDuration: this.getAnswerDuration()
|
|
|
- // 添加答题时长
|
|
|
- };
|
|
|
- } else {
|
|
|
- answer = {
|
|
|
- questionId: this.currentQuestion.id,
|
|
|
- questionType: this.currentQuestion.questionType,
|
|
|
- answer: this.selectedOptions,
|
|
|
- answerDuration: this.getAnswerDuration()
|
|
|
- // 添加答题时长
|
|
|
- };
|
|
|
- }
|
|
|
- const existingIndex = this.answers.findIndex((a) => a.questionId === answer.questionId);
|
|
|
- if (existingIndex > -1) {
|
|
|
- this.answers[existingIndex] = answer;
|
|
|
- } else {
|
|
|
- this.answers.push(answer);
|
|
|
- }
|
|
|
- this.currentAnswer = answer;
|
|
|
- console.log("已保存答案:", this.answers);
|
|
|
- },
|
|
|
- // 获取答题时长(秒)
|
|
|
- getAnswerDuration() {
|
|
|
- const remainingTimeArr = this.remainingTime.split(":");
|
|
|
- const remainingSeconds = parseInt(remainingTimeArr[0]) * 60 + parseInt(remainingTimeArr[1]);
|
|
|
- return 30 - remainingSeconds;
|
|
|
- },
|
|
|
- // 提交当前答案
|
|
|
- async submitCurrentAnswer() {
|
|
|
- if (!this.currentAnswer || this.isSubmitting)
|
|
|
- return;
|
|
|
- try {
|
|
|
- this.isSubmitting = true;
|
|
|
- common_vendor.index.showLoading({
|
|
|
- title: "正在提交答案..."
|
|
|
- });
|
|
|
- let answerContent = "";
|
|
|
- let answerOptions = [];
|
|
|
- if (this.currentAnswer.questionType === 0) {
|
|
|
- answerContent = this.currentAnswer.answer;
|
|
|
- answerOptions = [];
|
|
|
- } else if (this.currentAnswer.questionType === 1 || this.currentAnswer.questionType === 3 || this.currentAnswer.questionType === 4) {
|
|
|
- const selectedIndex = this.currentAnswer.answer;
|
|
|
- const selectedOption = this.currentQuestion.options[selectedIndex];
|
|
|
- console.log("selectedOption", selectedOption);
|
|
|
- const optionId = selectedOption.id ? selectedOption.id : selectedIndex;
|
|
|
- answerContent = optionId.toString();
|
|
|
- answerOptions = [optionId];
|
|
|
- } 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;
|
|
|
- });
|
|
|
- answerOptions = selectedOptionIds;
|
|
|
- }
|
|
|
- const submitData = {
|
|
|
- position_id: JSON.parse(common_vendor.index.getStorageSync("selectedJob")).id,
|
|
|
- applicant_id: JSON.parse(common_vendor.index.getStorageSync("userInfo")).id,
|
|
|
- job_position_question_id: this.currentAnswer.questionId,
|
|
|
- // answer_content: answerContent,
|
|
|
- answer_options: answerOptions,
|
|
|
- answer_duration: this.currentAnswer.answerDuration || 0,
|
|
|
- tenant_id: JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || 1
|
|
|
- };
|
|
|
- console.log("提交数据:", submitData);
|
|
|
- const res2 = await this.$http.post(`${common_config.apiBaseUrl}/api/job/submit_answer`, submitData);
|
|
|
- console.log("提交答案响应:", res2);
|
|
|
- return res2;
|
|
|
- } catch (error) {
|
|
|
- console.error("提交答案失败:", error);
|
|
|
- common_vendor.index.showToast({
|
|
|
- title: "提交答案失败,请重试",
|
|
|
- icon: "none"
|
|
|
- });
|
|
|
- throw error;
|
|
|
- } finally {
|
|
|
- common_vendor.index.hideLoading();
|
|
|
- this.isSubmitting = false;
|
|
|
- }
|
|
|
- },
|
|
|
- // 修改 goToNextQuestion 方法
|
|
|
- async goToNextQuestion() {
|
|
|
- if (this.currentQuestionIndex >= this.questions.length - 1) {
|
|
|
- this.showContinueButton = true;
|
|
|
- setTimeout(() => {
|
|
|
- this.scrollTop = 0;
|
|
|
- this.$nextTick(() => {
|
|
|
- setTimeout(() => {
|
|
|
- this.scrollTop = 1e4;
|
|
|
- }, 100);
|
|
|
- });
|
|
|
- }, 200);
|
|
|
- return;
|
|
|
- }
|
|
|
- this.currentQuestionIndex++;
|
|
|
- this.currentScrollId = "question-" + this.currentQuestionIndex;
|
|
|
- this.showResult = false;
|
|
|
- this.selectedOption = null;
|
|
|
- this.selectedOptions = [];
|
|
|
- this.openQuestionAnswer = "";
|
|
|
- if (this.questions[this.currentQuestionIndex]) {
|
|
|
- this.progressWidth = (this.currentQuestionIndex + 1) / this.questions.length * 100;
|
|
|
- this.resetTimer();
|
|
|
- this.playAiSpeaking();
|
|
|
- setTimeout(() => {
|
|
|
- this.pauseAiSpeaking();
|
|
|
- }, 2e3);
|
|
|
- }
|
|
|
- },
|
|
|
toggleSettings() {
|
|
|
common_vendor.index.showToast({
|
|
|
title: "设置功能开发中",
|
|
@@ -635,6 +528,132 @@ const _sfc_main = {
|
|
|
url: "/pages/interview-question/interview-question"
|
|
|
});
|
|
|
}
|
|
|
+ },
|
|
|
+ // 保存当前题目的答案
|
|
|
+ saveAnswer() {
|
|
|
+ let answer;
|
|
|
+ if (this.currentQuestion.questionType === 0) {
|
|
|
+ answer = {
|
|
|
+ questionId: this.currentQuestion.id,
|
|
|
+ questionType: this.currentQuestion.questionType,
|
|
|
+ answer: this.openQuestionAnswer,
|
|
|
+ answerDuration: this.getAnswerDuration()
|
|
|
+ // 添加答题时长
|
|
|
+ };
|
|
|
+ } else if (this.currentQuestion.questionType === 1 || this.currentQuestion.questionType === 3 || this.currentQuestion.questionType === 4) {
|
|
|
+ answer = {
|
|
|
+ questionId: this.currentQuestion.id,
|
|
|
+ questionType: this.currentQuestion.questionType,
|
|
|
+ answer: this.selectedOption,
|
|
|
+ answerDuration: this.getAnswerDuration()
|
|
|
+ // 添加答题时长
|
|
|
+ };
|
|
|
+ } else {
|
|
|
+ answer = {
|
|
|
+ questionId: this.currentQuestion.id,
|
|
|
+ questionType: this.currentQuestion.questionType,
|
|
|
+ answer: this.selectedOptions,
|
|
|
+ answerDuration: this.getAnswerDuration()
|
|
|
+ // 添加答题时长
|
|
|
+ };
|
|
|
+ }
|
|
|
+ const existingIndex = this.answers.findIndex((a) => a.questionId === answer.questionId);
|
|
|
+ if (existingIndex > -1) {
|
|
|
+ this.answers[existingIndex] = answer;
|
|
|
+ } else {
|
|
|
+ this.answers.push(answer);
|
|
|
+ }
|
|
|
+ this.currentAnswer = answer;
|
|
|
+ console.log("已保存答案:", this.answers);
|
|
|
+ },
|
|
|
+ // 获取答题时长(秒)
|
|
|
+ getAnswerDuration() {
|
|
|
+ const remainingTimeArr = this.remainingTime.split(":");
|
|
|
+ const remainingSeconds = parseInt(remainingTimeArr[0]) * 60 + parseInt(remainingTimeArr[1]);
|
|
|
+ return 30 - remainingSeconds;
|
|
|
+ },
|
|
|
+ // 提交当前答案
|
|
|
+ async submitCurrentAnswer() {
|
|
|
+ if (!this.currentAnswer || this.isSubmitting)
|
|
|
+ return;
|
|
|
+ try {
|
|
|
+ this.isSubmitting = true;
|
|
|
+ common_vendor.index.showLoading({
|
|
|
+ title: "正在提交答案..."
|
|
|
+ });
|
|
|
+ let answerContent = "";
|
|
|
+ let answerOptions = [];
|
|
|
+ if (this.currentAnswer.questionType === 0) {
|
|
|
+ answerContent = this.currentAnswer.answer;
|
|
|
+ answerOptions = [];
|
|
|
+ } else if (this.currentAnswer.questionType === 1 || this.currentAnswer.questionType === 3 || this.currentAnswer.questionType === 4) {
|
|
|
+ const selectedIndex = this.currentAnswer.answer;
|
|
|
+ const selectedOption = this.currentQuestion.options[selectedIndex];
|
|
|
+ console.log("selectedOption", selectedOption);
|
|
|
+ const optionId = selectedOption.id ? selectedOption.id : selectedIndex;
|
|
|
+ answerContent = optionId.toString();
|
|
|
+ answerOptions = [optionId];
|
|
|
+ } 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;
|
|
|
+ });
|
|
|
+ answerOptions = selectedOptionIds;
|
|
|
+ }
|
|
|
+ const submitData = {
|
|
|
+ position_id: JSON.parse(common_vendor.index.getStorageSync("selectedJob")).id,
|
|
|
+ applicant_id: JSON.parse(common_vendor.index.getStorageSync("userInfo")).id,
|
|
|
+ job_position_question_id: this.currentAnswer.questionId,
|
|
|
+ // answer_content: answerContent,
|
|
|
+ answer_options: answerOptions,
|
|
|
+ answer_duration: this.currentAnswer.answerDuration || 0,
|
|
|
+ tenant_id: JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || 1
|
|
|
+ };
|
|
|
+ console.log("提交数据:", submitData);
|
|
|
+ const res2 = await this.$http.post(`${common_config.apiBaseUrl}/api/job/submit_answer`, submitData);
|
|
|
+ console.log("提交答案响应:", res2);
|
|
|
+ return res2;
|
|
|
+ } catch (error) {
|
|
|
+ console.error("提交答案失败:", error);
|
|
|
+ common_vendor.index.showToast({
|
|
|
+ title: "提交答案失败,请重试",
|
|
|
+ icon: "none"
|
|
|
+ });
|
|
|
+ throw error;
|
|
|
+ } finally {
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ this.isSubmitting = false;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 修改 goToNextQuestion 方法
|
|
|
+ async goToNextQuestion() {
|
|
|
+ if (this.currentQuestionIndex >= this.questions.length - 1) {
|
|
|
+ this.showContinueButton = true;
|
|
|
+ setTimeout(() => {
|
|
|
+ this.scrollTop = 0;
|
|
|
+ this.$nextTick(() => {
|
|
|
+ setTimeout(() => {
|
|
|
+ this.scrollTop = 1e4;
|
|
|
+ }, 100);
|
|
|
+ });
|
|
|
+ }, 200);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.currentQuestionIndex++;
|
|
|
+ this.currentScrollId = "question-" + this.currentQuestionIndex;
|
|
|
+ this.showResult = false;
|
|
|
+ this.selectedOption = null;
|
|
|
+ this.selectedOptions = [];
|
|
|
+ this.openQuestionAnswer = "";
|
|
|
+ if (this.questions[this.currentQuestionIndex]) {
|
|
|
+ this.progressWidth = (this.currentQuestionIndex + 1) / this.questions.length * 100;
|
|
|
+ this.resetTimer();
|
|
|
+ this.playAiSpeaking();
|
|
|
+ setTimeout(() => {
|
|
|
+ this.pauseAiSpeaking();
|
|
|
+ }, 2e3);
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
// 添加生命周期钩子,确保在组件销毁时清除计时器
|