camera.vue 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  1. <template>
  2. <view class="camera-container">
  3. <!-- 顶部标题栏 -->
  4. <!-- <view class="header">
  5. <view class="back-button" @click="back">
  6. <text class="iconfont icon-back">&#xe679;</text>
  7. </view>
  8. <view class="title">中国传统文化测试</view>
  9. <view class="controls">
  10. <text class="iconfont icon-mic">&#xe677;</text>
  11. <text class="iconfont icon-settings" @click="toggleSettings">&#xe678;</text>
  12. </view>
  13. </view> -->
  14. <!-- 主要内容区域 -->
  15. <view class="content">
  16. <!-- 数字人头像 -->
  17. <view class="digital-avatar">
  18. <web-view v-if="digitalHumanUrl" :src="digitalHumanUrl" class="digital-human-webview"></web-view>
  19. <image v-else src="/static/avatar.png" mode="aspectFill" class="avatar-image"></image>
  20. </view>
  21. <!-- 进度指示器 -->
  22. <!-- <view class="progress-container">
  23. <view class="progress-step" v-for="(step, index) in 3" :key="index">
  24. <view class="step-circle" :class="{'active': currentStep >= index+1}">{{index+1}}</view>
  25. <view class="step-text">{{stepTexts[index]}}</view>
  26. </view>
  27. <view class="progress-bar">
  28. <view class="progress-fill" :style="{width: progressWidth + '%'}"></view>
  29. </view>
  30. </view> -->
  31. <!-- 面试内容区域 -->
  32. <view class="interview-content">
  33. <!-- 问题编号和进度 -->
  34. <view class="question-number">
  35. <text>{{currentQuestionIndex + 1}}/{{questions.length}}</text>
  36. </view>
  37. <!-- 问题和选项区域 -->
  38. <view class="question-area">
  39. <view class="question-importance">
  40. <text v-if="currentQuestion.isImportant">重点题</text>
  41. <text class="question-type">[{{currentQuestion.questionTypeName}}]</text>
  42. {{currentQuestion.text}}
  43. </view>
  44. <view class="options">
  45. <!-- 开放问题 (question_form: 0) - 显示文本输入框 -->
  46. <!-- {{ currentQuestion }} -->
  47. <view v-if="currentQuestion.questionType == 0" class="open-question-container">
  48. <textarea
  49. class="open-question-input"
  50. v-model="openQuestionAnswer"
  51. placeholder="请输入您的回答..."
  52. maxlength="500"
  53. ></textarea>
  54. <view class="word-count">{{openQuestionAnswer.length}}/500</view>
  55. </view>
  56. <!-- 单选题和多选题 (question_form: 1 或 2) -->
  57. <view
  58. v-else
  59. v-for="(option, index) in currentQuestion.options"
  60. :key="index"
  61. class="option-item"
  62. :class="{
  63. 'option-selected': currentQuestion.questionType === 1 ? selectedOption === index : selectedOptions.includes(index),
  64. 'option-correct': showResult && (
  65. currentQuestion.questionType === 1 ? index === currentQuestion.correctAnswer : currentQuestion.correctAnswers.includes(index)
  66. ),
  67. 'option-wrong': showResult && (
  68. currentQuestion.questionType === 1 ?
  69. (selectedOption === index && index !== currentQuestion.correctAnswer) :
  70. (selectedOptions.includes(index) && !currentQuestion.correctAnswers.includes(index))
  71. )
  72. }"
  73. @click="selectOption(index)">
  74. <!-- 选项前添加单选/多选标识 -->
  75. <text class="option-prefix">{{currentQuestion.questionType === 1 ? '●' : '☐'}}</text>
  76. <text class="option-text">{{ option.option_text || (typeof option === 'string' ? option : JSON.stringify(option)) }}</text>
  77. </view>
  78. </view>
  79. <!-- <view class="timer-container">
  80. <text class="timer-text">本题剩余时间 {{remainingTime}}</text>
  81. </view> -->
  82. <button class="next-button" @click="nextQuestion(option)"
  83. :disabled="
  84. (currentQuestion.questionType === 0 && openQuestionAnswer.trim() === '') ||
  85. (currentQuestion.questionType === 1 && selectedOption === null) ||
  86. (currentQuestion.questionType === 2 && selectedOptions.length === 0)
  87. ">
  88. {{showResult ? '下一题' : '提交答案'}}
  89. </button>
  90. </view>
  91. </view>
  92. </view>
  93. <!-- 底部控制栏 -->
  94. <!-- <view class="footer">
  95. <view class="timer">本题剩余 {{remainingTime}}</view>
  96. <view class="next-step">进入下一题</view>
  97. </view> -->
  98. <!-- 面试结束弹窗 -->
  99. <view class="interview-end-modal" v-if="showEndModal">
  100. <view class="modal-content">
  101. <view class="modal-title">测试已完成</view>
  102. <!-- <view class="score-display">{{score}}/{{totalQuestions}}</view>
  103. <view class="modal-message">您在本次测试中答了{{score}}道题目,共{{totalQuestions}}道题目。</view> -->
  104. <view class="modal-buttons">
  105. <!-- <button type="default" class="modal-button" @click="restartTest">重新测试</button> -->
  106. <button type="primary" class="modal-button" @click="navigateToInterview">进入面试</button>
  107. </view>
  108. </view>
  109. </view>
  110. <!-- AI面试结束页面 -->
  111. <view class="interview-complete-screen" v-if="interviewCompleted">
  112. <view class="digital-avatar-large">
  113. <image src="/static/avatar.png" mode="aspectFill" class="avatar-image-large"></image>
  114. </view>
  115. <view class="complete-message">AI面试已结束</view>
  116. <view class="complete-description">本次面试的全部环节已结束。非常感谢您的参与。</view>
  117. <button class="complete-button" @click="back">我知道了</button>
  118. </view>
  119. <!-- 在模板中添加一个测试按钮(开发时使用,发布前删除) -->
  120. <!-- <button @click="testEndScreen" style="position: absolute; top: 10px; right: 10px; z-index: 9999;">测试结束页</button> -->
  121. <!-- 添加加载状态 -->
  122. <view class="loading-container" v-if="loading">
  123. <uni-load-more status="loading" :contentText="{contentdown: '加载中...'}" />
  124. <text class="loading-text">正在加载面试题目...</text>
  125. </view>
  126. <!-- 添加加载错误提示 -->
  127. <view class="loading-container" v-if="!loading && loadError">
  128. <view class="error-container">
  129. <text class="error-message">加载面试题目失败</text>
  130. <button class="retry-button" @click="fetchInterviewData">重试</button>
  131. </view>
  132. </view>
  133. </view>
  134. </template>
  135. <script>
  136. import { getInterviewList, getInterviewDetail } from '@/api/user.js';
  137. export default {
  138. data() {
  139. return {
  140. cameraContext: null,
  141. devicePosition: 'front',
  142. interviewStarted: true,
  143. showEndModal: false,
  144. currentQuestionIndex: 0,
  145. currentStep: 1,
  146. stepTexts: ['测试准备', '回答问题', '测试结束'],
  147. progressWidth: 50,
  148. remainingTime: '00:27',
  149. selectedOption: null,
  150. selectedOptions: [],
  151. showResult: false,
  152. isAnswerCorrect: false,
  153. questions: [], // 改为空数组,将通过API获取
  154. interviewId: null, // 存储当前面试ID
  155. useVideo: false,
  156. timerInterval: null,
  157. score: 0,
  158. totalQuestions: 0,
  159. interviewCompleted: false,
  160. digitalHumanUrl: '', // 数字人URL
  161. loading: true, // 添加加载状态
  162. loadError: false, // 添加加载错误状态
  163. errorMessage: '', // 添加错误消息
  164. answers: [], // 存储用户的所有答案
  165. currentQuestionDetail: null, // 当前题目详情
  166. isSubmitting: false, // 是否正在提交答案
  167. openQuestionAnswer: '', // 存储开放问题的答案
  168. currentAnswer: null, // 存储当前答案以便提交
  169. questionStartTime: null, // 存储问题开始时间
  170. }
  171. },
  172. computed: {
  173. currentQuestion() {
  174. console.log(this.questions[this.currentQuestionIndex]);
  175. return this.questions[this.currentQuestionIndex];
  176. }
  177. },
  178. onLoad(options) {
  179. // 从路由参数中获取面试ID
  180. if (options && options.id) {
  181. this.interviewId = options.id;
  182. this.fetchInterviewData();
  183. } else {
  184. // 如果没有ID,可以获取面试列表并使用第一个
  185. this.fetchInterviewList();
  186. }
  187. },
  188. onReady() {
  189. // 创建相机上下文
  190. this.cameraContext = uni.createCameraContext();
  191. // 创建AI视频上下文
  192. if (this.useVideo) {
  193. this.aiVideoContext = uni.createVideoContext('aiInterviewer');
  194. }
  195. // 初始化数字人
  196. this.initDigitalHuman();
  197. },
  198. methods: {
  199. // 获取面试列表
  200. async fetchInterviewList() {
  201. try {
  202. this.loading = true;
  203. const res = await getInterviewList({job_id:JSON.parse(uni.getStorageSync('selectedJob')).id});
  204. console.log(res);
  205. // 使用第一个面试
  206. this.interviewId = res//[0].id;
  207. this.fetchInterviewData(res);
  208. } catch (error) {
  209. console.error('获取面试列表失败:', error);
  210. this.handleLoadError('获取面试列表失败');
  211. }
  212. },
  213. // 获取面试详情数据
  214. async fetchInterviewData(data) {
  215. try {
  216. this.loading = true;
  217. // const res = await getInterviewDetail({ id: this.interviewId });
  218. // console.log('API返回数据:', res);
  219. // 如果返回的是问题列表
  220. if (data && Array.isArray(data)) {
  221. // 处理多个问题
  222. this.questions =data.map((q, index) => ({
  223. id: q.id || index + 1,
  224. text: q.question || '未知问题',
  225. options:q.options || [],
  226. correctAnswer: q.correctAnswer || 0,
  227. isImportant: q.is_system || false,
  228. explanation: q.explanation || '',
  229. questionType: q.question_form,
  230. questionTypeName: q.question_form_name || '单选题',
  231. correctAnswers: q.correct_answers || [],
  232. difficulty: q.difficulty || 1,
  233. difficultyName: q.difficulty_name || '初级'
  234. }));
  235. } else {
  236. // 处理单个问题
  237. this.processInterviewData(res);
  238. }
  239. console.log(this.questions);
  240. // 设置总题目数
  241. this.totalQuestions = this.questions.length;
  242. // 启动倒计时
  243. if (this.questions.length > 0) {
  244. this.startTimer();
  245. }
  246. } catch (error) {
  247. console.error('获取面试详情失败:', error);
  248. this.handleLoadError('获取面试详情失败');
  249. } finally {
  250. this.loading = false;
  251. }
  252. },
  253. // 处理面试数据
  254. processInterviewData(data) {
  255. // 清空现有问题列表
  256. this.questions = [];
  257. // 检查数据格式并处理
  258. if (data) {
  259. // 创建一个格式化的问题对象
  260. const formattedQuestion = {
  261. id: data.id || 1,
  262. text: data.question || '未知问题',
  263. options: data.options || [],
  264. correctAnswer: data.correctAnswer || 0,
  265. isImportant: data.is_system || false,
  266. explanation: data.explanation || '',
  267. questionType: data.question_form, // 1-单选题,2-多选题
  268. questionTypeName: data.question_form_name || '单选题',
  269. correctAnswers: data.correct_answers || [],
  270. difficulty: data.difficulty || 1,
  271. difficultyName: data.difficulty_name || '初级'
  272. };
  273. // 添加到问题列表
  274. this.questions.push(formattedQuestion);
  275. // 设置总题目数
  276. this.totalQuestions = this.questions.length;
  277. // 启动倒计时
  278. this.startTimer();
  279. } else {
  280. this.handleLoadError('面试中没有问题');
  281. }
  282. },
  283. // 处理加载错误
  284. handleLoadError(message) {
  285. this.loadError = true;
  286. this.loading = false;
  287. this.errorMessage = message || '加载失败';
  288. uni.showToast({
  289. title: message || '加载失败',
  290. icon: 'none',
  291. duration: 2000
  292. });
  293. },
  294. startTimer() {
  295. // 确保问题已加载
  296. if (this.questions.length === 0) return;
  297. // 记录开始时间
  298. this.questionStartTime = new Date();
  299. // 模拟倒计时
  300. let seconds = 30; // 每题30秒
  301. this.timerInterval = setInterval(() => {
  302. seconds--;
  303. if (seconds <= 0) {
  304. clearInterval(this.timerInterval);
  305. // 时间到,自动提交答案
  306. if (!this.showResult) {
  307. this.checkAnswer();
  308. }
  309. }
  310. const min = Math.floor(seconds / 60).toString().padStart(2, '0');
  311. const sec = (seconds % 60).toString().padStart(2, '0');
  312. this.remainingTime = `${min}:${sec}`;
  313. }, 1000);
  314. },
  315. resetTimer() {
  316. clearInterval(this.timerInterval);
  317. this.startTimer();
  318. },
  319. selectOption(index) {
  320. if (this.showResult) return; // 已显示结果时不能再选择
  321. // 判断当前题目类型
  322. if (this.currentQuestion.questionType === 2) { // 多选题
  323. // 如果已经选中,则取消选中
  324. const optionIndex = this.selectedOptions.indexOf(index);
  325. if (optionIndex > -1) {
  326. this.selectedOptions.splice(optionIndex, 1);
  327. } else {
  328. // 否则添加到已选中数组
  329. this.selectedOptions.push(index);
  330. }
  331. } else if (this.currentQuestion.questionType === 1) { // 单选题
  332. this.selectedOption = index;
  333. }
  334. this.playAiSpeaking();
  335. },
  336. checkAnswer() {
  337. clearInterval(this.timerInterval); // 停止计时
  338. // 确保当前问题存在
  339. if (!this.currentQuestion) {
  340. console.error('当前问题不存在');
  341. return;
  342. }
  343. // 根据题目类型检查答案是否正确
  344. if (this.currentQuestion.questionType === 0) { // 开放问题
  345. // 开放问题没有标准答案,可以根据需要设置为正确或待评估
  346. this.isAnswerCorrect = true; // 或者设置为 null 表示待评估
  347. } else if (this.currentQuestion.questionType === 2) { // 多选题
  348. const sortedSelected = [...this.selectedOptions].sort();
  349. const sortedCorrect = [...this.currentQuestion.correctAnswers].sort();
  350. if (sortedSelected.length !== sortedCorrect.length) {
  351. this.isAnswerCorrect = false;
  352. } else {
  353. this.isAnswerCorrect = sortedSelected.every((value, index) => value === sortedCorrect[index]);
  354. }
  355. } else { // 单选题
  356. this.isAnswerCorrect = this.selectedOption === this.currentQuestion.correctAnswer;
  357. }
  358. // 显示结果
  359. this.showResult = true;
  360. },
  361. nextQuestion(data) {
  362. // 如果还没有显示结果,先检查答案并提交
  363. if (!this.showResult) {
  364. this.checkAnswer();
  365. // 保存当前题目的答案并立即提交
  366. this.saveAnswer(data);
  367. this.submitCurrentAnswer(data).then(() => {
  368. // 提交成功后显示结果
  369. this.showResult = true;
  370. }).catch(error => {
  371. console.error('提交答案失败:', error);
  372. uni.showToast({
  373. title: '提交答案失败,请重试',
  374. icon: 'none'
  375. });
  376. // 即使提交失败也显示结果
  377. this.showResult = true;
  378. });
  379. return;
  380. }
  381. // 如果已经显示结果,点击"下一题"按钮时执行
  382. // 如果是最后一题,直接跳转到手部照片采集页面
  383. if (this.currentQuestionIndex >= this.questions.length - 1) {
  384. // 直接跳转到手部照片采集页面,不显示结束模态框
  385. uni.navigateTo({
  386. url: '/pages/interview/interview', // 假设这是手部照片采集页面的路径
  387. success: () => {
  388. console.log('成功跳转到手部照片采集页面');
  389. },
  390. fail: (err) => {
  391. console.error('跳转失败:', err);
  392. uni.showToast({
  393. title: '跳转失败,请手动返回首页',
  394. icon: 'none'
  395. });
  396. }
  397. });
  398. return;
  399. }
  400. // 前往下一题
  401. this.goToNextQuestion();
  402. },
  403. // 保存当前题目的答案
  404. saveAnswer() {
  405. let answer;
  406. if (this.currentQuestion.questionType === 0) { // 开放问题
  407. answer = {
  408. questionId: this.currentQuestion.id,
  409. questionType: this.currentQuestion.questionType,
  410. answer: this.openQuestionAnswer,
  411. answerDuration: this.getAnswerDuration() // 添加答题时长
  412. };
  413. } else { // 单选或多选
  414. answer = {
  415. questionId: this.currentQuestion.id,
  416. questionType: this.currentQuestion.questionType,
  417. answer: this.currentQuestion.questionType === 1 ?
  418. this.selectedOption : this.selectedOptions,
  419. answerDuration: this.getAnswerDuration() // 添加答题时长
  420. };
  421. }
  422. // 检查是否已存在该题目的答案,如果存在则更新
  423. const existingIndex = this.answers.findIndex(a => a.questionId === answer.questionId);
  424. if (existingIndex > -1) {
  425. this.answers[existingIndex] = answer;
  426. } else {
  427. this.answers.push(answer);
  428. }
  429. // 保存当前答案以便提交
  430. this.currentAnswer = answer;
  431. console.log('已保存答案:', this.answers);
  432. },
  433. // 获取答题时长(秒)
  434. getAnswerDuration() {
  435. // 这里假设每题默认30秒,根据剩余时间计算用时
  436. // 您可以根据实际情况调整计算逻辑
  437. const remainingTimeArr = this.remainingTime.split(':');
  438. const remainingSeconds = parseInt(remainingTimeArr[0]) * 60 + parseInt(remainingTimeArr[1]);
  439. return 30 - remainingSeconds; // 假设每题30秒
  440. },
  441. // 提交当前答案
  442. async submitCurrentAnswer() {
  443. if (!this.currentAnswer) return;
  444. try {
  445. // 显示提交中提示
  446. uni.showLoading({
  447. title: '正在提交答案...'
  448. });
  449. // 构建提交数据
  450. let answerContent = '';
  451. if (this.currentAnswer.questionType === 0) {
  452. // 开放题直接使用文本答案
  453. answerContent = this.currentAnswer.answer;
  454. } else if (this.currentAnswer.questionType === 1) {
  455. // 单选题,获取选项ID而不是索引
  456. const selectedIndex = this.currentAnswer.answer;
  457. const selectedOption = this.currentQuestion.options[selectedIndex];
  458. // 使用选项的ID或其他唯一标识符
  459. answerContent = selectedOption.id ? selectedOption.id.toString() : selectedIndex.toString();
  460. } else if (this.currentAnswer.questionType === 2) {
  461. // 多选题,将选项ID数组转为逗号分隔的字符串
  462. const selectedIndices = this.currentAnswer.answer;
  463. const selectedOptionIds = selectedIndices.map(index => {
  464. const option = this.currentQuestion.options[index];
  465. // 使用选项的ID或其他唯一标识符
  466. return option.id ? option.id : index;
  467. });
  468. answerContent = selectedOptionIds.join(',');
  469. }
  470. const submitData = {
  471. application_id: 1, // 或者使用其他合适的ID
  472. question_id: this.currentAnswer.questionId,
  473. answer_content: answerContent,
  474. answer_duration: this.currentAnswer.answerDuration || 0,
  475. // 如果需要tenant_id,请在这里添加
  476. tenant_id: 1
  477. };
  478. console.log('提交数据:', submitData);
  479. // 调用API提交答案
  480. const res = await this.$http.post('http://192.168.66.187:8083/api/job/submit_answer', submitData);
  481. console.log('提交答案响应:', res);
  482. // 隐藏加载提示
  483. uni.hideLoading();
  484. return res;
  485. } catch (error) {
  486. console.error('提交答案失败:', error);
  487. // 隐藏加载提示
  488. uni.hideLoading();
  489. // 显示错误提示
  490. uni.showToast({
  491. title: '提交答案失败,请重试',
  492. icon: 'none'
  493. });
  494. throw error;
  495. }
  496. },
  497. // 修改 goToNextQuestion 方法,添加 async 关键字
  498. async goToNextQuestion() {
  499. // 重置状态
  500. this.showResult = false;
  501. this.selectedOption = null;
  502. this.selectedOptions = [];
  503. this.openQuestionAnswer = ''; // 重置开放问题答案
  504. // 前往下一题
  505. this.currentQuestionIndex++;
  506. // 如果已经有下一题的详情,直接使用
  507. if (this.questions[this.currentQuestionIndex]) {
  508. // 更新进度
  509. this.progressWidth = (this.currentQuestionIndex + 1) / this.questions.length * 100;
  510. // 重置计时器
  511. this.resetTimer();
  512. // 播放AI介绍下一题
  513. this.playAiSpeaking();
  514. setTimeout(() => {
  515. this.pauseAiSpeaking();
  516. }, 2000);
  517. return;
  518. }
  519. // 否则请求下一题详情
  520. try {
  521. this.loading = true;
  522. // 假设您有一个获取单个题目详情的API
  523. // const res = await getQuestionDetail({
  524. // interviewId: this.interviewId,
  525. // questionIndex: this.currentQuestionIndex
  526. // });
  527. // 模拟API调用
  528. await new Promise(resolve => setTimeout(resolve, 1000));
  529. const res = { /* 模拟的题目数据 */ };
  530. // 处理题目数据
  531. if (res) {
  532. const formattedQuestion = {
  533. id: res.id || this.currentQuestionIndex + 1,
  534. text: res.question || '未知问题',
  535. options: res.options || [],
  536. correctAnswer: res.correctAnswer || 0,
  537. isImportant: res.is_system || false,
  538. explanation: res.explanation || '',
  539. questionType: res.question_form || 1,
  540. questionTypeName: res.question_form_name || '单选题',
  541. correctAnswers: res.correct_answers || [],
  542. difficulty: res.difficulty || 1,
  543. difficultyName: res.difficulty_name || '初级'
  544. };
  545. // 添加到问题列表
  546. this.questions.push(formattedQuestion);
  547. }
  548. } catch (error) {
  549. console.error('获取题目详情失败:', error);
  550. uni.showToast({
  551. title: '获取题目失败,请重试',
  552. icon: 'none'
  553. });
  554. // 出错时回到上一题
  555. this.currentQuestionIndex--;
  556. } finally {
  557. this.loading = false;
  558. // 更新进度
  559. this.progressWidth = (this.currentQuestionIndex + 1) / this.questions.length * 100;
  560. // 重置计时器
  561. this.resetTimer();
  562. }
  563. },
  564. toggleSettings() {
  565. // 打开设置面板
  566. uni.showToast({
  567. title: '设置功能开发中',
  568. icon: 'none'
  569. });
  570. },
  571. back(target) {
  572. // 清除计时器
  573. if (this.timerInterval) {
  574. clearInterval(this.timerInterval);
  575. }
  576. // 如果指定了跳转目标
  577. if (target) {
  578. uni.navigateTo({
  579. url: target
  580. });
  581. return;
  582. }
  583. // 否则尝试返回上一页,如果失败则跳转到首页
  584. try {
  585. const pages = getCurrentPages();
  586. if (pages.length > 1) {
  587. uni.reLaunch({
  588. url: '/pages/index/index'
  589. });
  590. } else {
  591. // 如果当前是第一页,则跳转到首页
  592. uni.reLaunch({
  593. url: '/pages/index/index'
  594. });
  595. }
  596. } catch (e) {
  597. console.error('导航错误:', e);
  598. // 出错时也跳转到首页
  599. uni.reLaunch({
  600. url: '/pages/index/index'
  601. });
  602. }
  603. },
  604. error(e) {
  605. // 相机错误事件
  606. console.error(e.detail);
  607. uni.showToast({
  608. title: '相机启动失败,请检查权限设置',
  609. icon: 'none'
  610. });
  611. },
  612. playAiSpeaking() {
  613. if (this.useVideo && this.aiVideoContext) {
  614. this.aiVideoContext.play();
  615. }
  616. // 触发数字人说话动画
  617. if (this.digitalHumanUrl) {
  618. // 假设当前问题的文本作为数字人要说的内容
  619. const speakText = this.currentQuestion ? this.currentQuestion.text : '';
  620. this.interactWithDigitalHuman(speakText);
  621. }
  622. },
  623. pauseAiSpeaking() {
  624. if (this.useVideo && this.aiVideoContext) {
  625. this.aiVideoContext.pause();
  626. }
  627. },
  628. // 修改 restartTest 方法,添加可选的跳转目标
  629. restartTest(target) {
  630. this.currentQuestionIndex = 0;
  631. this.score = 0;
  632. this.showEndModal = false;
  633. this.showResult = false;
  634. this.selectedOption = null;
  635. this.selectedOptions = [];
  636. this.resetTimer();
  637. // 如果指定了跳转目标
  638. if (target) {
  639. uni.navigateTo({
  640. url: target
  641. });
  642. }
  643. },
  644. // 在methods中添加测试方法
  645. testEndScreen() {
  646. this.interviewCompleted = true;
  647. this.showEndModal = false;
  648. },
  649. // 初始化数字人
  650. initDigitalHuman() {
  651. // 移除不可用的示例URL
  652. // this.digitalHumanUrl = 'https://your-digital-human-service.com/avatar?id=123';
  653. // 暂时不使用数字人服务,直接使用本地图片
  654. this.digitalHumanUrl = '';
  655. // 如果您有实际可用的数字人服务,可以在这里设置
  656. // 例如:this.digitalHumanUrl = 'https://your-actual-service.com/avatar';
  657. // 或者使用本地HTML文件(如果有的话)
  658. // this.digitalHumanUrl = '/hybrid/html/digital-human.html';
  659. },
  660. // 与数字人交互的方法
  661. interactWithDigitalHuman(message) {
  662. // 如果数字人是通过web-view加载的,可以使用postMessage与其通信
  663. const webview = this.$mp.page.$getAppWebview().children()[0];
  664. if (webview) {
  665. webview.evalJS(`receiveMessage('${message}')`);
  666. }
  667. },
  668. // 添加 navigateToInterview 方法
  669. navigateToInterview() {
  670. // 关闭模态框
  671. this.showEndModal = false;
  672. // 跳转到interview页面
  673. uni.navigateTo({
  674. url: '/pages/interview/interview',
  675. success: () => {
  676. console.log('成功跳转到interview页面');
  677. },
  678. fail: (err) => {
  679. console.error('跳转失败:', err);
  680. uni.showToast({
  681. title: '跳转失败,请手动返回首页',
  682. icon: 'none'
  683. });
  684. }
  685. });
  686. }
  687. },
  688. // 添加生命周期钩子,确保在组件销毁时清除计时器
  689. beforeDestroy() {
  690. if (this.timerInterval) {
  691. clearInterval(this.timerInterval);
  692. }
  693. }
  694. }
  695. </script>
  696. <style>
  697. .camera-container {
  698. position: relative;
  699. width: 100%;
  700. height: 100vh;
  701. background-color: #ffffff;
  702. display: flex;
  703. flex-direction: column;
  704. }
  705. .header {
  706. height: 90rpx;
  707. /* background-color: #000000; */
  708. display: flex;
  709. align-items: center;
  710. padding: 0 30rpx;
  711. /* color: #ffffff; */
  712. }
  713. .back-button {
  714. width: 60rpx;
  715. height: 60rpx;
  716. display: flex;
  717. align-items: center;
  718. justify-content: center;
  719. }
  720. .title {
  721. flex: 1;
  722. text-align: center;
  723. font-size: 32rpx;
  724. font-weight: bold;
  725. }
  726. .controls {
  727. display: flex;
  728. gap: 30rpx;
  729. }
  730. .iconfont {
  731. font-size: 40rpx;
  732. }
  733. .content {
  734. flex: 1;
  735. display: flex;
  736. flex-direction: column;
  737. position: relative;
  738. padding: 50rpx 20rpx 0;
  739. }
  740. .progress-container {
  741. display: flex;
  742. flex-direction: column;
  743. justify-content: space-between;
  744. margin-bottom: 20rpx;
  745. }
  746. .progress-step {
  747. display: flex;
  748. align-items: center;
  749. margin-bottom: 10rpx;
  750. }
  751. .step-circle {
  752. width: 40rpx;
  753. height: 40rpx;
  754. border-radius: 50%;
  755. background-color: #e0e0e0;
  756. display: flex;
  757. align-items: center;
  758. justify-content: center;
  759. font-size: 24rpx;
  760. margin-right: 10rpx;
  761. }
  762. .step-circle.active {
  763. background-color: #ff9500;
  764. color: #ffffff;
  765. }
  766. .step-text {
  767. font-size: 24rpx;
  768. color: #666666;
  769. }
  770. .progress-bar {
  771. height: 10rpx;
  772. background-color: #e0e0e0;
  773. border-radius: 5rpx;
  774. overflow: hidden;
  775. margin-bottom: 20rpx;
  776. }
  777. .progress-fill {
  778. height: 100%;
  779. background-color: #00c853;
  780. transition: width 0.3s;
  781. }
  782. .interview-content {
  783. flex: 1;
  784. display: flex;
  785. flex-direction: column;
  786. }
  787. .video-area {
  788. display: flex;
  789. /* flex-direction: column; */
  790. justify-content: space-between;
  791. height: auto;
  792. margin-bottom: 20rpx;
  793. }
  794. .video-camera {
  795. display: flex;
  796. flex-direction: row;
  797. align-items: center;
  798. justify-content: space-between;
  799. width: 65%;
  800. }
  801. .interviewer {
  802. background-color: #f5f5f5;
  803. display: flex;
  804. align-items: center;
  805. justify-content: center;
  806. position: relative;
  807. width: 48% !important;
  808. height: 300rpx;
  809. }
  810. .interviewer-video {
  811. width: 100%;
  812. height: 100%;
  813. object-fit: cover;
  814. }
  815. .interviewer-avatar {
  816. width: 80%;
  817. height: 80%;
  818. object-fit: contain;
  819. }
  820. .user-camera-container {
  821. width: 48%;
  822. height: 300rpx;
  823. border-radius: 10rpx;
  824. overflow: hidden;
  825. border: 4rpx solid #ffffff;
  826. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.2);
  827. }
  828. .question-area {
  829. flex: 1;
  830. display: flex;
  831. flex-direction: column;
  832. }
  833. .question-number {
  834. font-size: 28rpx;
  835. color: #666;
  836. margin-bottom: 20rpx;
  837. }
  838. .question-importance {
  839. background-color: #f9f9f9;
  840. padding: 20rpx;
  841. border-radius: 10rpx;
  842. margin-bottom: 20rpx;
  843. font-size: 28rpx;
  844. color: #333;
  845. }
  846. .question-importance text {
  847. color: #ff0000;
  848. margin-right: 10rpx;
  849. }
  850. .options {
  851. display: flex;
  852. flex-direction: column;
  853. gap: 20rpx;
  854. margin-bottom: 30rpx;
  855. }
  856. .option-item {
  857. padding: 20rpx;
  858. background-color: #f5f5f5;
  859. border-radius: 10rpx;
  860. font-size: 28rpx;
  861. transition: all 0.3s;
  862. border: 1px solid #e0e0e0;
  863. }
  864. .option-selected {
  865. background-color: #e6f7ff;
  866. border: 1px solid #1890ff;
  867. }
  868. .option-correct {
  869. background-color: #d4f7d4;
  870. border: 1px solid #52c41a;
  871. }
  872. .option-wrong {
  873. background-color: #fff1f0;
  874. border: 1px solid #ff4d4f;
  875. }
  876. .option-text {
  877. color: #333;
  878. }
  879. .timer-container {
  880. text-align: center;
  881. margin: 20rpx 0;
  882. }
  883. .timer-text {
  884. font-size: 24rpx;
  885. color: #666;
  886. }
  887. .next-button {
  888. background-color: #6c5ce7;
  889. color: #ffffff;
  890. border-radius: 10rpx;
  891. font-size: 30rpx;
  892. margin: 20rpx auto;
  893. height: 80rpx;
  894. line-height: 80rpx;
  895. width: 90%;
  896. text-align: center;
  897. }
  898. .next-button[disabled] {
  899. background-color: #cccccc;
  900. color: #999999;
  901. }
  902. .footer {
  903. height: 100rpx;
  904. background-color: #000000;
  905. display: flex;
  906. justify-content: space-between;
  907. align-items: center;
  908. padding: 0 30rpx;
  909. color: #ffffff;
  910. }
  911. .timer {
  912. font-size: 28rpx;
  913. }
  914. .next-step {
  915. font-size: 28rpx;
  916. }
  917. .interview-end-modal {
  918. position: fixed;
  919. top: 0;
  920. left: 0;
  921. right: 0;
  922. bottom: 0;
  923. background-color: rgba(0, 0, 0, 0.5);
  924. display: flex;
  925. align-items: center;
  926. justify-content: center;
  927. z-index: 999;
  928. }
  929. .modal-content {
  930. width: 80%;
  931. background-color: #ffffff;
  932. border-radius: 20rpx;
  933. padding: 40rpx;
  934. display: flex;
  935. flex-direction: column;
  936. align-items: center;
  937. }
  938. .modal-title {
  939. font-size: 36rpx;
  940. font-weight: bold;
  941. margin-bottom: 30rpx;
  942. }
  943. .score-display {
  944. font-size: 48rpx;
  945. font-weight: bold;
  946. color: #6c5ce7;
  947. margin: 20rpx 0;
  948. }
  949. .modal-message {
  950. font-size: 28rpx;
  951. color: #666;
  952. text-align: center;
  953. margin-bottom: 40rpx;
  954. }
  955. .modal-buttons {
  956. display: flex;
  957. justify-content: space-between;
  958. width: 100%;
  959. margin-top: 20rpx;
  960. }
  961. .modal-button {
  962. width: 45%;
  963. }
  964. @keyframes speaking {
  965. 0% {
  966. opacity: 0.8;
  967. }
  968. 50% {
  969. opacity: 1;
  970. }
  971. 100% {
  972. opacity: 0.8;
  973. }
  974. }
  975. .speaking {
  976. animation: speaking 1.5s infinite;
  977. }
  978. .digital-avatar {
  979. width: 120rpx;
  980. height: 120rpx;
  981. z-index: 10;
  982. overflow: hidden;
  983. }
  984. .avatar-image {
  985. width: 120rpx;
  986. height: 120rpx;
  987. border-radius: 20rpx;
  988. border: 2rpx solid #e0e0e0;
  989. }
  990. .digital-human-webview {
  991. width: 120rpx;
  992. height: 120rpx;
  993. border-radius: 20rpx;
  994. border: 2rpx solid #e0e0e0;
  995. }
  996. .interview-complete-screen {
  997. position: fixed;
  998. top: 0;
  999. left: 0;
  1000. right: 0;
  1001. bottom: 0;
  1002. background-color: #f0f5ff;
  1003. display: flex;
  1004. flex-direction: column;
  1005. align-items: center;
  1006. justify-content: center;
  1007. z-index: 1000;
  1008. padding: 40rpx;
  1009. }
  1010. .digital-avatar-large {
  1011. width: 200rpx;
  1012. height: 200rpx;
  1013. margin-bottom: 60rpx;
  1014. }
  1015. .avatar-image-large {
  1016. width: 100%;
  1017. height: 100%;
  1018. border-radius: 30rpx;
  1019. }
  1020. .complete-message {
  1021. font-size: 40rpx;
  1022. font-weight: bold;
  1023. color: #333;
  1024. margin-bottom: 30rpx;
  1025. }
  1026. .complete-description {
  1027. font-size: 28rpx;
  1028. color: #666;
  1029. text-align: center;
  1030. margin-bottom: 80rpx;
  1031. line-height: 1.5;
  1032. }
  1033. .complete-button {
  1034. background-color: #6c5ce7;
  1035. color: #ffffff;
  1036. border-radius: 10rpx;
  1037. font-size: 32rpx;
  1038. padding: 20rpx 60rpx;
  1039. margin-top: 40rpx;
  1040. }
  1041. /* 添加加载状态样式 */
  1042. .loading-container {
  1043. position: absolute;
  1044. top: 0;
  1045. left: 0;
  1046. right: 0;
  1047. bottom: 0;
  1048. display: flex;
  1049. flex-direction: column;
  1050. align-items: center;
  1051. justify-content: center;
  1052. background-color: rgba(255, 255, 255, 0.9);
  1053. z-index: 100;
  1054. }
  1055. .loading-text {
  1056. margin-top: 20rpx;
  1057. font-size: 28rpx;
  1058. color: #666;
  1059. }
  1060. .error-container {
  1061. text-align: center;
  1062. }
  1063. .error-message {
  1064. font-size: 28rpx;
  1065. color: #ff4d4f;
  1066. margin-bottom: 30rpx;
  1067. }
  1068. .retry-button {
  1069. background-color: #6c5ce7;
  1070. color: #ffffff;
  1071. border-radius: 10rpx;
  1072. font-size: 28rpx;
  1073. padding: 10rpx 30rpx;
  1074. }
  1075. .question-type {
  1076. display: inline-block;
  1077. background-color: #6c5ce7;
  1078. color: white;
  1079. font-size: 24rpx;
  1080. padding: 4rpx 10rpx;
  1081. border-radius: 6rpx;
  1082. margin-right: 10rpx;
  1083. }
  1084. /* 新增的开放问题样式 */
  1085. .open-question-container {
  1086. display: flex;
  1087. flex-direction: column;
  1088. width: 100%;
  1089. margin-bottom: 20rpx;
  1090. }
  1091. .open-question-input {
  1092. width: 100%;
  1093. height: 300rpx;
  1094. background-color: #f9f9f9;
  1095. border: 1px solid #e0e0e0;
  1096. border-radius: 10rpx;
  1097. padding: 20rpx;
  1098. font-size: 28rpx;
  1099. color: #333;
  1100. }
  1101. .word-count {
  1102. text-align: right;
  1103. font-size: 24rpx;
  1104. color: #999;
  1105. margin-top: 10rpx;
  1106. }
  1107. .option-prefix {
  1108. margin-right: 10rpx;
  1109. color: #6c5ce7;
  1110. font-weight: bold;
  1111. }
  1112. </style>