|
@@ -1,5 +1,6 @@
|
|
"use strict";
|
|
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const common_vendor = require("../../common/vendor.js");
|
|
|
|
+const api_user = require("../../api/user.js");
|
|
const common_assets = require("../../common/assets.js");
|
|
const common_assets = require("../../common/assets.js");
|
|
const _sfc_main = {
|
|
const _sfc_main = {
|
|
data() {
|
|
data() {
|
|
@@ -14,74 +15,137 @@ const _sfc_main = {
|
|
progressWidth: 50,
|
|
progressWidth: 50,
|
|
remainingTime: "00:27",
|
|
remainingTime: "00:27",
|
|
selectedOption: null,
|
|
selectedOption: null,
|
|
|
|
+ selectedOptions: [],
|
|
showResult: false,
|
|
showResult: false,
|
|
isAnswerCorrect: false,
|
|
isAnswerCorrect: false,
|
|
- questions: [
|
|
|
|
- {
|
|
|
|
- id: 6,
|
|
|
|
- text: "以下不属于中国传统节日的是( )。",
|
|
|
|
- options: [
|
|
|
|
- "A. 春节",
|
|
|
|
- "B. 端午节",
|
|
|
|
- "C. 重阳节",
|
|
|
|
- "D. 元旦"
|
|
|
|
- ],
|
|
|
|
- correctAnswer: 3,
|
|
|
|
- isImportant: true,
|
|
|
|
- explanation: "元旦是公历新年,属于现代节日,而春节、端午节和重阳节都是中国传统节日。"
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- id: 7,
|
|
|
|
- text: "下列哪个是中国四大名著之一( )。",
|
|
|
|
- options: [
|
|
|
|
- "A. 聊斋志异",
|
|
|
|
- "B. 西游记",
|
|
|
|
- "C. 世说新语",
|
|
|
|
- "D. 聊斋志异"
|
|
|
|
- ],
|
|
|
|
- correctAnswer: 1,
|
|
|
|
- isImportant: false,
|
|
|
|
- explanation: "中国四大名著是《红楼梦》、《西游记》、《水浒传》和《三国演义》。"
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- id: 8,
|
|
|
|
- text: '中国传统文化中"仁义礼智信"五常不包括( )。',
|
|
|
|
- options: [
|
|
|
|
- "A. 忠",
|
|
|
|
- "B. 孝",
|
|
|
|
- "C. 礼",
|
|
|
|
- "D. 信"
|
|
|
|
- ],
|
|
|
|
- correctAnswer: 1,
|
|
|
|
- isImportant: true,
|
|
|
|
- explanation: '儒家的五常是"仁、义、礼、智、信",不包括"孝"。'
|
|
|
|
- }
|
|
|
|
- ],
|
|
|
|
|
|
+ questions: [],
|
|
|
|
+ // 改为空数组,将通过API获取
|
|
|
|
+ interviewId: null,
|
|
|
|
+ // 存储当前面试ID
|
|
useVideo: false,
|
|
useVideo: false,
|
|
timerInterval: null,
|
|
timerInterval: null,
|
|
score: 0,
|
|
score: 0,
|
|
totalQuestions: 0,
|
|
totalQuestions: 0,
|
|
interviewCompleted: false,
|
|
interviewCompleted: false,
|
|
- digitalHumanUrl: ""
|
|
|
|
|
|
+ digitalHumanUrl: "",
|
|
// 数字人URL
|
|
// 数字人URL
|
|
|
|
+ loading: true,
|
|
|
|
+ // 添加加载状态
|
|
|
|
+ loadError: false,
|
|
|
|
+ // 添加加载错误状态
|
|
|
|
+ errorMessage: ""
|
|
|
|
+ // 添加错误消息
|
|
};
|
|
};
|
|
},
|
|
},
|
|
computed: {
|
|
computed: {
|
|
currentQuestion() {
|
|
currentQuestion() {
|
|
|
|
+ console.log(this.questions[this.currentQuestionIndex]);
|
|
return this.questions[this.currentQuestionIndex];
|
|
return this.questions[this.currentQuestionIndex];
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ onLoad(options) {
|
|
|
|
+ if (options && options.id) {
|
|
|
|
+ this.interviewId = options.id;
|
|
|
|
+ this.fetchInterviewData();
|
|
|
|
+ } else {
|
|
|
|
+ this.fetchInterviewList();
|
|
|
|
+ }
|
|
|
|
+ },
|
|
onReady() {
|
|
onReady() {
|
|
this.cameraContext = common_vendor.index.createCameraContext();
|
|
this.cameraContext = common_vendor.index.createCameraContext();
|
|
if (this.useVideo) {
|
|
if (this.useVideo) {
|
|
this.aiVideoContext = common_vendor.index.createVideoContext("aiInterviewer");
|
|
this.aiVideoContext = common_vendor.index.createVideoContext("aiInterviewer");
|
|
}
|
|
}
|
|
- this.startTimer();
|
|
|
|
- this.totalQuestions = this.questions.length;
|
|
|
|
this.initDigitalHuman();
|
|
this.initDigitalHuman();
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
|
|
+ // 获取面试列表
|
|
|
|
+ async fetchInterviewList() {
|
|
|
|
+ try {
|
|
|
|
+ this.loading = true;
|
|
|
|
+ const res = await api_user.getInterviewList();
|
|
|
|
+ console.log(res);
|
|
|
|
+ this.interviewId = res.items[0].id;
|
|
|
|
+ this.fetchInterviewData();
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error("获取面试列表失败:", error);
|
|
|
|
+ this.handleLoadError("获取面试列表失败");
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ // 获取面试详情数据
|
|
|
|
+ async fetchInterviewData() {
|
|
|
|
+ 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) => ({
|
|
|
|
+ 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,
|
|
|
|
+ questionTypeName: q.question_form_name || "单选题",
|
|
|
|
+ correctAnswers: q.correct_answers || [],
|
|
|
|
+ difficulty: q.difficulty || 1,
|
|
|
|
+ difficultyName: q.difficulty_name || "初级"
|
|
|
|
+ }));
|
|
|
|
+ } else {
|
|
|
|
+ this.processInterviewData(res);
|
|
|
|
+ }
|
|
|
|
+ console.log(this.questions);
|
|
|
|
+ this.totalQuestions = this.questions.length;
|
|
|
|
+ if (this.questions.length > 0) {
|
|
|
|
+ this.startTimer();
|
|
|
|
+ }
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error("获取面试详情失败:", error);
|
|
|
|
+ this.handleLoadError("获取面试详情失败");
|
|
|
|
+ } finally {
|
|
|
|
+ this.loading = false;
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ // 处理面试数据
|
|
|
|
+ processInterviewData(data) {
|
|
|
|
+ this.questions = [];
|
|
|
|
+ if (data) {
|
|
|
|
+ const formattedQuestion = {
|
|
|
|
+ id: data.id || 1,
|
|
|
|
+ text: data.question || "未知问题",
|
|
|
|
+ options: data.options || [],
|
|
|
|
+ correctAnswer: data.correctAnswer || 0,
|
|
|
|
+ isImportant: data.is_system || false,
|
|
|
|
+ explanation: data.explanation || "",
|
|
|
|
+ questionType: data.question_form || 1,
|
|
|
|
+ // 1-单选题,2-多选题
|
|
|
|
+ questionTypeName: data.question_form_name || "单选题",
|
|
|
|
+ correctAnswers: data.correct_answers || [],
|
|
|
|
+ difficulty: data.difficulty || 1,
|
|
|
|
+ difficultyName: data.difficulty_name || "初级"
|
|
|
|
+ };
|
|
|
|
+ this.questions.push(formattedQuestion);
|
|
|
|
+ this.totalQuestions = this.questions.length;
|
|
|
|
+ this.startTimer();
|
|
|
|
+ } else {
|
|
|
|
+ this.handleLoadError("面试中没有问题");
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ // 处理加载错误
|
|
|
|
+ handleLoadError(message) {
|
|
|
|
+ this.loadError = true;
|
|
|
|
+ this.loading = false;
|
|
|
|
+ this.errorMessage = message || "加载失败";
|
|
|
|
+ common_vendor.index.showToast({
|
|
|
|
+ title: message || "加载失败",
|
|
|
|
+ icon: "none",
|
|
|
|
+ duration: 2e3
|
|
|
|
+ });
|
|
|
|
+ },
|
|
startTimer() {
|
|
startTimer() {
|
|
|
|
+ if (this.questions.length === 0)
|
|
|
|
+ return;
|
|
let seconds = 30;
|
|
let seconds = 30;
|
|
this.timerInterval = setInterval(() => {
|
|
this.timerInterval = setInterval(() => {
|
|
seconds--;
|
|
seconds--;
|
|
@@ -103,7 +167,16 @@ const _sfc_main = {
|
|
selectOption(index) {
|
|
selectOption(index) {
|
|
if (this.showResult)
|
|
if (this.showResult)
|
|
return;
|
|
return;
|
|
- this.selectedOption = index;
|
|
|
|
|
|
+ if (this.currentQuestion.questionType === 2) {
|
|
|
|
+ const optionIndex = this.selectedOptions.indexOf(index);
|
|
|
|
+ if (optionIndex > -1) {
|
|
|
|
+ this.selectedOptions.splice(optionIndex, 1);
|
|
|
|
+ } else {
|
|
|
|
+ this.selectedOptions.push(index);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ this.selectedOption = index;
|
|
|
|
+ }
|
|
this.playAiSpeaking();
|
|
this.playAiSpeaking();
|
|
},
|
|
},
|
|
checkAnswer() {
|
|
checkAnswer() {
|
|
@@ -112,31 +185,53 @@ const _sfc_main = {
|
|
console.error("当前问题不存在");
|
|
console.error("当前问题不存在");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- this.isAnswerCorrect = this.selectedOption === this.currentQuestion.correctAnswer;
|
|
|
|
|
|
+ if (this.currentQuestion.questionType === 2) {
|
|
|
|
+ const sortedSelected = [...this.selectedOptions].sort();
|
|
|
|
+ const sortedCorrect = [...this.currentQuestion.correctAnswers].sort();
|
|
|
|
+ if (sortedSelected.length !== sortedCorrect.length) {
|
|
|
|
+ this.isAnswerCorrect = false;
|
|
|
|
+ } else {
|
|
|
|
+ this.isAnswerCorrect = sortedSelected.every((value, index) => value === sortedCorrect[index]);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ this.isAnswerCorrect = this.selectedOption === this.currentQuestion.correctAnswer;
|
|
|
|
+ }
|
|
if (this.isAnswerCorrect) {
|
|
if (this.isAnswerCorrect) {
|
|
this.score++;
|
|
this.score++;
|
|
}
|
|
}
|
|
|
|
+ this.showResult = true;
|
|
if (this.currentQuestionIndex === this.questions.length - 1) {
|
|
if (this.currentQuestionIndex === this.questions.length - 1) {
|
|
- this.showEndModal = false;
|
|
|
|
- this.interviewCompleted = true;
|
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ this.interviewCompleted = false;
|
|
|
|
+ }, 1500);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- this.goToNextQuestion();
|
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ this.goToNextQuestion();
|
|
|
|
+ }, 1500);
|
|
},
|
|
},
|
|
nextQuestion() {
|
|
nextQuestion() {
|
|
- if (this.selectedOption !== null) {
|
|
|
|
- this.checkAnswer();
|
|
|
|
- return;
|
|
|
|
|
|
+ if (this.currentQuestion.questionType === 2) {
|
|
|
|
+ if (this.selectedOptions.length > 0 && !this.showResult) {
|
|
|
|
+ this.checkAnswer();
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (this.selectedOption !== null && !this.showResult) {
|
|
|
|
+ this.checkAnswer();
|
|
|
|
+ } else if (this.showResult) {
|
|
|
|
+ this.goToNextQuestion();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
},
|
|
},
|
|
// 新增方法,处理进入下一题的逻辑
|
|
// 新增方法,处理进入下一题的逻辑
|
|
goToNextQuestion() {
|
|
goToNextQuestion() {
|
|
this.showResult = false;
|
|
this.showResult = false;
|
|
this.selectedOption = null;
|
|
this.selectedOption = null;
|
|
|
|
+ this.selectedOptions = [];
|
|
this.currentQuestionIndex++;
|
|
this.currentQuestionIndex++;
|
|
if (this.currentQuestionIndex >= this.questions.length) {
|
|
if (this.currentQuestionIndex >= this.questions.length) {
|
|
- this.showEndModal = false;
|
|
|
|
- this.interviewCompleted = true;
|
|
|
|
|
|
+ this.showEndModal = true;
|
|
|
|
+ this.interviewCompleted = false;
|
|
if (this.timerInterval) {
|
|
if (this.timerInterval) {
|
|
clearInterval(this.timerInterval);
|
|
clearInterval(this.timerInterval);
|
|
}
|
|
}
|
|
@@ -205,6 +300,7 @@ const _sfc_main = {
|
|
this.showEndModal = false;
|
|
this.showEndModal = false;
|
|
this.showResult = false;
|
|
this.showResult = false;
|
|
this.selectedOption = null;
|
|
this.selectedOption = null;
|
|
|
|
+ this.selectedOptions = [];
|
|
this.resetTimer();
|
|
this.resetTimer();
|
|
},
|
|
},
|
|
// 在methods中添加测试方法
|
|
// 在methods中添加测试方法
|
|
@@ -214,7 +310,7 @@ const _sfc_main = {
|
|
},
|
|
},
|
|
// 初始化数字人
|
|
// 初始化数字人
|
|
initDigitalHuman() {
|
|
initDigitalHuman() {
|
|
- this.digitalHumanUrl = "https://your-digital-human-service.com/avatar?id=123";
|
|
|
|
|
|
+ this.digitalHumanUrl = "";
|
|
},
|
|
},
|
|
// 与数字人交互的方法
|
|
// 与数字人交互的方法
|
|
interactWithDigitalHuman(message) {
|
|
interactWithDigitalHuman(message) {
|
|
@@ -231,6 +327,10 @@ const _sfc_main = {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
+if (!Array) {
|
|
|
|
+ const _component_uni_load_more = common_vendor.resolveComponent("uni-load-more");
|
|
|
|
+ _component_uni_load_more();
|
|
|
|
+}
|
|
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
return common_vendor.e({
|
|
return common_vendor.e({
|
|
a: $data.digitalHumanUrl
|
|
a: $data.digitalHumanUrl
|
|
@@ -244,33 +344,48 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
f: common_vendor.t($data.questions.length),
|
|
f: common_vendor.t($data.questions.length),
|
|
g: $options.currentQuestion.isImportant
|
|
g: $options.currentQuestion.isImportant
|
|
}, $options.currentQuestion.isImportant ? {} : {}, {
|
|
}, $options.currentQuestion.isImportant ? {} : {}, {
|
|
- h: common_vendor.t($options.currentQuestion.text),
|
|
|
|
- i: common_vendor.f($options.currentQuestion.options, (option, index, i0) => {
|
|
|
|
|
|
+ h: common_vendor.t($options.currentQuestion.questionTypeName),
|
|
|
|
+ i: common_vendor.t($options.currentQuestion.text),
|
|
|
|
+ j: common_vendor.f($options.currentQuestion.options, (option, index, i0) => {
|
|
return {
|
|
return {
|
|
- a: common_vendor.t(option),
|
|
|
|
|
|
+ a: common_vendor.t(option.option_text || (typeof option === "string" ? option : JSON.stringify(option))),
|
|
b: index,
|
|
b: index,
|
|
- c: $data.selectedOption === index ? 1 : "",
|
|
|
|
- d: $data.showResult && index === $options.currentQuestion.correctAnswer ? 1 : "",
|
|
|
|
- e: $data.showResult && $data.selectedOption === index && index !== $options.currentQuestion.correctAnswer ? 1 : "",
|
|
|
|
|
|
+ c: ($options.currentQuestion.questionType === 1 ? $data.selectedOption === index : $data.selectedOptions.includes(index)) ? 1 : "",
|
|
|
|
+ d: $data.showResult && ($options.currentQuestion.questionType === 1 ? index === $options.currentQuestion.correctAnswer : $options.currentQuestion.correctAnswers.includes(index)) ? 1 : "",
|
|
|
|
+ e: $data.showResult && ($options.currentQuestion.questionType === 1 ? $data.selectedOption === index && index !== $options.currentQuestion.correctAnswer : $data.selectedOptions.includes(index) && !$options.currentQuestion.correctAnswers.includes(index)) ? 1 : "",
|
|
f: common_vendor.o(($event) => $options.selectOption(index), index)
|
|
f: common_vendor.o(($event) => $options.selectOption(index), index)
|
|
};
|
|
};
|
|
}),
|
|
}),
|
|
- j: common_vendor.t($data.remainingTime),
|
|
|
|
- k: common_vendor.o((...args) => $options.nextQuestion && $options.nextQuestion(...args)),
|
|
|
|
- l: $data.selectedOption === null,
|
|
|
|
- m: $data.showEndModal
|
|
|
|
|
|
+ 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
|
|
}, $data.showEndModal ? {
|
|
}, $data.showEndModal ? {
|
|
- n: common_vendor.t($data.score),
|
|
|
|
- o: common_vendor.t($data.totalQuestions),
|
|
|
|
p: common_vendor.t($data.score),
|
|
p: common_vendor.t($data.score),
|
|
q: common_vendor.t($data.totalQuestions),
|
|
q: common_vendor.t($data.totalQuestions),
|
|
- r: common_vendor.o((...args) => $options.restartTest && $options.restartTest(...args)),
|
|
|
|
- s: common_vendor.o((...args) => $options.back && $options.back(...args))
|
|
|
|
|
|
+ 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))
|
|
} : {}, {
|
|
} : {}, {
|
|
- t: $data.interviewCompleted
|
|
|
|
|
|
+ w: $data.interviewCompleted
|
|
}, $data.interviewCompleted ? {
|
|
}, $data.interviewCompleted ? {
|
|
- v: common_assets._imports_0,
|
|
|
|
- w: common_vendor.o((...args) => $options.back && $options.back(...args))
|
|
|
|
|
|
+ x: common_assets._imports_0,
|
|
|
|
+ y: common_vendor.o((...args) => $options.back && $options.back(...args))
|
|
|
|
+ } : {}, {
|
|
|
|
+ z: $data.loading
|
|
|
|
+ }, $data.loading ? {
|
|
|
|
+ A: common_vendor.p({
|
|
|
|
+ status: "loading",
|
|
|
|
+ contentText: {
|
|
|
|
+ contentdown: "加载中..."
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ } : {}, {
|
|
|
|
+ B: !$data.loading && $data.loadError
|
|
|
|
+ }, !$data.loading && $data.loadError ? {
|
|
|
|
+ C: common_vendor.o((...args) => $options.fetchInterviewData && $options.fetchInterviewData(...args))
|
|
} : {});
|
|
} : {});
|
|
}
|
|
}
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
|