camera.vue 30 KB

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