"use strict"; const common_vendor = require("../../common/vendor.js"); const common_assets = require("../../common/assets.js"); const _sfc_main = { data() { return { cameraContext: null, devicePosition: "front", interviewStarted: true, showEndModal: false, currentQuestionIndex: 0, currentStep: 1, stepTexts: ["测试准备", "回答问题", "测试结束"], progressWidth: 50, remainingTime: "00:27", selectedOption: null, showResult: 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: '儒家的五常是"仁、义、礼、智、信",不包括"孝"。' } ], useVideo: false, timerInterval: null, score: 0, totalQuestions: 0, interviewCompleted: false }; }, computed: { currentQuestion() { return this.questions[this.currentQuestionIndex]; } }, onReady() { this.cameraContext = common_vendor.index.createCameraContext(); if (this.useVideo) { this.aiVideoContext = common_vendor.index.createVideoContext("aiInterviewer"); } this.startTimer(); this.totalQuestions = this.questions.length; }, methods: { startTimer() { let seconds = 30; this.timerInterval = setInterval(() => { seconds--; if (seconds <= 0) { clearInterval(this.timerInterval); if (!this.showResult) { this.checkAnswer(); } } const min = Math.floor(seconds / 60).toString().padStart(2, "0"); const sec = (seconds % 60).toString().padStart(2, "0"); this.remainingTime = `${min}:${sec}`; }, 1e3); }, resetTimer() { clearInterval(this.timerInterval); this.startTimer(); }, selectOption(index) { if (this.showResult) return; this.selectedOption = index; this.playAiSpeaking(); }, checkAnswer() { clearInterval(this.timerInterval); if (!this.currentQuestion) { console.error("当前问题不存在"); return; } this.isAnswerCorrect = this.selectedOption === this.currentQuestion.correctAnswer; if (this.isAnswerCorrect) { this.score++; } if (this.currentQuestionIndex === this.questions.length - 1) { this.showEndModal = false; this.interviewCompleted = true; return; } this.goToNextQuestion(); }, nextQuestion() { if (this.selectedOption !== null) { this.checkAnswer(); return; } }, // 新增方法,处理进入下一题的逻辑 goToNextQuestion() { this.showResult = false; this.selectedOption = null; this.currentQuestionIndex++; if (this.currentQuestionIndex >= this.questions.length) { this.showEndModal = false; this.interviewCompleted = true; if (this.timerInterval) { clearInterval(this.timerInterval); } return; } this.resetTimer(); this.progressWidth = (this.currentQuestionIndex + 1) / this.questions.length * 100; this.playAiSpeaking(); setTimeout(() => { this.pauseAiSpeaking(); }, 2e3); }, toggleSettings() { common_vendor.index.showToast({ title: "设置功能开发中", icon: "none" }); }, back() { if (this.timerInterval) { clearInterval(this.timerInterval); } try { const pages = getCurrentPages(); if (pages.length > 1) { common_vendor.index.reLaunch({ url: "/pages/index/index" }); } else { common_vendor.index.reLaunch({ url: "/pages/index/index" }); } } catch (e) { console.error("导航错误:", e); common_vendor.index.reLaunch({ url: "/pages/index/index" }); } }, error(e) { console.error(e.detail); common_vendor.index.showToast({ title: "相机启动失败,请检查权限设置", icon: "none" }); }, playAiSpeaking() { if (this.useVideo && this.aiVideoContext) { this.aiVideoContext.play(); } }, pauseAiSpeaking() { if (this.useVideo && this.aiVideoContext) { this.aiVideoContext.pause(); } }, // 重新开始测试 restartTest() { this.currentQuestionIndex = 0; this.score = 0; this.showEndModal = false; this.showResult = false; this.selectedOption = null; this.resetTimer(); }, // 在methods中添加测试方法 testEndScreen() { this.interviewCompleted = true; this.showEndModal = false; } }, // 添加生命周期钩子,确保在组件销毁时清除计时器 beforeDestroy() { if (this.timerInterval) { clearInterval(this.timerInterval); } } }; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return common_vendor.e({ a: common_assets._imports_0, b: common_vendor.t($data.currentQuestionIndex + 1), c: common_vendor.t($options.currentQuestion.id), d: common_vendor.t($data.questions.length), e: $options.currentQuestion.isImportant }, $options.currentQuestion.isImportant ? {} : {}, { f: common_vendor.t($options.currentQuestion.text), g: common_vendor.f($options.currentQuestion.options, (option, index, i0) => { return { a: common_vendor.t(option), 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 : "", f: common_vendor.o(($event) => $options.selectOption(index), index) }; }), h: common_vendor.t($data.remainingTime), i: common_vendor.o((...args) => $options.nextQuestion && $options.nextQuestion(...args)), j: $data.selectedOption === null, k: $data.showEndModal }, $data.showEndModal ? { l: common_vendor.t($data.score), m: common_vendor.t($data.totalQuestions), n: common_vendor.t($data.score), o: common_vendor.t($data.totalQuestions), p: common_vendor.o((...args) => $options.restartTest && $options.restartTest(...args)), q: common_vendor.o((...args) => $options.back && $options.back(...args)) } : {}, { r: $data.interviewCompleted }, $data.interviewCompleted ? { s: common_assets._imports_0, t: common_vendor.o((...args) => $options.back && $options.back(...args)) } : {}); } const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]); wx.createPage(MiniProgramPage);