camera.vue 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177
  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"
  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. }
  169. },
  170. computed: {
  171. currentQuestion() {
  172. console.log(this.questions[this.currentQuestionIndex]);
  173. return this.questions[this.currentQuestionIndex];
  174. }
  175. },
  176. onLoad(options) {
  177. // 从路由参数中获取面试ID
  178. if (options && options.id) {
  179. this.interviewId = options.id;
  180. this.fetchInterviewData();
  181. } else {
  182. // 如果没有ID,可以获取面试列表并使用第一个
  183. this.fetchInterviewList();
  184. }
  185. },
  186. onReady() {
  187. // 创建相机上下文
  188. this.cameraContext = uni.createCameraContext();
  189. // 创建AI视频上下文
  190. if (this.useVideo) {
  191. this.aiVideoContext = uni.createVideoContext('aiInterviewer');
  192. }
  193. // 初始化数字人
  194. this.initDigitalHuman();
  195. },
  196. methods: {
  197. // 获取面试列表
  198. async fetchInterviewList() {
  199. try {
  200. this.loading = true;
  201. const res = await getInterviewList();
  202. console.log(res);
  203. // 使用第一个面试
  204. this.interviewId = res.items//[0].id;
  205. this.fetchInterviewData(res.items);
  206. } catch (error) {
  207. console.error('获取面试列表失败:', error);
  208. this.handleLoadError('获取面试列表失败');
  209. }
  210. },
  211. // 获取面试详情数据
  212. async fetchInterviewData(data) {
  213. try {
  214. this.loading = true;
  215. // const res = await getInterviewDetail({ id: this.interviewId });
  216. // console.log('API返回数据:', res);
  217. // 如果返回的是问题列表
  218. if (data && Array.isArray(data)) {
  219. // 处理多个问题
  220. this.questions =data.map((q, index) => ({
  221. id: q.id || index + 1,
  222. text: q.question || '未知问题',
  223. options:q.options || [],
  224. correctAnswer: q.correctAnswer || 0,
  225. isImportant: q.is_system || false,
  226. explanation: q.explanation || '',
  227. questionType: q.question_form,
  228. questionTypeName: q.question_form_name || '单选题',
  229. correctAnswers: q.correct_answers || [],
  230. difficulty: q.difficulty || 1,
  231. difficultyName: q.difficulty_name || '初级'
  232. }));
  233. } else {
  234. // 处理单个问题
  235. this.processInterviewData(res);
  236. }
  237. console.log(this.questions);
  238. // 设置总题目数
  239. this.totalQuestions = this.questions.length;
  240. // 启动倒计时
  241. if (this.questions.length > 0) {
  242. this.startTimer();
  243. }
  244. } catch (error) {
  245. console.error('获取面试详情失败:', error);
  246. this.handleLoadError('获取面试详情失败');
  247. } finally {
  248. this.loading = false;
  249. }
  250. },
  251. // 处理面试数据
  252. processInterviewData(data) {
  253. // 清空现有问题列表
  254. this.questions = [];
  255. // 检查数据格式并处理
  256. if (data) {
  257. // 创建一个格式化的问题对象
  258. const formattedQuestion = {
  259. id: data.id || 1,
  260. text: data.question || '未知问题',
  261. options: data.options || [],
  262. correctAnswer: data.correctAnswer || 0,
  263. isImportant: data.is_system || false,
  264. explanation: data.explanation || '',
  265. questionType: data.question_form, // 1-单选题,2-多选题
  266. questionTypeName: data.question_form_name || '单选题',
  267. correctAnswers: data.correct_answers || [],
  268. difficulty: data.difficulty || 1,
  269. difficultyName: data.difficulty_name || '初级'
  270. };
  271. // 添加到问题列表
  272. this.questions.push(formattedQuestion);
  273. // 设置总题目数
  274. this.totalQuestions = this.questions.length;
  275. // 启动倒计时
  276. this.startTimer();
  277. } else {
  278. this.handleLoadError('面试中没有问题');
  279. }
  280. },
  281. // 处理加载错误
  282. handleLoadError(message) {
  283. this.loadError = true;
  284. this.loading = false;
  285. this.errorMessage = message || '加载失败';
  286. uni.showToast({
  287. title: message || '加载失败',
  288. icon: 'none',
  289. duration: 2000
  290. });
  291. },
  292. startTimer() {
  293. // 确保问题已加载
  294. if (this.questions.length === 0) return;
  295. // 模拟倒计时
  296. let seconds = 30; // 每题30秒
  297. this.timerInterval = setInterval(() => {
  298. seconds--;
  299. if (seconds <= 0) {
  300. clearInterval(this.timerInterval);
  301. // 时间到,自动提交答案
  302. if (!this.showResult) {
  303. this.checkAnswer();
  304. }
  305. }
  306. const min = Math.floor(seconds / 60).toString().padStart(2, '0');
  307. const sec = (seconds % 60).toString().padStart(2, '0');
  308. this.remainingTime = `${min}:${sec}`;
  309. }, 1000);
  310. },
  311. resetTimer() {
  312. clearInterval(this.timerInterval);
  313. this.startTimer();
  314. },
  315. selectOption(index) {
  316. if (this.showResult) return; // 已显示结果时不能再选择
  317. // 判断当前题目类型
  318. if (this.currentQuestion.questionType === 2) { // 多选题
  319. // 如果已经选中,则取消选中
  320. const optionIndex = this.selectedOptions.indexOf(index);
  321. if (optionIndex > -1) {
  322. this.selectedOptions.splice(optionIndex, 1);
  323. } else {
  324. // 否则添加到已选中数组
  325. this.selectedOptions.push(index);
  326. }
  327. } else if (this.currentQuestion.questionType === 1) { // 单选题
  328. this.selectedOption = index;
  329. }
  330. this.playAiSpeaking();
  331. },
  332. checkAnswer() {
  333. clearInterval(this.timerInterval); // 停止计时
  334. // 确保当前问题存在
  335. if (!this.currentQuestion) {
  336. console.error('当前问题不存在');
  337. return;
  338. }
  339. // 根据题目类型检查答案是否正确
  340. if (this.currentQuestion.questionType === 0) { // 开放问题
  341. // 开放问题没有标准答案,可以根据需要设置为正确或待评估
  342. this.isAnswerCorrect = true; // 或者设置为 null 表示待评估
  343. } else if (this.currentQuestion.questionType === 2) { // 多选题
  344. const sortedSelected = [...this.selectedOptions].sort();
  345. const sortedCorrect = [...this.currentQuestion.correctAnswers].sort();
  346. if (sortedSelected.length !== sortedCorrect.length) {
  347. this.isAnswerCorrect = false;
  348. } else {
  349. this.isAnswerCorrect = sortedSelected.every((value, index) => value === sortedCorrect[index]);
  350. }
  351. } else { // 单选题
  352. this.isAnswerCorrect = this.selectedOption === this.currentQuestion.correctAnswer;
  353. }
  354. // 显示结果
  355. this.showResult = true;
  356. },
  357. nextQuestion() {
  358. // 如果还没有显示结果,先检查答案
  359. if (!this.showResult) {
  360. this.checkAnswer();
  361. return;
  362. }
  363. // 保存当前题目的答案
  364. this.saveAnswer();
  365. // 如果是最后一题,提交所有答案
  366. if (this.currentQuestionIndex >= this.questions.length - 1) {
  367. // 显示结果页面
  368. this.showEndModal = true;
  369. return;
  370. }
  371. // 前往下一题
  372. this.goToNextQuestion();
  373. },
  374. // 保存当前题目的答案
  375. saveAnswer() {
  376. let answer;
  377. if (this.currentQuestion.questionType === 0) { // 开放问题
  378. answer = {
  379. questionId: this.currentQuestion.id,
  380. questionType: this.currentQuestion.questionType,
  381. answer: this.openQuestionAnswer
  382. };
  383. } else { // 单选或多选
  384. answer = {
  385. questionId: this.currentQuestion.id,
  386. questionType: this.currentQuestion.questionType,
  387. answer: this.currentQuestion.questionType === 1 ?
  388. this.selectedOption : this.selectedOptions
  389. };
  390. }
  391. // 检查是否已存在该题目的答案,如果存在则更新
  392. const existingIndex = this.answers.findIndex(a => a.questionId === answer.questionId);
  393. if (existingIndex > -1) {
  394. this.answers[existingIndex] = answer;
  395. } else {
  396. this.answers.push(answer);
  397. }
  398. console.log('已保存答案:', this.answers);
  399. },
  400. // 提交所有答案
  401. async submitAllAnswers() {
  402. if (this.isSubmitting) return;
  403. try {
  404. this.isSubmitting = true;
  405. // 显示提交中提示
  406. uni.showLoading({
  407. title: '正在提交答案...'
  408. });
  409. // 构建提交数据
  410. const submitData = {
  411. interviewId: this.interviewId,
  412. answers: this.answers
  413. };
  414. // 这里需要添加您的API调用
  415. // const res = await submitInterviewAnswers(submitData);
  416. // 模拟API调用
  417. await new Promise(resolve => setTimeout(resolve, 1000));
  418. // 隐藏加载提示
  419. uni.hideLoading();
  420. // 显示成功提示
  421. uni.showToast({
  422. title: '提交成功',
  423. icon: 'success'
  424. });
  425. // 关闭结果页面,可以选择跳转到其他页面
  426. setTimeout(() => {
  427. this.back();
  428. }, 1500);
  429. } catch (error) {
  430. console.error('提交答案失败:', error);
  431. uni.showToast({
  432. title: '提交答案失败,请重试',
  433. icon: 'none'
  434. });
  435. } finally {
  436. this.isSubmitting = false;
  437. }
  438. },
  439. // 修改 goToNextQuestion 方法,添加 async 关键字
  440. async goToNextQuestion() {
  441. // 重置状态
  442. this.showResult = false;
  443. this.selectedOption = null;
  444. this.selectedOptions = [];
  445. this.openQuestionAnswer = ''; // 重置开放问题答案
  446. // 前往下一题
  447. this.currentQuestionIndex++;
  448. // 如果已经有下一题的详情,直接使用
  449. if (this.questions[this.currentQuestionIndex]) {
  450. // 更新进度
  451. this.progressWidth = (this.currentQuestionIndex + 1) / this.questions.length * 100;
  452. // 重置计时器
  453. this.resetTimer();
  454. // 播放AI介绍下一题
  455. this.playAiSpeaking();
  456. setTimeout(() => {
  457. this.pauseAiSpeaking();
  458. }, 2000);
  459. return;
  460. }
  461. // 否则请求下一题详情
  462. try {
  463. this.loading = true;
  464. // 假设您有一个获取单个题目详情的API
  465. // const res = await getQuestionDetail({
  466. // interviewId: this.interviewId,
  467. // questionIndex: this.currentQuestionIndex
  468. // });
  469. // 模拟API调用
  470. await new Promise(resolve => setTimeout(resolve, 1000));
  471. const res = { /* 模拟的题目数据 */ };
  472. // 处理题目数据
  473. if (res) {
  474. const formattedQuestion = {
  475. id: res.id || this.currentQuestionIndex + 1,
  476. text: res.question || '未知问题',
  477. options: res.options || [],
  478. correctAnswer: res.correctAnswer || 0,
  479. isImportant: res.is_system || false,
  480. explanation: res.explanation || '',
  481. questionType: res.question_form || 1,
  482. questionTypeName: res.question_form_name || '单选题',
  483. correctAnswers: res.correct_answers || [],
  484. difficulty: res.difficulty || 1,
  485. difficultyName: res.difficulty_name || '初级'
  486. };
  487. // 添加到问题列表
  488. this.questions.push(formattedQuestion);
  489. }
  490. } catch (error) {
  491. console.error('获取题目详情失败:', error);
  492. uni.showToast({
  493. title: '获取题目失败,请重试',
  494. icon: 'none'
  495. });
  496. // 出错时回到上一题
  497. this.currentQuestionIndex--;
  498. } finally {
  499. this.loading = false;
  500. // 更新进度
  501. this.progressWidth = (this.currentQuestionIndex + 1) / this.questions.length * 100;
  502. // 重置计时器
  503. this.resetTimer();
  504. }
  505. },
  506. toggleSettings() {
  507. // 打开设置面板
  508. uni.showToast({
  509. title: '设置功能开发中',
  510. icon: 'none'
  511. });
  512. },
  513. back() {
  514. // 清除计时器
  515. if (this.timerInterval) {
  516. clearInterval(this.timerInterval);
  517. }
  518. // 尝试返回上一页,如果失败则跳转到首页
  519. try {
  520. const pages = getCurrentPages();
  521. if (pages.length > 1) {
  522. uni.reLaunch({
  523. url: '/pages/index/index'
  524. });
  525. } else {
  526. // 如果当前是第一页,则跳转到首页
  527. uni.reLaunch({
  528. url: '/pages/index/index'
  529. });
  530. }
  531. } catch (e) {
  532. console.error('导航错误:', e);
  533. // 出错时也跳转到首页
  534. uni.reLaunch({
  535. url: '/pages/index/index'
  536. });
  537. }
  538. },
  539. error(e) {
  540. // 相机错误事件
  541. console.error(e.detail);
  542. uni.showToast({
  543. title: '相机启动失败,请检查权限设置',
  544. icon: 'none'
  545. });
  546. },
  547. playAiSpeaking() {
  548. if (this.useVideo && this.aiVideoContext) {
  549. this.aiVideoContext.play();
  550. }
  551. // 触发数字人说话动画
  552. if (this.digitalHumanUrl) {
  553. // 假设当前问题的文本作为数字人要说的内容
  554. const speakText = this.currentQuestion ? this.currentQuestion.text : '';
  555. this.interactWithDigitalHuman(speakText);
  556. }
  557. },
  558. pauseAiSpeaking() {
  559. if (this.useVideo && this.aiVideoContext) {
  560. this.aiVideoContext.pause();
  561. }
  562. },
  563. // 重新开始测试
  564. restartTest() {
  565. this.currentQuestionIndex = 0;
  566. this.score = 0;
  567. this.showEndModal = false;
  568. this.showResult = false;
  569. this.selectedOption = null;
  570. this.selectedOptions = [];
  571. this.resetTimer();
  572. },
  573. // 在methods中添加测试方法
  574. testEndScreen() {
  575. this.interviewCompleted = true;
  576. this.showEndModal = false;
  577. },
  578. // 初始化数字人
  579. initDigitalHuman() {
  580. // 移除不可用的示例URL
  581. // this.digitalHumanUrl = 'https://your-digital-human-service.com/avatar?id=123';
  582. // 暂时不使用数字人服务,直接使用本地图片
  583. this.digitalHumanUrl = '';
  584. // 如果您有实际可用的数字人服务,可以在这里设置
  585. // 例如:this.digitalHumanUrl = 'https://your-actual-service.com/avatar';
  586. // 或者使用本地HTML文件(如果有的话)
  587. // this.digitalHumanUrl = '/hybrid/html/digital-human.html';
  588. },
  589. // 与数字人交互的方法
  590. interactWithDigitalHuman(message) {
  591. // 如果数字人是通过web-view加载的,可以使用postMessage与其通信
  592. const webview = this.$mp.page.$getAppWebview().children()[0];
  593. if (webview) {
  594. webview.evalJS(`receiveMessage('${message}')`);
  595. }
  596. }
  597. },
  598. // 添加生命周期钩子,确保在组件销毁时清除计时器
  599. beforeDestroy() {
  600. if (this.timerInterval) {
  601. clearInterval(this.timerInterval);
  602. }
  603. }
  604. }
  605. </script>
  606. <style>
  607. .camera-container {
  608. position: relative;
  609. width: 100%;
  610. height: 100vh;
  611. background-color: #ffffff;
  612. display: flex;
  613. flex-direction: column;
  614. }
  615. .header {
  616. height: 90rpx;
  617. /* background-color: #000000; */
  618. display: flex;
  619. align-items: center;
  620. padding: 0 30rpx;
  621. /* color: #ffffff; */
  622. }
  623. .back-button {
  624. width: 60rpx;
  625. height: 60rpx;
  626. display: flex;
  627. align-items: center;
  628. justify-content: center;
  629. }
  630. .title {
  631. flex: 1;
  632. text-align: center;
  633. font-size: 32rpx;
  634. font-weight: bold;
  635. }
  636. .controls {
  637. display: flex;
  638. gap: 30rpx;
  639. }
  640. .iconfont {
  641. font-size: 40rpx;
  642. }
  643. .content {
  644. flex: 1;
  645. display: flex;
  646. flex-direction: column;
  647. position: relative;
  648. padding: 50rpx 20rpx 0;
  649. }
  650. .progress-container {
  651. display: flex;
  652. flex-direction: column;
  653. justify-content: space-between;
  654. margin-bottom: 20rpx;
  655. }
  656. .progress-step {
  657. display: flex;
  658. align-items: center;
  659. margin-bottom: 10rpx;
  660. }
  661. .step-circle {
  662. width: 40rpx;
  663. height: 40rpx;
  664. border-radius: 50%;
  665. background-color: #e0e0e0;
  666. display: flex;
  667. align-items: center;
  668. justify-content: center;
  669. font-size: 24rpx;
  670. margin-right: 10rpx;
  671. }
  672. .step-circle.active {
  673. background-color: #ff9500;
  674. color: #ffffff;
  675. }
  676. .step-text {
  677. font-size: 24rpx;
  678. color: #666666;
  679. }
  680. .progress-bar {
  681. height: 10rpx;
  682. background-color: #e0e0e0;
  683. border-radius: 5rpx;
  684. overflow: hidden;
  685. margin-bottom: 20rpx;
  686. }
  687. .progress-fill {
  688. height: 100%;
  689. background-color: #00c853;
  690. transition: width 0.3s;
  691. }
  692. .interview-content {
  693. flex: 1;
  694. display: flex;
  695. flex-direction: column;
  696. }
  697. .video-area {
  698. display: flex;
  699. /* flex-direction: column; */
  700. justify-content: space-between;
  701. height: auto;
  702. margin-bottom: 20rpx;
  703. }
  704. .video-camera {
  705. display: flex;
  706. flex-direction: row;
  707. align-items: center;
  708. justify-content: space-between;
  709. width: 65%;
  710. }
  711. .interviewer {
  712. background-color: #f5f5f5;
  713. display: flex;
  714. align-items: center;
  715. justify-content: center;
  716. position: relative;
  717. width: 48% !important;
  718. height: 300rpx;
  719. }
  720. .interviewer-video {
  721. width: 100%;
  722. height: 100%;
  723. object-fit: cover;
  724. }
  725. .interviewer-avatar {
  726. width: 80%;
  727. height: 80%;
  728. object-fit: contain;
  729. }
  730. .user-camera-container {
  731. width: 48%;
  732. height: 300rpx;
  733. border-radius: 10rpx;
  734. overflow: hidden;
  735. border: 4rpx solid #ffffff;
  736. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.2);
  737. }
  738. .question-area {
  739. flex: 1;
  740. display: flex;
  741. flex-direction: column;
  742. }
  743. .question-number {
  744. font-size: 28rpx;
  745. color: #666;
  746. margin-bottom: 20rpx;
  747. }
  748. .question-importance {
  749. background-color: #f9f9f9;
  750. padding: 20rpx;
  751. border-radius: 10rpx;
  752. margin-bottom: 20rpx;
  753. font-size: 28rpx;
  754. color: #333;
  755. }
  756. .question-importance text {
  757. color: #ff0000;
  758. margin-right: 10rpx;
  759. }
  760. .options {
  761. display: flex;
  762. flex-direction: column;
  763. gap: 20rpx;
  764. margin-bottom: 30rpx;
  765. }
  766. .option-item {
  767. padding: 20rpx;
  768. background-color: #f5f5f5;
  769. border-radius: 10rpx;
  770. font-size: 28rpx;
  771. transition: all 0.3s;
  772. border: 1px solid #e0e0e0;
  773. }
  774. .option-selected {
  775. background-color: #e6f7ff;
  776. border: 1px solid #1890ff;
  777. }
  778. .option-correct {
  779. background-color: #d4f7d4;
  780. border: 1px solid #52c41a;
  781. }
  782. .option-wrong {
  783. background-color: #fff1f0;
  784. border: 1px solid #ff4d4f;
  785. }
  786. .option-text {
  787. color: #333;
  788. }
  789. .timer-container {
  790. text-align: center;
  791. margin: 20rpx 0;
  792. }
  793. .timer-text {
  794. font-size: 24rpx;
  795. color: #666;
  796. }
  797. .next-button {
  798. background-color: #6c5ce7;
  799. color: #ffffff;
  800. border-radius: 10rpx;
  801. font-size: 30rpx;
  802. margin: 20rpx auto;
  803. height: 80rpx;
  804. line-height: 80rpx;
  805. width: 90%;
  806. text-align: center;
  807. }
  808. .next-button[disabled] {
  809. background-color: #cccccc;
  810. color: #999999;
  811. }
  812. .footer {
  813. height: 100rpx;
  814. background-color: #000000;
  815. display: flex;
  816. justify-content: space-between;
  817. align-items: center;
  818. padding: 0 30rpx;
  819. color: #ffffff;
  820. }
  821. .timer {
  822. font-size: 28rpx;
  823. }
  824. .next-step {
  825. font-size: 28rpx;
  826. }
  827. .interview-end-modal {
  828. position: fixed;
  829. top: 0;
  830. left: 0;
  831. right: 0;
  832. bottom: 0;
  833. background-color: rgba(0, 0, 0, 0.5);
  834. display: flex;
  835. align-items: center;
  836. justify-content: center;
  837. z-index: 999;
  838. }
  839. .modal-content {
  840. width: 80%;
  841. background-color: #ffffff;
  842. border-radius: 20rpx;
  843. padding: 40rpx;
  844. display: flex;
  845. flex-direction: column;
  846. align-items: center;
  847. }
  848. .modal-title {
  849. font-size: 36rpx;
  850. font-weight: bold;
  851. margin-bottom: 30rpx;
  852. }
  853. .score-display {
  854. font-size: 48rpx;
  855. font-weight: bold;
  856. color: #6c5ce7;
  857. margin: 20rpx 0;
  858. }
  859. .modal-message {
  860. font-size: 28rpx;
  861. color: #666;
  862. text-align: center;
  863. margin-bottom: 40rpx;
  864. }
  865. .modal-buttons {
  866. display: flex;
  867. justify-content: space-between;
  868. width: 100%;
  869. margin-top: 20rpx;
  870. }
  871. .modal-button {
  872. width: 45%;
  873. }
  874. @keyframes speaking {
  875. 0% {
  876. opacity: 0.8;
  877. }
  878. 50% {
  879. opacity: 1;
  880. }
  881. 100% {
  882. opacity: 0.8;
  883. }
  884. }
  885. .speaking {
  886. animation: speaking 1.5s infinite;
  887. }
  888. .digital-avatar {
  889. width: 120rpx;
  890. height: 120rpx;
  891. z-index: 10;
  892. overflow: hidden;
  893. }
  894. .avatar-image {
  895. width: 120rpx;
  896. height: 120rpx;
  897. border-radius: 20rpx;
  898. border: 2rpx solid #e0e0e0;
  899. }
  900. .digital-human-webview {
  901. width: 120rpx;
  902. height: 120rpx;
  903. border-radius: 20rpx;
  904. border: 2rpx solid #e0e0e0;
  905. }
  906. .interview-complete-screen {
  907. position: fixed;
  908. top: 0;
  909. left: 0;
  910. right: 0;
  911. bottom: 0;
  912. background-color: #f0f5ff;
  913. display: flex;
  914. flex-direction: column;
  915. align-items: center;
  916. justify-content: center;
  917. z-index: 1000;
  918. padding: 40rpx;
  919. }
  920. .digital-avatar-large {
  921. width: 200rpx;
  922. height: 200rpx;
  923. margin-bottom: 60rpx;
  924. }
  925. .avatar-image-large {
  926. width: 100%;
  927. height: 100%;
  928. border-radius: 30rpx;
  929. }
  930. .complete-message {
  931. font-size: 40rpx;
  932. font-weight: bold;
  933. color: #333;
  934. margin-bottom: 30rpx;
  935. }
  936. .complete-description {
  937. font-size: 28rpx;
  938. color: #666;
  939. text-align: center;
  940. margin-bottom: 80rpx;
  941. line-height: 1.5;
  942. }
  943. .complete-button {
  944. background-color: #6c5ce7;
  945. color: #ffffff;
  946. border-radius: 10rpx;
  947. font-size: 32rpx;
  948. padding: 20rpx 60rpx;
  949. margin-top: 40rpx;
  950. }
  951. /* 添加加载状态样式 */
  952. .loading-container {
  953. position: absolute;
  954. top: 0;
  955. left: 0;
  956. right: 0;
  957. bottom: 0;
  958. display: flex;
  959. flex-direction: column;
  960. align-items: center;
  961. justify-content: center;
  962. background-color: rgba(255, 255, 255, 0.9);
  963. z-index: 100;
  964. }
  965. .loading-text {
  966. margin-top: 20rpx;
  967. font-size: 28rpx;
  968. color: #666;
  969. }
  970. .error-container {
  971. text-align: center;
  972. }
  973. .error-message {
  974. font-size: 28rpx;
  975. color: #ff4d4f;
  976. margin-bottom: 30rpx;
  977. }
  978. .retry-button {
  979. background-color: #6c5ce7;
  980. color: #ffffff;
  981. border-radius: 10rpx;
  982. font-size: 28rpx;
  983. padding: 10rpx 30rpx;
  984. }
  985. .question-type {
  986. display: inline-block;
  987. background-color: #6c5ce7;
  988. color: white;
  989. font-size: 24rpx;
  990. padding: 4rpx 10rpx;
  991. border-radius: 6rpx;
  992. margin-right: 10rpx;
  993. }
  994. /* 新增的开放问题样式 */
  995. .open-question-container {
  996. display: flex;
  997. flex-direction: column;
  998. width: 100%;
  999. margin-bottom: 20rpx;
  1000. }
  1001. .open-question-input {
  1002. width: 100%;
  1003. height: 300rpx;
  1004. background-color: #f9f9f9;
  1005. border: 1px solid #e0e0e0;
  1006. border-radius: 10rpx;
  1007. padding: 20rpx;
  1008. font-size: 28rpx;
  1009. color: #333;
  1010. }
  1011. .word-count {
  1012. text-align: right;
  1013. font-size: 24rpx;
  1014. color: #999;
  1015. margin-top: 10rpx;
  1016. }
  1017. .option-prefix {
  1018. margin-right: 10rpx;
  1019. color: #6c5ce7;
  1020. font-weight: bold;
  1021. }
  1022. </style>