camera.vue 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  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}}-{{currentQuestion.id}}/{{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="back">返回首页</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();
  204. console.log(res);
  205. // 使用第一个面试
  206. this.interviewId = res.items//[0].id;
  207. this.fetchInterviewData(res.items);
  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. return;
  366. }
  367. // 保存当前题目的答案并提交
  368. this.saveAnswer(data);
  369. this.submitCurrentAnswer(data).then(() => {
  370. // 如果是最后一题,显示结果页面
  371. if (this.currentQuestionIndex >= this.questions.length - 1) {
  372. this.showEndModal = true;
  373. return;
  374. }
  375. // 前往下一题
  376. this.goToNextQuestion();
  377. }).catch(error => {
  378. console.error('提交答案失败:', error);
  379. uni.showToast({
  380. title: '提交答案失败,请重试',
  381. icon: 'none'
  382. });
  383. });
  384. },
  385. // 保存当前题目的答案
  386. saveAnswer() {
  387. let answer;
  388. if (this.currentQuestion.questionType === 0) { // 开放问题
  389. answer = {
  390. questionId: this.currentQuestion.id,
  391. questionType: this.currentQuestion.questionType,
  392. answer: this.openQuestionAnswer,
  393. answerDuration: this.getAnswerDuration() // 添加答题时长
  394. };
  395. } else { // 单选或多选
  396. answer = {
  397. questionId: this.currentQuestion.id,
  398. questionType: this.currentQuestion.questionType,
  399. answer: this.currentQuestion.questionType === 1 ?
  400. this.selectedOption : this.selectedOptions,
  401. answerDuration: this.getAnswerDuration() // 添加答题时长
  402. };
  403. }
  404. // 检查是否已存在该题目的答案,如果存在则更新
  405. const existingIndex = this.answers.findIndex(a => a.questionId === answer.questionId);
  406. if (existingIndex > -1) {
  407. this.answers[existingIndex] = answer;
  408. } else {
  409. this.answers.push(answer);
  410. }
  411. // 保存当前答案以便提交
  412. this.currentAnswer = answer;
  413. console.log('已保存答案:', this.answers);
  414. },
  415. // 获取答题时长(秒)
  416. getAnswerDuration() {
  417. // 这里假设每题默认30秒,根据剩余时间计算用时
  418. // 您可以根据实际情况调整计算逻辑
  419. const remainingTimeArr = this.remainingTime.split(':');
  420. const remainingSeconds = parseInt(remainingTimeArr[0]) * 60 + parseInt(remainingTimeArr[1]);
  421. return 30 - remainingSeconds; // 假设每题30秒
  422. },
  423. // 提交当前答案
  424. async submitCurrentAnswer() {
  425. if (!this.currentAnswer) return;
  426. try {
  427. // 显示提交中提示
  428. uni.showLoading({
  429. title: '正在提交答案...'
  430. });
  431. // 构建提交数据
  432. let answerContent = '';
  433. if (this.currentAnswer.questionType === 0) {
  434. // 开放题直接使用文本答案
  435. answerContent = this.currentAnswer.answer;
  436. } else if (this.currentAnswer.questionType === 1) {
  437. // 单选题,获取选项ID而不是索引
  438. const selectedIndex = this.currentAnswer.answer;
  439. const selectedOption = this.currentQuestion.options[selectedIndex];
  440. // 使用选项的ID或其他唯一标识符
  441. answerContent = selectedOption.id ? selectedOption.id.toString() : selectedIndex.toString();
  442. } else if (this.currentAnswer.questionType === 2) {
  443. // 多选题,将选项ID数组转为逗号分隔的字符串
  444. const selectedIndices = this.currentAnswer.answer;
  445. const selectedOptionIds = selectedIndices.map(index => {
  446. const option = this.currentQuestion.options[index];
  447. // 使用选项的ID或其他唯一标识符
  448. return option.id ? option.id : index;
  449. });
  450. answerContent = selectedOptionIds.join(',');
  451. }
  452. const submitData = {
  453. application_id: 1, // 或者使用其他合适的ID
  454. question_id: this.currentAnswer.questionId,
  455. answer_content: answerContent,
  456. answer_duration: this.currentAnswer.answerDuration || 0,
  457. // 如果需要tenant_id,请在这里添加
  458. tenant_id: 1
  459. };
  460. console.log('提交数据:', submitData);
  461. // 调用API提交答案
  462. const res = await this.$http.post('http://192.168.66.187:8083/api/job/submit_answer', submitData);
  463. console.log('提交答案响应:', res);
  464. // 隐藏加载提示
  465. uni.hideLoading();
  466. return res;
  467. } catch (error) {
  468. console.error('提交答案失败:', error);
  469. // 隐藏加载提示
  470. uni.hideLoading();
  471. // 显示错误提示
  472. uni.showToast({
  473. title: '提交答案失败,请重试',
  474. icon: 'none'
  475. });
  476. throw error;
  477. }
  478. },
  479. // 修改 goToNextQuestion 方法,添加 async 关键字
  480. async goToNextQuestion() {
  481. // 重置状态
  482. this.showResult = false;
  483. this.selectedOption = null;
  484. this.selectedOptions = [];
  485. this.openQuestionAnswer = ''; // 重置开放问题答案
  486. // 前往下一题
  487. this.currentQuestionIndex++;
  488. // 如果已经有下一题的详情,直接使用
  489. if (this.questions[this.currentQuestionIndex]) {
  490. // 更新进度
  491. this.progressWidth = (this.currentQuestionIndex + 1) / this.questions.length * 100;
  492. // 重置计时器
  493. this.resetTimer();
  494. // 播放AI介绍下一题
  495. this.playAiSpeaking();
  496. setTimeout(() => {
  497. this.pauseAiSpeaking();
  498. }, 2000);
  499. return;
  500. }
  501. // 否则请求下一题详情
  502. try {
  503. this.loading = true;
  504. // 假设您有一个获取单个题目详情的API
  505. // const res = await getQuestionDetail({
  506. // interviewId: this.interviewId,
  507. // questionIndex: this.currentQuestionIndex
  508. // });
  509. // 模拟API调用
  510. await new Promise(resolve => setTimeout(resolve, 1000));
  511. const res = { /* 模拟的题目数据 */ };
  512. // 处理题目数据
  513. if (res) {
  514. const formattedQuestion = {
  515. id: res.id || this.currentQuestionIndex + 1,
  516. text: res.question || '未知问题',
  517. options: res.options || [],
  518. correctAnswer: res.correctAnswer || 0,
  519. isImportant: res.is_system || false,
  520. explanation: res.explanation || '',
  521. questionType: res.question_form || 1,
  522. questionTypeName: res.question_form_name || '单选题',
  523. correctAnswers: res.correct_answers || [],
  524. difficulty: res.difficulty || 1,
  525. difficultyName: res.difficulty_name || '初级'
  526. };
  527. // 添加到问题列表
  528. this.questions.push(formattedQuestion);
  529. }
  530. } catch (error) {
  531. console.error('获取题目详情失败:', error);
  532. uni.showToast({
  533. title: '获取题目失败,请重试',
  534. icon: 'none'
  535. });
  536. // 出错时回到上一题
  537. this.currentQuestionIndex--;
  538. } finally {
  539. this.loading = false;
  540. // 更新进度
  541. this.progressWidth = (this.currentQuestionIndex + 1) / this.questions.length * 100;
  542. // 重置计时器
  543. this.resetTimer();
  544. }
  545. },
  546. toggleSettings() {
  547. // 打开设置面板
  548. uni.showToast({
  549. title: '设置功能开发中',
  550. icon: 'none'
  551. });
  552. },
  553. back() {
  554. // 清除计时器
  555. if (this.timerInterval) {
  556. clearInterval(this.timerInterval);
  557. }
  558. // 尝试返回上一页,如果失败则跳转到首页
  559. try {
  560. const pages = getCurrentPages();
  561. if (pages.length > 1) {
  562. uni.reLaunch({
  563. url: '/pages/index/index'
  564. });
  565. } else {
  566. // 如果当前是第一页,则跳转到首页
  567. uni.reLaunch({
  568. url: '/pages/index/index'
  569. });
  570. }
  571. } catch (e) {
  572. console.error('导航错误:', e);
  573. // 出错时也跳转到首页
  574. uni.reLaunch({
  575. url: '/pages/index/index'
  576. });
  577. }
  578. },
  579. error(e) {
  580. // 相机错误事件
  581. console.error(e.detail);
  582. uni.showToast({
  583. title: '相机启动失败,请检查权限设置',
  584. icon: 'none'
  585. });
  586. },
  587. playAiSpeaking() {
  588. if (this.useVideo && this.aiVideoContext) {
  589. this.aiVideoContext.play();
  590. }
  591. // 触发数字人说话动画
  592. if (this.digitalHumanUrl) {
  593. // 假设当前问题的文本作为数字人要说的内容
  594. const speakText = this.currentQuestion ? this.currentQuestion.text : '';
  595. this.interactWithDigitalHuman(speakText);
  596. }
  597. },
  598. pauseAiSpeaking() {
  599. if (this.useVideo && this.aiVideoContext) {
  600. this.aiVideoContext.pause();
  601. }
  602. },
  603. // 重新开始测试
  604. restartTest() {
  605. this.currentQuestionIndex = 0;
  606. this.score = 0;
  607. this.showEndModal = false;
  608. this.showResult = false;
  609. this.selectedOption = null;
  610. this.selectedOptions = [];
  611. this.resetTimer();
  612. },
  613. // 在methods中添加测试方法
  614. testEndScreen() {
  615. this.interviewCompleted = true;
  616. this.showEndModal = false;
  617. },
  618. // 初始化数字人
  619. initDigitalHuman() {
  620. // 移除不可用的示例URL
  621. // this.digitalHumanUrl = 'https://your-digital-human-service.com/avatar?id=123';
  622. // 暂时不使用数字人服务,直接使用本地图片
  623. this.digitalHumanUrl = '';
  624. // 如果您有实际可用的数字人服务,可以在这里设置
  625. // 例如:this.digitalHumanUrl = 'https://your-actual-service.com/avatar';
  626. // 或者使用本地HTML文件(如果有的话)
  627. // this.digitalHumanUrl = '/hybrid/html/digital-human.html';
  628. },
  629. // 与数字人交互的方法
  630. interactWithDigitalHuman(message) {
  631. // 如果数字人是通过web-view加载的,可以使用postMessage与其通信
  632. const webview = this.$mp.page.$getAppWebview().children()[0];
  633. if (webview) {
  634. webview.evalJS(`receiveMessage('${message}')`);
  635. }
  636. }
  637. },
  638. // 添加生命周期钩子,确保在组件销毁时清除计时器
  639. beforeDestroy() {
  640. if (this.timerInterval) {
  641. clearInterval(this.timerInterval);
  642. }
  643. }
  644. }
  645. </script>
  646. <style>
  647. .camera-container {
  648. position: relative;
  649. width: 100%;
  650. height: 100vh;
  651. background-color: #ffffff;
  652. display: flex;
  653. flex-direction: column;
  654. }
  655. .header {
  656. height: 90rpx;
  657. /* background-color: #000000; */
  658. display: flex;
  659. align-items: center;
  660. padding: 0 30rpx;
  661. /* color: #ffffff; */
  662. }
  663. .back-button {
  664. width: 60rpx;
  665. height: 60rpx;
  666. display: flex;
  667. align-items: center;
  668. justify-content: center;
  669. }
  670. .title {
  671. flex: 1;
  672. text-align: center;
  673. font-size: 32rpx;
  674. font-weight: bold;
  675. }
  676. .controls {
  677. display: flex;
  678. gap: 30rpx;
  679. }
  680. .iconfont {
  681. font-size: 40rpx;
  682. }
  683. .content {
  684. flex: 1;
  685. display: flex;
  686. flex-direction: column;
  687. position: relative;
  688. padding: 50rpx 20rpx 0;
  689. }
  690. .progress-container {
  691. display: flex;
  692. flex-direction: column;
  693. justify-content: space-between;
  694. margin-bottom: 20rpx;
  695. }
  696. .progress-step {
  697. display: flex;
  698. align-items: center;
  699. margin-bottom: 10rpx;
  700. }
  701. .step-circle {
  702. width: 40rpx;
  703. height: 40rpx;
  704. border-radius: 50%;
  705. background-color: #e0e0e0;
  706. display: flex;
  707. align-items: center;
  708. justify-content: center;
  709. font-size: 24rpx;
  710. margin-right: 10rpx;
  711. }
  712. .step-circle.active {
  713. background-color: #ff9500;
  714. color: #ffffff;
  715. }
  716. .step-text {
  717. font-size: 24rpx;
  718. color: #666666;
  719. }
  720. .progress-bar {
  721. height: 10rpx;
  722. background-color: #e0e0e0;
  723. border-radius: 5rpx;
  724. overflow: hidden;
  725. margin-bottom: 20rpx;
  726. }
  727. .progress-fill {
  728. height: 100%;
  729. background-color: #00c853;
  730. transition: width 0.3s;
  731. }
  732. .interview-content {
  733. flex: 1;
  734. display: flex;
  735. flex-direction: column;
  736. }
  737. .video-area {
  738. display: flex;
  739. /* flex-direction: column; */
  740. justify-content: space-between;
  741. height: auto;
  742. margin-bottom: 20rpx;
  743. }
  744. .video-camera {
  745. display: flex;
  746. flex-direction: row;
  747. align-items: center;
  748. justify-content: space-between;
  749. width: 65%;
  750. }
  751. .interviewer {
  752. background-color: #f5f5f5;
  753. display: flex;
  754. align-items: center;
  755. justify-content: center;
  756. position: relative;
  757. width: 48% !important;
  758. height: 300rpx;
  759. }
  760. .interviewer-video {
  761. width: 100%;
  762. height: 100%;
  763. object-fit: cover;
  764. }
  765. .interviewer-avatar {
  766. width: 80%;
  767. height: 80%;
  768. object-fit: contain;
  769. }
  770. .user-camera-container {
  771. width: 48%;
  772. height: 300rpx;
  773. border-radius: 10rpx;
  774. overflow: hidden;
  775. border: 4rpx solid #ffffff;
  776. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.2);
  777. }
  778. .question-area {
  779. flex: 1;
  780. display: flex;
  781. flex-direction: column;
  782. }
  783. .question-number {
  784. font-size: 28rpx;
  785. color: #666;
  786. margin-bottom: 20rpx;
  787. }
  788. .question-importance {
  789. background-color: #f9f9f9;
  790. padding: 20rpx;
  791. border-radius: 10rpx;
  792. margin-bottom: 20rpx;
  793. font-size: 28rpx;
  794. color: #333;
  795. }
  796. .question-importance text {
  797. color: #ff0000;
  798. margin-right: 10rpx;
  799. }
  800. .options {
  801. display: flex;
  802. flex-direction: column;
  803. gap: 20rpx;
  804. margin-bottom: 30rpx;
  805. }
  806. .option-item {
  807. padding: 20rpx;
  808. background-color: #f5f5f5;
  809. border-radius: 10rpx;
  810. font-size: 28rpx;
  811. transition: all 0.3s;
  812. border: 1px solid #e0e0e0;
  813. }
  814. .option-selected {
  815. background-color: #e6f7ff;
  816. border: 1px solid #1890ff;
  817. }
  818. .option-correct {
  819. background-color: #d4f7d4;
  820. border: 1px solid #52c41a;
  821. }
  822. .option-wrong {
  823. background-color: #fff1f0;
  824. border: 1px solid #ff4d4f;
  825. }
  826. .option-text {
  827. color: #333;
  828. }
  829. .timer-container {
  830. text-align: center;
  831. margin: 20rpx 0;
  832. }
  833. .timer-text {
  834. font-size: 24rpx;
  835. color: #666;
  836. }
  837. .next-button {
  838. background-color: #6c5ce7;
  839. color: #ffffff;
  840. border-radius: 10rpx;
  841. font-size: 30rpx;
  842. margin: 20rpx auto;
  843. height: 80rpx;
  844. line-height: 80rpx;
  845. width: 90%;
  846. text-align: center;
  847. }
  848. .next-button[disabled] {
  849. background-color: #cccccc;
  850. color: #999999;
  851. }
  852. .footer {
  853. height: 100rpx;
  854. background-color: #000000;
  855. display: flex;
  856. justify-content: space-between;
  857. align-items: center;
  858. padding: 0 30rpx;
  859. color: #ffffff;
  860. }
  861. .timer {
  862. font-size: 28rpx;
  863. }
  864. .next-step {
  865. font-size: 28rpx;
  866. }
  867. .interview-end-modal {
  868. position: fixed;
  869. top: 0;
  870. left: 0;
  871. right: 0;
  872. bottom: 0;
  873. background-color: rgba(0, 0, 0, 0.5);
  874. display: flex;
  875. align-items: center;
  876. justify-content: center;
  877. z-index: 999;
  878. }
  879. .modal-content {
  880. width: 80%;
  881. background-color: #ffffff;
  882. border-radius: 20rpx;
  883. padding: 40rpx;
  884. display: flex;
  885. flex-direction: column;
  886. align-items: center;
  887. }
  888. .modal-title {
  889. font-size: 36rpx;
  890. font-weight: bold;
  891. margin-bottom: 30rpx;
  892. }
  893. .score-display {
  894. font-size: 48rpx;
  895. font-weight: bold;
  896. color: #6c5ce7;
  897. margin: 20rpx 0;
  898. }
  899. .modal-message {
  900. font-size: 28rpx;
  901. color: #666;
  902. text-align: center;
  903. margin-bottom: 40rpx;
  904. }
  905. .modal-buttons {
  906. display: flex;
  907. justify-content: space-between;
  908. width: 100%;
  909. margin-top: 20rpx;
  910. }
  911. .modal-button {
  912. width: 45%;
  913. }
  914. @keyframes speaking {
  915. 0% {
  916. opacity: 0.8;
  917. }
  918. 50% {
  919. opacity: 1;
  920. }
  921. 100% {
  922. opacity: 0.8;
  923. }
  924. }
  925. .speaking {
  926. animation: speaking 1.5s infinite;
  927. }
  928. .digital-avatar {
  929. width: 120rpx;
  930. height: 120rpx;
  931. z-index: 10;
  932. overflow: hidden;
  933. }
  934. .avatar-image {
  935. width: 120rpx;
  936. height: 120rpx;
  937. border-radius: 20rpx;
  938. border: 2rpx solid #e0e0e0;
  939. }
  940. .digital-human-webview {
  941. width: 120rpx;
  942. height: 120rpx;
  943. border-radius: 20rpx;
  944. border: 2rpx solid #e0e0e0;
  945. }
  946. .interview-complete-screen {
  947. position: fixed;
  948. top: 0;
  949. left: 0;
  950. right: 0;
  951. bottom: 0;
  952. background-color: #f0f5ff;
  953. display: flex;
  954. flex-direction: column;
  955. align-items: center;
  956. justify-content: center;
  957. z-index: 1000;
  958. padding: 40rpx;
  959. }
  960. .digital-avatar-large {
  961. width: 200rpx;
  962. height: 200rpx;
  963. margin-bottom: 60rpx;
  964. }
  965. .avatar-image-large {
  966. width: 100%;
  967. height: 100%;
  968. border-radius: 30rpx;
  969. }
  970. .complete-message {
  971. font-size: 40rpx;
  972. font-weight: bold;
  973. color: #333;
  974. margin-bottom: 30rpx;
  975. }
  976. .complete-description {
  977. font-size: 28rpx;
  978. color: #666;
  979. text-align: center;
  980. margin-bottom: 80rpx;
  981. line-height: 1.5;
  982. }
  983. .complete-button {
  984. background-color: #6c5ce7;
  985. color: #ffffff;
  986. border-radius: 10rpx;
  987. font-size: 32rpx;
  988. padding: 20rpx 60rpx;
  989. margin-top: 40rpx;
  990. }
  991. /* 添加加载状态样式 */
  992. .loading-container {
  993. position: absolute;
  994. top: 0;
  995. left: 0;
  996. right: 0;
  997. bottom: 0;
  998. display: flex;
  999. flex-direction: column;
  1000. align-items: center;
  1001. justify-content: center;
  1002. background-color: rgba(255, 255, 255, 0.9);
  1003. z-index: 100;
  1004. }
  1005. .loading-text {
  1006. margin-top: 20rpx;
  1007. font-size: 28rpx;
  1008. color: #666;
  1009. }
  1010. .error-container {
  1011. text-align: center;
  1012. }
  1013. .error-message {
  1014. font-size: 28rpx;
  1015. color: #ff4d4f;
  1016. margin-bottom: 30rpx;
  1017. }
  1018. .retry-button {
  1019. background-color: #6c5ce7;
  1020. color: #ffffff;
  1021. border-radius: 10rpx;
  1022. font-size: 28rpx;
  1023. padding: 10rpx 30rpx;
  1024. }
  1025. .question-type {
  1026. display: inline-block;
  1027. background-color: #6c5ce7;
  1028. color: white;
  1029. font-size: 24rpx;
  1030. padding: 4rpx 10rpx;
  1031. border-radius: 6rpx;
  1032. margin-right: 10rpx;
  1033. }
  1034. /* 新增的开放问题样式 */
  1035. .open-question-container {
  1036. display: flex;
  1037. flex-direction: column;
  1038. width: 100%;
  1039. margin-bottom: 20rpx;
  1040. }
  1041. .open-question-input {
  1042. width: 100%;
  1043. height: 300rpx;
  1044. background-color: #f9f9f9;
  1045. border: 1px solid #e0e0e0;
  1046. border-radius: 10rpx;
  1047. padding: 20rpx;
  1048. font-size: 28rpx;
  1049. color: #333;
  1050. }
  1051. .word-count {
  1052. text-align: right;
  1053. font-size: 24rpx;
  1054. color: #999;
  1055. margin-top: 10rpx;
  1056. }
  1057. .option-prefix {
  1058. margin-right: 10rpx;
  1059. color: #6c5ce7;
  1060. font-weight: bold;
  1061. }
  1062. </style>