camera.vue 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999
  1. <template>
  2. <view class="camera-container">
  3. <!-- 顶部相机区域 - 固定位置 -->
  4. <view class="fixed-camera-container">
  5. <view class="user-avatar" :class="{ 'camera-warning': showPageWarning }">
  6. <camera v-if="!digitalHumanUrl" device-position="front" flash="auto" class="camera"
  7. :mode="mode" @error="handleCameraError"></camera>
  8. <web-view v-else-if="digitalHumanUrl" :src="digitalHumanUrl" class="digital-human-webview"></web-view>
  9. <image v-else src="/static/avatar.png" mode="aspectFill" class="avatar-image"></image>
  10. </view>
  11. </view>
  12. <!-- 主要内容区域 - 修改为流式布局 -->
  13. <scroll-view class="content-scroll" scroll-y="true" :scroll-into-view="currentScrollId" :scroll-with-animation="true" :scroll-top="scrollTop">
  14. <view class="content">
  15. <!-- 测试内容区域 - 修改为流式布局,每个问题都显示 -->
  16. <view v-for="(question, qIndex) in questions" :key="question.id" :id="'question-'+qIndex" class="interview-content">
  17. <!-- 问题编号和进度 -->
  18. <view class="question-number">
  19. <text>{{qIndex + 1}}/{{questions.length}}</text>
  20. </view>
  21. <!-- 问题和选项区域 -->
  22. <view class="question-area">
  23. <view class="question-importance">
  24. <!-- <text v-if="currentQuestion.isImportant">重点题</text> -->
  25. <text class="question-type">{{question.questionTypeName}}</text>
  26. {{question.text}}<text class="question-type" v-if="question.is_required_correct">(红线题)</text>
  27. </view>
  28. <!-- 添加图片显示区域,仅在 question_form 为 3 时显示 -->
  29. <view class="question-image-container" v-if="question.questionType === 3 && question.imageUrl">
  30. <image :src="question.imageUrl" mode="widthFix" class="question-image"></image>
  31. </view>
  32. <view class="options">
  33. <!-- 渲染非开放问题 (questionType: 1, 2 或 3) -->
  34. <view
  35. v-if="question.questionType !== 0"
  36. v-for="(option, index) in question.options"
  37. :key="index"
  38. class="option-item"
  39. :class="{
  40. 'option-selected': isOptionSelected(question, qIndex, index),
  41. 'option-disabled': qIndex !== currentQuestionIndex
  42. }"
  43. @click="handleOptionClick(qIndex, index)">
  44. <text class="option-text">{{ option.option_text || (typeof option === 'string' ? option : JSON.stringify(option)) }}</text>
  45. </view>
  46. </view>
  47. <!-- 添加当前题目的按钮 - 只在多选题时显示 -->
  48. <view class="question-button-container" v-if="qIndex === currentQuestionIndex && question.questionType === 2">
  49. <button class="next-button" @click="nextQuestion()"
  50. :disabled="selectedOptions.length === 0">
  51. {{"下一题"}}
  52. </button>
  53. </view>
  54. </view>
  55. </view>
  56. <view class="continue-button-container" v-if="showContinueButton" id="continue-button">
  57. <button class="continue-button" @click="handleContinue">
  58. {{ currentGroupIndex < questionGroups.length - 1 ? '继续下一部分' : '完成测试' }}
  59. </button>
  60. </view>
  61. <!-- 添加底部锚点元素 -->
  62. <view id="bottom-anchor" style="height: 1px;"></view>
  63. <!-- 添加底部空白区域,确保内容不被固定按钮遮挡 -->
  64. <view class="bottom-space"></view>
  65. </view>
  66. </scroll-view>
  67. <!-- 面试结束弹窗 -->
  68. <view class="interview-end-modal" v-if="showEndModal">
  69. <view class="modal-content">
  70. <view class="modal-title">测试已完成</view>
  71. <!-- <view class="score-display">{{score}}/{{totalQuestions}}</view>
  72. <view class="modal-message">您在本次测试中答了{{score}}道题目,共{{totalQuestions}}道题目。</view> -->
  73. <view class="modal-buttons">
  74. <!-- <button type="default" class="modal-button" @click="restartTest">重新测试</button> -->
  75. <button type="primary" class="modal-button" @click="navigateToInterview">进入面试</button>
  76. </view>
  77. </view>
  78. </view>
  79. <!-- AI面试结束页面 -->
  80. <view class="interview-complete-screen" v-if="interviewCompleted">
  81. <view class="digital-avatar-large">
  82. <image src="/static/avatar.png" mode="aspectFill" class="avatar-image-large"></image>
  83. </view>
  84. <view class="complete-message">AI面试已结束</view>
  85. <view class="complete-description">本次面试的全部环节已结束。非常感谢您的参与。</view>
  86. <button class="complete-button" @click="back">我知道了</button>
  87. </view>
  88. <!-- 在模板中添加一个测试按钮(开发时使用,发布前删除) -->
  89. <!-- <button @click="testEndScreen" style="position: absolute; top: 10px; right: 10px; z-index: 9999;">测试结束页</button> -->
  90. <!-- 添加加载状态 -->
  91. <view class="loading-container" v-if="loading">
  92. <uni-load-more status="loading" :contentText="{contentdown: '加载中...'}" />
  93. <text class="loading-text">正在加载面试题目...</text>
  94. </view>
  95. <!-- 添加加载错误提示 -->
  96. <view class="loading-container" v-if="!loading && loadError">
  97. <view class="error-container">
  98. <text class="error-message">加载面试题目失败</text>
  99. <button class="retry-button" @click="fetchInterviewData">重试</button>
  100. </view>
  101. </view>
  102. <!-- 添加提示弹窗 -->
  103. <view class="prompt-modal" v-if="showPromptModal">
  104. <view class="prompt-content">
  105. <view class="prompt-title">温馨提示</view>
  106. <view class="prompt-text">
  107. 这部分是有关压力与情绪的测试,<text class="bold-text">所有问题没有绝对的"正确"或"错误"答案,只需结合您目前的状态选择最匹配的程度选项。</text>
  108. </view>
  109. <view class="prompt-text">
  110. 我们更关注您当下最真实的想法和感受。就像和朋友聊天一样,依据自己的主观意识如实回答即可。您的每一个回答都将被严格保密,仅用于帮助我们更深入地认识您,助力后续的职业发展规划。
  111. </view>
  112. <view class="prompt-text">
  113. 在开始前,不妨先做几个深呼吸,调整好状态。希望您能以轻松的心态完成检测!
  114. </view>
  115. <button class="prompt-button" @click="handlePromptConfirm">确定</button>
  116. </view>
  117. </view>
  118. </view>
  119. </template>
  120. <script>
  121. import { getInterviewList, getInterviewDetail,getQuestions } from '@/api/user.js';
  122. import { apiBaseUrl,personDetectionWsUrl } from '@/common/config.js';
  123. export default {
  124. data() {
  125. return {
  126. cameraContext: null,
  127. devicePosition: 'front',
  128. interviewStarted: true,
  129. showEndModal: false,
  130. currentQuestionIndex: 0,
  131. currentStep: 1,
  132. stepTexts: ['测试准备', '回答问题', '测试结束'],
  133. progressWidth: 50,
  134. remainingTime: '00:27',
  135. selectedOption: null,
  136. selectedOptions: [],
  137. showResult: false,
  138. isAnswerCorrect: false,
  139. questions: [], // 改为空数组,将通过API获取
  140. interviewId: null, // 存储当前面试ID
  141. useVideo: false,
  142. timerInterval: null,
  143. score: 0,
  144. totalQuestions: 0,
  145. interviewCompleted: false,
  146. digitalHumanUrl: '', // 数字人URL
  147. loading: true, // 添加加载状态
  148. loadError: false, // 添加加载错误状态
  149. errorMessage: '', // 添加错误消息
  150. answers: [], // 存储用户的所有答案
  151. currentQuestionDetail: null, // 当前题目详情
  152. isSubmitting: false, // 是否正在提交答案
  153. openQuestionAnswer: '', // 存储开放问题的答案
  154. currentAnswer: null, // 存储当前答案以便提交
  155. questionStartTime: null, // 存储问题开始时间
  156. mode: 'normal', // 相机模式
  157. currentScrollId: 'question-0', // 当前滚动到的问题ID
  158. questionGroups: [], // 存储分组后的题目
  159. currentGroupIndex: 0, // 当前显示的组索引
  160. showContinueButton: false, // 是否显示继续按钮
  161. scrollToBottom: false, // 新增:是否需要滚动到底部
  162. scrollTop: 0, // 控制 scroll-view 的滚动位置
  163. _clickTimer: null,
  164. _isClicking: false,
  165. showPromptModal: false, // 添加新的数据属性
  166. personDetectionSocket: null, // WebSocket对象
  167. personDetectionInterval: null, // 定时器对象
  168. showCameraWarning: false, // 添加新的数据属性
  169. showPageWarning: false, // 添加新的数据属性
  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. mounted() {
  199. // 添加截屏监听
  200. uni.onUserCaptureScreen(() => {
  201. console.log('User captured screen');
  202. this.screenCaptureCount++;
  203. if (this.screenCaptureCount === 1) {
  204. uni.showModal({
  205. title: 'Warning',
  206. content: '检测到屏幕截图。如果你再次捕捉屏幕,你的面试将无效.',
  207. showCancel: false,
  208. confirmText: 'OK'
  209. });
  210. } else if (this.screenCaptureCount >= 2) {
  211. uni.showModal({
  212. title: 'Interview Invalid',
  213. content: '由于多次屏幕截图,您的面试已无效。请联系招聘人员寻求帮助.',
  214. showCancel: false,
  215. confirmText: 'OK',
  216. success: () => {
  217. this.invalidateInterview();
  218. }
  219. });
  220. }
  221. });
  222. },
  223. beforeDestroy() {
  224. // 移除截屏
  225. this.cleanupPersonDetectionWebSocket();
  226. },
  227. methods: {
  228. initPersonDetectionWebSocket() {
  229. if (this.personDetectionSocket) {
  230. this.cleanupPersonDetectionWebSocket();
  231. }
  232. try {
  233. this.personDetectionSocket = uni.connectSocket({
  234. url: `${personDetectionWsUrl}/ws/interview-room/room_${uni.getStorageSync('appId')}/${uni.getStorageSync('appId')}/`,
  235. success: () => {
  236. console.log('WebSocket connection initiated');
  237. },
  238. fail: (error) => {
  239. console.error('WebSocket connection failed:', error);
  240. }
  241. });
  242. this.personDetectionSocket.onOpen(() => {
  243. console.log('WebSocket connection opened');
  244. this.startPersonDetectionInterval();
  245. });
  246. this.personDetectionSocket.onError((error) => {
  247. console.error('WebSocket error:', error);
  248. this.cleanupPersonDetectionWebSocket();
  249. });
  250. this.personDetectionSocket.onClose(() => {
  251. console.log('WebSocket connection closed');
  252. this.cleanupPersonDetectionWebSocket();
  253. });
  254. this.personDetectionSocket.onMessage((res) => {
  255. try {
  256. const data = JSON.parse(res.data);
  257. console.log(data);
  258. if (data.type === 'person_detection_result') {
  259. this.handlePersonDetectionResult(data);
  260. }
  261. } catch (error) {
  262. console.error('Error parsing WebSocket message:', error);
  263. }
  264. });
  265. } catch (error) {
  266. console.error('Error initializing WebSocket:', error);
  267. this.cleanupPersonDetectionWebSocket();
  268. }
  269. },
  270. startPersonDetectionInterval() {
  271. if (this.personDetectionInterval) {
  272. clearInterval(this.personDetectionInterval);
  273. }
  274. this.personDetectionInterval = setInterval(() => {
  275. if (this.personDetectionSocket && this.cameraContext) {
  276. this.cameraContext.takePhoto({
  277. quality: 'low',
  278. success: (res) => {
  279. const tempFilePath = res.tempImagePath;
  280. uni.getFileSystemManager().readFile({
  281. filePath: tempFilePath,
  282. encoding: 'base64',
  283. success: (res) => {
  284. const base64Image = res.data;
  285. this.personDetectionSocket.send({
  286. data: JSON.stringify({
  287. type: 'person_detection',
  288. image_data: base64Image
  289. })
  290. });
  291. },
  292. fail: (error) => {
  293. console.error('Error reading image file:', error);
  294. }
  295. });
  296. },
  297. fail: (error) => {
  298. console.error('Error taking photo:', error);
  299. }
  300. });
  301. }
  302. }, 3000);
  303. },
  304. cleanupPersonDetectionWebSocket() {
  305. if (this.personDetectionInterval) {
  306. clearInterval(this.personDetectionInterval);
  307. this.personDetectionInterval = null;
  308. }
  309. if (this.personDetectionSocket) {
  310. try {
  311. this.personDetectionSocket.close();
  312. } catch (error) {
  313. console.error('Error closing WebSocket:', error);
  314. }
  315. this.personDetectionSocket = null;
  316. }
  317. },
  318. handlePersonDetectionResult(data) {
  319. console.log(data.data.detection.has_person);
  320. console.log(data.data.identity.status);//identity_verified
  321. // 首先检查是否有人
  322. /* if (!data.data.detection.has_person) {
  323. this.showPageWarning = true;
  324. uni.showToast({
  325. title: '请勿离开摄像头',
  326. icon: 'none',
  327. duration: 3000
  328. });
  329. // 添加震动反馈
  330. uni.vibrateShort({
  331. success: function () {
  332. console.log('Vibration successful');
  333. },
  334. fail: function (err) {
  335. console.error('Vibration failed:', err);
  336. }
  337. });
  338. setTimeout(() => {
  339. this.showPageWarning = false;
  340. }, 3000);
  341. }
  342. // 然后检查身份验证状态
  343. else */ if (data.data.identity.status !== "identity_verified") {
  344. this.showPageWarning = true;
  345. uni.showToast({
  346. title: data.data.identity.message,
  347. icon: 'none',
  348. duration: 3000
  349. });
  350. uni.vibrateLong({
  351. success: function () {
  352. console.log('Vibration successful');
  353. },
  354. fail: function (err) {
  355. console.error('Vibration failed:', err);
  356. }
  357. });
  358. setTimeout(() => {
  359. this.showPageWarning = false;
  360. }, 3000);
  361. }
  362. },
  363. // 添加作废面试的方法
  364. invalidateInterview() {
  365. // 停止录制(如果正在录制)
  366. if (this.isRecording) {
  367. this.stopRecordingAnswer();
  368. }
  369. // 清除所有计时器
  370. if (this.recordingTimer) {
  371. clearInterval(this.recordingTimer);
  372. }
  373. // 重置状态
  374. this.isRecording = false;
  375. this.showStopRecordingButton = false;
  376. this.showStartRecordingButton = false;
  377. // 显示作废提示
  378. // uni.showToast({
  379. // title: 'Interview invalidated',
  380. // icon: 'none',
  381. // duration: 2000
  382. // });
  383. // 延迟后返回上一页
  384. setTimeout(() => {
  385. uni.switchTab({
  386. url: '/pages/index/index'
  387. });
  388. }, 500);
  389. const systemInfo = uni.getSystemInfoSync();
  390. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith('mp-');
  391. if (isMiniProgram) {
  392. this.initPersonDetectionWebSocket();
  393. }
  394. },
  395. // 获取面试列表
  396. async fetchInterviewList() {
  397. try {
  398. this.loading = true;
  399. const res = await getQuestions({
  400. position_id:JSON.parse(uni.getStorageSync('selectedJob')).id,
  401. page:1,
  402. limit:999,
  403. tenant_id:JSON.parse(uni.getStorageSync('userInfo')).tenant_id || 1
  404. });
  405. console.log(res.items);
  406. // 使用第一个面试
  407. this.interviewId = res.items//[0].id;
  408. this.fetchInterviewData(res.items);
  409. } catch (error) {
  410. console.error('获取面试列表失败:', error);
  411. this.handleLoadError('获取面试列表失败');
  412. }
  413. },
  414. // 获取面试详情数据
  415. async fetchInterviewData(data) {
  416. try {
  417. this.loading = true;
  418. // const res = await getInterviewDetail({ id: this.interviewId });
  419. // console.log('API返回数据:', res);
  420. // 如果返回的是问题列表
  421. if (data && Array.isArray(data)) {
  422. const formattedQuestions = data
  423. .filter(q => q.question_form !== 0)
  424. .map((q, index) => ({
  425. id: q.id || index + 1,
  426. text: q.question || '未知问题',
  427. options: q.options || [],
  428. correctAnswer: q.correctAnswer || 0,
  429. isImportant: q.is_system || false,
  430. explanation: q.explanation || '',
  431. questionType: q.question_form,
  432. questionTypeName: q.question_form_name || '单选题',
  433. is_required_correct: q.is_required_correct || false,
  434. correctAnswers: q.correct_answers || [],
  435. difficulty: q.difficulty || 1,
  436. difficultyName: q.difficulty_name || '初级',
  437. imageUrl: q.question_image_url || '', // 添加图片URL字段
  438. category: q.category || 0, // 添加 category 字段
  439. }));
  440. // 处理题目分组
  441. this.processQuestionGroups(formattedQuestions);
  442. } else {
  443. // 处理单个问题
  444. this.processInterviewData(res);
  445. }
  446. console.log(this.questions);
  447. // 设置总题目数
  448. this.totalQuestions = this.questions.length;
  449. /* // 启动倒计时
  450. if (this.questions.length > 0) {
  451. this.startTimer();
  452. } */
  453. } catch (error) {
  454. console.error('获取面试详情失败:', error);
  455. this.handleLoadError('获取面试详情失败');
  456. } finally {
  457. this.loading = false;
  458. }
  459. },
  460. // 处理面试数据
  461. processInterviewData(data) {
  462. // 清空现有问题列表
  463. this.questions = [];
  464. // 检查数据格式并处理
  465. if (data && data.question_form !== 0) { // 只处理非开放问题
  466. // 创建一个格式化的问题对象
  467. const formattedQuestion = {
  468. id: data.id || 1,
  469. text: data.question || '未知问题',
  470. options: data.options || [],
  471. correctAnswer: data.correctAnswer || 0,
  472. isImportant: data.is_system || false,
  473. explanation: data.explanation || '',
  474. questionType: data.question_form, // 1-单选题,2-多选题,3-看图答题
  475. questionTypeName: data.question_form_name || '单选题',
  476. is_required_correct: data.is_required_correct || false,
  477. correctAnswers: data.correct_answers || [],
  478. difficulty: data.difficulty || 1,
  479. difficultyName: data.difficulty_name || '初级',
  480. imageUrl: data.question_image_url || '' // 添加图片URL字段
  481. };
  482. // 添加到问题列表
  483. this.questions.push(formattedQuestion);
  484. // 设置总题目数
  485. this.totalQuestions = this.questions.length;
  486. /* // 启动倒计时
  487. this.startTimer(); */
  488. } else {
  489. this.handleLoadError('没有可用的选择题');
  490. }
  491. },
  492. // 处理加载错误
  493. handleLoadError(message) {
  494. this.loadError = true;
  495. this.loading = false;
  496. this.errorMessage = message || '加载失败';
  497. uni.showToast({
  498. title: message || '加载失败',
  499. icon: 'none',
  500. duration: 2000
  501. });
  502. },
  503. startTimer() {
  504. // 确保问题已加载
  505. if (this.questions.length === 0) return;
  506. // 记录开始时间
  507. this.questionStartTime = new Date();
  508. // 设置倒计时时间(秒)
  509. let seconds = 60; // 每题60秒,可以根据需要调整
  510. this.remainingTime = `01:00`;
  511. this.timerInterval = setInterval(() => {
  512. seconds--;
  513. if (seconds <= 0) {
  514. clearInterval(this.timerInterval);
  515. // 时间到,自动提交答案并进入下一题
  516. if (!this.showResult) {
  517. this.checkAnswer();
  518. // 短暂延迟后自动进入下一题
  519. setTimeout(() => {
  520. if (this.currentQuestionIndex < this.questions.length - 1) {
  521. this.goToNextQuestion();
  522. } else {
  523. // 如果是最后一题,显示结束模态框或跳转
  524. uni.navigateTo({
  525. url: '/pages/interview-question/interview-question'
  526. });
  527. }
  528. }, 1500);
  529. }
  530. }
  531. // 格式化显示时间 (不再显示,但仍然计算用于内部逻辑)
  532. const min = Math.floor(seconds / 60).toString().padStart(2, '0');
  533. const sec = (seconds % 60).toString().padStart(2, '0');
  534. this.remainingTime = `${min}:${sec}`;
  535. }, 1000);
  536. },
  537. resetTimer() {
  538. clearInterval(this.timerInterval);
  539. /* this.startTimer(); */
  540. },
  541. selectOption(index) {
  542. // 如果是最后一题且已经显示继续按钮,不允许重复作答
  543. if (this.currentQuestionIndex === this.questions.length - 1 && this.showContinueButton) {
  544. uni.showToast({
  545. title: '该题目已完成,请继续下一部分',
  546. icon: 'none',
  547. duration: 2000
  548. });
  549. return;
  550. }
  551. // 如果已经显示结果,不允许再次选择
  552. if (this.showResult) return;
  553. console.log('selectOption', index);
  554. // 判断当前题目类型
  555. if (this.currentQuestion.questionType === 2) {
  556. // 如果已经选中,则取消选中
  557. const optionIndex = this.selectedOptions.indexOf(index);
  558. if (optionIndex > -1) {
  559. this.selectedOptions.splice(optionIndex, 1);
  560. } else {
  561. // 否则添加到已选中数组
  562. this.selectedOptions.push(index);
  563. }
  564. // 多选题不自动提交,需要用户手动点击"提交答案"按钮
  565. } else if (this.currentQuestion.questionType === 1 || this.currentQuestion.questionType === 3 || this.currentQuestion.questionType === 4) {
  566. this.selectedOption = index;
  567. this.playAiSpeaking();
  568. setTimeout(() => {
  569. this.checkAnswer();
  570. this.saveAnswer();
  571. this.submitCurrentAnswer().then(() => {
  572. setTimeout(() => {
  573. this.goToNextQuestion();
  574. }, 800);
  575. }).catch(error => {
  576. console.error('提交答案失败:', error);
  577. setTimeout(() => {
  578. this.goToNextQuestion();
  579. }, 1000);
  580. });
  581. }, 500);
  582. } else {
  583. // 单选题逻辑
  584. this.selectedOption = index;
  585. // 保存答案到 answers 数组
  586. const answer = {
  587. questionId: this.currentQuestion.id,
  588. questionType: this.currentQuestion.questionType,
  589. answer: index
  590. };
  591. const existingIndex = this.answers.findIndex(a => a.questionId === answer.questionId);
  592. if (existingIndex > -1) {
  593. this.answers[existingIndex] = answer;
  594. } else {
  595. this.answers.push(answer);
  596. }
  597. this.playAiSpeaking();
  598. setTimeout(() => {
  599. this.checkAnswer();
  600. this.saveAnswer();
  601. this.submitCurrentAnswer().then(() => {
  602. setTimeout(() => {
  603. this.goToNextQuestion();
  604. }, 800);
  605. }).catch(error => {
  606. console.error('提交答案失败:', error);
  607. setTimeout(() => {
  608. this.goToNextQuestion();
  609. }, 1000);
  610. });
  611. }, 500);
  612. }
  613. },
  614. checkAnswer() {
  615. // 如果已经显示结果,说明已经提交过答案,不再重复提交
  616. if (this.showResult) return;
  617. clearInterval(this.timerInterval); // 停止计时
  618. // 确保当前问题存在
  619. if (!this.currentQuestion) {
  620. console.error('当前问题不存在');
  621. return;
  622. }
  623. // 根据题目类型检查答案是否正确
  624. if (this.currentQuestion.questionType === 0) {
  625. this.isAnswerCorrect = true;
  626. } else if (this.currentQuestion.questionType === 2) {
  627. const sortedSelected = [...this.selectedOptions].sort();
  628. const sortedCorrect = [...this.currentQuestion.correctAnswers].sort();
  629. if (sortedSelected.length !== sortedCorrect.length) {
  630. this.isAnswerCorrect = false;
  631. } else {
  632. this.isAnswerCorrect = sortedSelected.every((value, index) => value === sortedCorrect[index]);
  633. }
  634. } else {
  635. this.isAnswerCorrect = this.selectedOption === this.currentQuestion.correctAnswer;
  636. }
  637. // 显示结果
  638. this.showResult = true;
  639. // 保存当前题目的答案
  640. this.saveAnswer();
  641. // 如果是最后一题,确保状态被保存
  642. if (this.currentQuestionIndex === this.questions.length - 1) {
  643. this.$nextTick(() => {
  644. // 强制更新视图
  645. this.$forceUpdate();
  646. });
  647. }
  648. },
  649. // 修改 nextQuestion 方法,只处理多选题
  650. nextQuestion() {
  651. // 确保当前是多选题
  652. if (this.currentQuestion.questionType !== 2) return;
  653. // 检查答案并提交
  654. this.checkAnswer();
  655. // 保存当前题目的答案
  656. this.saveAnswer();
  657. // 提交答案
  658. this.submitCurrentAnswer().then(() => {
  659. // 提交成功后,短暂延迟后自动进入下一题
  660. setTimeout(() => {
  661. // 如果是最后一题,检查是否是最后一组题目
  662. if (this.currentQuestionIndex >= this.questions.length - 1) {
  663. if (this.currentGroupIndex < this.questionGroups.length - 1) {
  664. // 如果还有下一组题目,显示继续按钮
  665. this.showContinueButton = true;
  666. // 使用延时确保按钮渲染完成后再滚动
  667. setTimeout(() => {
  668. // 先重置 scrollTop,然后再设置新值,强制触发更新
  669. this.scrollTop = 0;
  670. // 使用 nextTick 确保视图已更新
  671. this.$nextTick(() => {
  672. // 延迟设置新的滚动位置
  673. setTimeout(() => {
  674. this.scrollTop = 10000; // 一个足够大的值
  675. }, 100);
  676. });
  677. }, 200);
  678. } else {
  679. // 如果是最后一组的最后一题,跳转到面试页面
  680. uni.navigateTo({
  681. url: '/pages/interview-question/interview-question'
  682. });
  683. }
  684. } else {
  685. // 否则进入下一题
  686. this.goToNextQuestion();
  687. }
  688. }, 500); // 0.5秒后自动进入下一题
  689. }).catch(error => {
  690. console.error('提交答案失败:', error);
  691. // 即使提交失败也继续下一题
  692. setTimeout(() => {
  693. if (this.currentQuestionIndex >= this.questions.length - 1) {
  694. if (this.currentGroupIndex < this.questionGroups.length - 1) {
  695. // 如果还有下一组题目,显示继续按钮
  696. this.showContinueButton = true;
  697. // 滚动到底部
  698. setTimeout(() => {
  699. this.scrollTop = 10000;
  700. }, 200);
  701. } else {
  702. // 如果是最后一组的最后一题,跳转到面试页面
  703. uni.navigateTo({
  704. url: '/pages/interview-question/interview-question'
  705. });
  706. }
  707. } else {
  708. this.goToNextQuestion();
  709. }
  710. }, 1000);
  711. });
  712. },
  713. toggleSettings() {
  714. // 打开设置面板
  715. uni.showToast({
  716. title: '设置功能开发中',
  717. icon: 'none'
  718. });
  719. },
  720. back(target) {
  721. // 清除计时器
  722. if (this.timerInterval) {
  723. clearInterval(this.timerInterval);
  724. }
  725. // 如果指定了跳转目标
  726. if (target) {
  727. uni.navigateTo({
  728. url: target
  729. });
  730. return;
  731. }
  732. // 否则尝试返回上一页,如果失败则跳转到首页
  733. // try {
  734. // const pages = getCurrentPages();
  735. // if (pages.length > 1) {
  736. // uni.reLaunch({
  737. // url: '/pages/index/index'
  738. // });
  739. // } else {
  740. // // 如果当前是第一页,则跳转到首页
  741. // uni.reLaunch({
  742. // url: '/pages/index/index'
  743. // });
  744. // }
  745. // } catch (e) {
  746. // console.error('导航错误:', e);
  747. // // 出错时也跳转到首页
  748. // uni.reLaunch({
  749. // url: '/pages/index/index'
  750. // });
  751. // }
  752. },
  753. error(e) {
  754. // 相机错误事件
  755. console.error(e.detail);
  756. uni.showToast({
  757. title: '相机启动失败,请检查权限设置',
  758. icon: 'none'
  759. });
  760. },
  761. playAiSpeaking() {
  762. if (this.useVideo && this.aiVideoContext) {
  763. this.aiVideoContext.play();
  764. }
  765. // 触发数字人说话动画
  766. if (this.digitalHumanUrl) {
  767. // 假设当前问题的文本作为数字人要说的内容
  768. const speakText = this.currentQuestion ? this.currentQuestion.text : '';
  769. this.interactWithDigitalHuman(speakText);
  770. }
  771. },
  772. pauseAiSpeaking() {
  773. if (this.useVideo && this.aiVideoContext) {
  774. this.aiVideoContext.pause();
  775. }
  776. },
  777. // 修改 restartTest 方法,添加可选的跳转目标
  778. restartTest(target) {
  779. this.currentQuestionIndex = 0;
  780. this.score = 0;
  781. this.showEndModal = false;
  782. this.showResult = false;
  783. this.selectedOption = null;
  784. this.selectedOptions = [];
  785. this.resetTimer();
  786. // 如果指定了跳转目标
  787. if (target) {
  788. uni.navigateTo({
  789. url: target
  790. });
  791. }
  792. },
  793. // 在methods中添加测试方法
  794. testEndScreen() {
  795. this.interviewCompleted = true;
  796. this.showEndModal = false;
  797. },
  798. // 初始化数字人
  799. initDigitalHuman() {
  800. // 移除不可用的示例URL
  801. // this.digitalHumanUrl = 'https://your-digital-human-service.com/avatar?id=123';
  802. // 暂时不使用数字人服务,直接使用本地图片
  803. this.digitalHumanUrl = '';
  804. // 如果您有实际可用的数字人服务,可以在这里设置
  805. // 例如:this.digitalHumanUrl = 'https://your-actual-service.com/avatar';
  806. // 或者使用本地HTML文件(如果有的话)
  807. // this.digitalHumanUrl = '/hybrid/html/digital-human.html';
  808. },
  809. // 与数字人交互的方法
  810. interactWithDigitalHuman(message) {
  811. // 如果数字人是通过web-view加载的,可以使用postMessage与其通信
  812. const webview = this.$mp.page.$getAppWebview().children()[0];
  813. if (webview) {
  814. webview.evalJS(`receiveMessage('${message}')`);
  815. }
  816. },
  817. // 添加 navigateToInterview 方法
  818. navigateToInterview() {
  819. // 关闭模态框
  820. this.showEndModal = false;
  821. // 跳转到interview页面
  822. uni.navigateTo({
  823. url: '/pages/interview/interview',
  824. success: () => {
  825. console.log('成功跳转到interview页面');
  826. },
  827. fail: (err) => {
  828. console.error('跳转失败:', err);
  829. uni.showToast({
  830. title: '跳转失败,请手动返回首页',
  831. icon: 'none'
  832. });
  833. }
  834. });
  835. },
  836. // 添加 handleCameraError 方法
  837. handleCameraError(e) {
  838. console.error('相机错误:', e.detail);
  839. uni.showToast({
  840. title: '相机启动失败,请检查权限设置',
  841. icon: 'none'
  842. });
  843. },
  844. // 修改 isOptionSelected 方法
  845. isOptionSelected(question, qIndex, optionIndex) {
  846. // 获取该题的答案
  847. const answer = this.answers.find(a => a.questionId === question.id);
  848. // 如果是当前正在回答的题目
  849. if (qIndex === this.currentQuestionIndex) {
  850. if (question.questionType === 1 || question.questionType === 3 || question.questionType === 4) {
  851. return this.selectedOption === optionIndex;
  852. } else if (question.questionType === 2) {
  853. return this.selectedOptions.includes(optionIndex);
  854. }
  855. }
  856. // 如果是已回答过的题目,使用保存的答案
  857. else if (answer) {
  858. if (question.questionType === 1 || question.questionType === 3 || question.questionType === 4) {
  859. return answer.answer === optionIndex;
  860. } else if (question.questionType === 2 && Array.isArray(answer.answer)) {
  861. return answer.answer.includes(optionIndex);
  862. }
  863. }
  864. return false;
  865. },
  866. // 修改 handleOptionClick 方法
  867. handleOptionClick(qIndex, index) {
  868. // 如果点击的是已完成的题目
  869. if (qIndex < this.currentQuestionIndex) {
  870. uni.showToast({
  871. title: '该题目已完成,无法修改',
  872. icon: 'none',
  873. duration: 2000
  874. });
  875. return;
  876. }
  877. // 如果是最后一题且已经显示继续按钮,不允许重复作答
  878. if (qIndex === this.questions.length - 1 && this.showContinueButton) {
  879. uni.showToast({
  880. title: '该题目已完成,请继续下一部分',
  881. icon: 'none',
  882. duration: 2000
  883. });
  884. return;
  885. }
  886. // 如果点击的是还未到的题目
  887. if (qIndex > this.currentQuestionIndex) {
  888. // 查找第一个未完成的题目索引
  889. const firstUnansweredIndex = this.currentQuestionIndex;
  890. uni.showToast({
  891. title: `请先完成第 ${firstUnansweredIndex + 1} 题`,
  892. icon: 'none',
  893. duration: 2000
  894. });
  895. // 滚动到当前应该做的题目
  896. this.currentScrollId = 'question-' + firstUnansweredIndex;
  897. return;
  898. }
  899. // 防重复点击
  900. if (this._isClicking) {
  901. return;
  902. }
  903. this._isClicking = true;
  904. // 清除之前的计时器
  905. if (this._clickTimer) {
  906. clearTimeout(this._clickTimer);
  907. }
  908. try {
  909. // 如果是当前题目,调用选择逻辑
  910. this.selectOption(index);
  911. // 设置延时,防止快速重复点击
  912. this._clickTimer = setTimeout(() => {
  913. this._isClicking = false;
  914. }, 1000);
  915. } catch (error) {
  916. console.error('处理选项点击失败:', error);
  917. uni.showToast({
  918. title: '操作失败,请重试',
  919. icon: 'none'
  920. });
  921. this._isClicking = false;
  922. }
  923. },
  924. // 处理题目分组
  925. processQuestionGroups(questions) {
  926. // 创建两个分组
  927. const group1 = []; // category 为 5 的题目
  928. const group2 = []; // 其他题目
  929. // 对题目进行分类
  930. questions.forEach(q => {
  931. if (q.category === 5) {
  932. group1.push(q);
  933. } else {
  934. group2.push(q);
  935. }
  936. });
  937. // 按照要求的顺序组合题目组:先显示其他题目,再显示 category 为 5 的题目
  938. this.questionGroups = [group2, group1].filter(group => group.length > 0);
  939. // 设置当前显示的题目
  940. this.questions = this.questionGroups[0] || [];
  941. },
  942. // 处理继续按钮点击
  943. handleContinue() {
  944. if (this.currentGroupIndex < this.questionGroups.length - 1) {
  945. // 检查是否是第一组结束
  946. if (this.currentGroupIndex === 0) {
  947. this.showPromptModal = true; // 显示提示弹窗
  948. } else {
  949. this.proceedToNextGroup();
  950. }
  951. } else {
  952. // 所有组都完成了,跳转到下一个页面
  953. uni.navigateTo({
  954. url: '/pages/interview-question/interview-question'
  955. });
  956. }
  957. },
  958. // 添加新的方法处理弹窗确认
  959. handlePromptConfirm() {
  960. this.showPromptModal = false;
  961. this.proceedToNextGroup();
  962. },
  963. // 添加新的方法处理组切换逻辑
  964. proceedToNextGroup() {
  965. this.currentGroupIndex++;
  966. this.questions = this.questionGroups[this.currentGroupIndex];
  967. this.currentQuestionIndex = 0;
  968. this.showContinueButton = false;
  969. this.currentScrollId = 'question-0';
  970. // 重置滚动位置
  971. this.scrollTop = 0;
  972. // 重置相关状态
  973. this.selectedOption = null;
  974. this.selectedOptions = [];
  975. this.showResult = false;
  976. },
  977. // 保存当前题目的答案
  978. saveAnswer() {
  979. let answer;
  980. if (this.currentQuestion.questionType === 0) { // 开放问题
  981. answer = {
  982. questionId: this.currentQuestion.id,
  983. questionType: this.currentQuestion.questionType,
  984. answer: this.openQuestionAnswer,
  985. answerDuration: this.getAnswerDuration() // 添加答题时长
  986. };
  987. } else if (this.currentQuestion.questionType === 1 || this.currentQuestion.questionType === 3 || this.currentQuestion.questionType === 4) { // 单选题、看图答题或类型4题目
  988. answer = {
  989. questionId: this.currentQuestion.id,
  990. questionType: this.currentQuestion.questionType,
  991. answer: this.selectedOption,
  992. answerDuration: this.getAnswerDuration() // 添加答题时长
  993. };
  994. } else { // 多选题
  995. answer = {
  996. questionId: this.currentQuestion.id,
  997. questionType: this.currentQuestion.questionType,
  998. answer: this.selectedOptions,
  999. answerDuration: this.getAnswerDuration() // 添加答题时长
  1000. };
  1001. }
  1002. // 检查是否已存在该题目的答案,如果存在则更新
  1003. const existingIndex = this.answers.findIndex(a => a.questionId === answer.questionId);
  1004. if (existingIndex > -1) {
  1005. this.answers[existingIndex] = answer;
  1006. } else {
  1007. this.answers.push(answer);
  1008. }
  1009. // 保存当前答案以便提交
  1010. this.currentAnswer = answer;
  1011. console.log('已保存答案:', this.answers);
  1012. },
  1013. // 获取答题时长(秒)
  1014. getAnswerDuration() {
  1015. // 这里假设每题默认30秒,根据剩余时间计算用时
  1016. // 您可以根据实际情况调整计算逻辑
  1017. const remainingTimeArr = this.remainingTime.split(':');
  1018. const remainingSeconds = parseInt(remainingTimeArr[0]) * 60 + parseInt(remainingTimeArr[1]);
  1019. return 30 - remainingSeconds; // 假设每题30秒
  1020. },
  1021. // 提交当前答案
  1022. async submitCurrentAnswer() {
  1023. if (!this.currentAnswer || this.isSubmitting) return; // 如果正在提交或没有答案,则不执行
  1024. try {
  1025. // 设置提交状态为true
  1026. this.isSubmitting = true;
  1027. // 显示提交中提示
  1028. uni.showLoading({
  1029. title: '正在提交答案...'
  1030. });
  1031. // 构建提交数据
  1032. let answerContent = '';
  1033. let answerOptions = [];
  1034. if (this.currentAnswer.questionType === 0) {
  1035. // 开放题直接使用文本答案
  1036. answerContent = this.currentAnswer.answer;
  1037. answerOptions = [];
  1038. } else if (this.currentAnswer.questionType === 1 || this.currentAnswer.questionType === 3 || this.currentAnswer.questionType === 4) {
  1039. // 单选题或看图答题,获取选项ID而不是索引
  1040. const selectedIndex = this.currentAnswer.answer;
  1041. const selectedOption = this.currentQuestion.options[selectedIndex];
  1042. console.log('selectedOption',selectedOption);
  1043. const optionId = selectedOption.id ? selectedOption.id : selectedIndex;
  1044. answerContent = optionId.toString();
  1045. answerOptions = [optionId];
  1046. } else if (this.currentAnswer.questionType === 2) {
  1047. // 多选题,将选项ID数组转为逗号分隔的字符串
  1048. const selectedIndices = this.currentAnswer.answer;
  1049. const selectedOptionIds = selectedIndices.map(index => {
  1050. const option = this.currentQuestion.options[index];
  1051. // 使用选项的ID或其他唯一标识符
  1052. return option.id ? option.id : index;
  1053. });
  1054. answerOptions = selectedOptionIds;
  1055. }
  1056. const submitData = {
  1057. position_id: JSON.parse(uni.getStorageSync('selectedJob')).id,
  1058. applicant_id: JSON.parse(uni.getStorageSync('userInfo')).id,
  1059. job_position_question_id: this.currentAnswer.questionId,
  1060. // answer_content: answerContent,
  1061. answer_options: answerOptions,
  1062. answer_duration: this.currentAnswer.answerDuration || 0,
  1063. tenant_id:JSON.parse(uni.getStorageSync('userInfo')).tenant_id || 1
  1064. };
  1065. console.log('提交数据:', submitData);
  1066. // 调用API提交答案
  1067. const res = await this.$http.post(`${apiBaseUrl}/api/job/submit_answer`, submitData);
  1068. console.log('提交答案响应:', res);
  1069. return res;
  1070. } catch (error) {
  1071. console.error('提交答案失败:', error);
  1072. // 显示错误提示
  1073. uni.showToast({
  1074. title: '提交答案失败,请重试',
  1075. icon: 'none'
  1076. });
  1077. throw error;
  1078. } finally {
  1079. // 隐藏加载提示
  1080. uni.hideLoading();
  1081. // 重置提交状态
  1082. this.isSubmitting = false;
  1083. }
  1084. },
  1085. // 修改 goToNextQuestion 方法
  1086. async goToNextQuestion() {
  1087. // 检查是否完成当前组的所有题目
  1088. if (this.currentQuestionIndex >= this.questions.length - 1) {
  1089. // 当前组的所有题目都已完成,显示继续按钮
  1090. this.showContinueButton = true;
  1091. // 使用延时确保按钮渲染完成后再滚动
  1092. setTimeout(() => {
  1093. // 先重置 scrollTop,然后再设置新值,强制触发更新
  1094. this.scrollTop = 0;
  1095. // 使用 nextTick 确保视图已更新
  1096. this.$nextTick(() => {
  1097. // 延迟设置新的滚动位置
  1098. setTimeout(() => {
  1099. this.scrollTop = 10000; // 一个足够大的值
  1100. }, 100);
  1101. });
  1102. }, 200);
  1103. return;
  1104. }
  1105. // 如果还有下一题,继续下一题
  1106. this.currentQuestionIndex++;
  1107. this.currentScrollId = 'question-' + this.currentQuestionIndex;
  1108. // 重置状态(只在非最后一题时重置)
  1109. this.showResult = false;
  1110. this.selectedOption = null;
  1111. this.selectedOptions = [];
  1112. this.openQuestionAnswer = '';
  1113. // 如果有下一题的详情
  1114. if (this.questions[this.currentQuestionIndex]) {
  1115. // 更新进度
  1116. this.progressWidth = (this.currentQuestionIndex + 1) / this.questions.length * 100;
  1117. // 重置计时器
  1118. this.resetTimer();
  1119. // 播放AI介绍下一题
  1120. this.playAiSpeaking();
  1121. setTimeout(() => {
  1122. this.pauseAiSpeaking();
  1123. }, 2000);
  1124. }
  1125. },
  1126. },
  1127. // 添加生命周期钩子,确保在组件销毁时清除计时器
  1128. beforeDestroy() {
  1129. if (this.timerInterval) {
  1130. clearInterval(this.timerInterval);
  1131. }
  1132. }
  1133. }
  1134. </script>
  1135. <style>
  1136. .camera-container {
  1137. position: relative;
  1138. width: 100%;
  1139. height: 100vh;
  1140. background-color: #ffffff;
  1141. display: flex;
  1142. flex-direction: column;
  1143. overflow: hidden; /* 防止内容溢出 */
  1144. }
  1145. .header {
  1146. height: 90rpx;
  1147. /* background-color: #000000; */
  1148. display: flex;
  1149. align-items: center;
  1150. padding: 0 30rpx;
  1151. /* color: #ffffff; */
  1152. }
  1153. .back-button {
  1154. width: 60rpx;
  1155. height: 60rpx;
  1156. display: flex;
  1157. align-items: center;
  1158. justify-content: center;
  1159. }
  1160. .title {
  1161. flex: 1;
  1162. text-align: center;
  1163. font-size: 32rpx;
  1164. font-weight: bold;
  1165. }
  1166. .controls {
  1167. display: flex;
  1168. gap: 30rpx;
  1169. }
  1170. .iconfont {
  1171. font-size: 40rpx;
  1172. }
  1173. .content {
  1174. flex: 1;
  1175. display: flex;
  1176. flex-direction: column;
  1177. position: relative;
  1178. padding: 50rpx 20rpx 0;
  1179. }
  1180. .progress-container {
  1181. display: flex;
  1182. flex-direction: column;
  1183. justify-content: space-between;
  1184. margin-bottom: 20rpx;
  1185. }
  1186. .progress-step {
  1187. display: flex;
  1188. align-items: center;
  1189. margin-bottom: 10rpx;
  1190. }
  1191. .step-circle {
  1192. width: 40rpx;
  1193. height: 40rpx;
  1194. border-radius: 50%;
  1195. background-color: #e0e0e0;
  1196. display: flex;
  1197. align-items: center;
  1198. justify-content: center;
  1199. font-size: 24rpx;
  1200. margin-right: 10rpx;
  1201. }
  1202. .step-circle.active {
  1203. background-color: #ff9500;
  1204. color: #ffffff;
  1205. }
  1206. .step-text {
  1207. font-size: 24rpx;
  1208. color: #666666;
  1209. }
  1210. .progress-bar {
  1211. height: 10rpx;
  1212. background-color: #e0e0e0;
  1213. border-radius: 5rpx;
  1214. overflow: hidden;
  1215. margin-bottom: 20rpx;
  1216. }
  1217. .progress-fill {
  1218. height: 100%;
  1219. background-color: #00c853;
  1220. transition: width 0.3s;
  1221. }
  1222. .interview-content {
  1223. flex: 1;
  1224. display: flex;
  1225. flex-direction: column;
  1226. margin-bottom: 40rpx;
  1227. padding: 20rpx;
  1228. border-bottom: 1px solid #eee;
  1229. }
  1230. .video-area {
  1231. display: flex;
  1232. /* flex-direction: column; */
  1233. justify-content: space-between;
  1234. height: auto;
  1235. margin-bottom: 20rpx;
  1236. }
  1237. .video-camera {
  1238. display: flex;
  1239. flex-direction: row;
  1240. align-items: center;
  1241. justify-content: space-between;
  1242. width: 65%;
  1243. }
  1244. .interviewer {
  1245. background-color: #f5f5f5;
  1246. display: flex;
  1247. align-items: center;
  1248. justify-content: center;
  1249. position: relative;
  1250. width: 48% !important;
  1251. height: 300rpx;
  1252. }
  1253. .interviewer-video {
  1254. width: 100%;
  1255. height: 100%;
  1256. object-fit: cover;
  1257. }
  1258. .interviewer-avatar {
  1259. width: 80%;
  1260. height: 80%;
  1261. object-fit: contain;
  1262. }
  1263. .user-camera-container {
  1264. width: 48%;
  1265. height: 300rpx;
  1266. border-radius: 10rpx;
  1267. overflow: hidden;
  1268. border: 4rpx solid #ffffff;
  1269. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.2);
  1270. }
  1271. .question-area {
  1272. flex: 1;
  1273. display: flex;
  1274. flex-direction: column;
  1275. }
  1276. .question-number {
  1277. font-size: 28rpx;
  1278. color: #666;
  1279. margin-bottom: 20rpx;
  1280. }
  1281. .question-importance {
  1282. background-color: #f9f9f9;
  1283. padding: 20rpx;
  1284. border-radius: 10rpx;
  1285. margin-bottom: 20rpx;
  1286. font-size: 28rpx;
  1287. color: #333;
  1288. }
  1289. .question-importance text {
  1290. color: #ff0000;
  1291. /* margin-right: 10rpx; */
  1292. }
  1293. .options {
  1294. display: flex;
  1295. flex-direction: column;
  1296. gap: 20rpx;
  1297. margin-bottom: 30rpx;
  1298. }
  1299. .option-item {
  1300. padding: 20rpx;
  1301. background-color: #f5f5f5;
  1302. border-radius: 10rpx;
  1303. font-size: 28rpx;
  1304. transition: all 0.3s;
  1305. border: 1px solid #e0e0e0;
  1306. display: flex;
  1307. align-items: center;
  1308. cursor: pointer; /* 添加指针样式 */
  1309. }
  1310. .option-item:active {
  1311. transform: scale(0.98); /* 点击时轻微缩小效果 */
  1312. opacity: 0.9;
  1313. }
  1314. .option-selected {
  1315. background-color: #e6f7ff;
  1316. border: 1px solid #1890ff;
  1317. }
  1318. /* 添加选中后的动画效果 */
  1319. @keyframes selectedPulse {
  1320. 0% { box-shadow: 0 0 0 0 rgba(24, 144, 255, 0.4); }
  1321. 70% { box-shadow: 0 0 0 10px rgba(24, 144, 255, 0); }
  1322. 100% { box-shadow: 0 0 0 0 rgba(24, 144, 255, 0); }
  1323. }
  1324. .option-selected {
  1325. animation: selectedPulse 1.5s ease-out;
  1326. }
  1327. .option-correct {
  1328. background-color: #d4f7d4;
  1329. border: 1px solid #52c41a;
  1330. }
  1331. .option-wrong {
  1332. background-color: #fff1f0;
  1333. border: 1px solid #ff4d4f;
  1334. }
  1335. .option-text {
  1336. color: #333;
  1337. }
  1338. .timer-container {
  1339. text-align: right;
  1340. margin: 20rpx 0;
  1341. }
  1342. .timer-text {
  1343. font-size: 24rpx;
  1344. color: #666;
  1345. background-color: #f0f0f0;
  1346. padding: 6rpx 12rpx;
  1347. border-radius: 6rpx;
  1348. }
  1349. .bottom-button-container {
  1350. position: fixed;
  1351. bottom: 50px;
  1352. left: 5%;
  1353. right: 0;
  1354. padding: 20rpx;
  1355. display: flex;
  1356. justify-content: center;
  1357. z-index: 10;
  1358. }
  1359. .bottom-button-wrapper {
  1360. display: flex;
  1361. width: 100%;
  1362. justify-content: space-between;
  1363. align-items: center;
  1364. }
  1365. .timer-display {
  1366. font-size: 28rpx;
  1367. color: #666;
  1368. padding: 10rpx 20rpx;
  1369. border-radius: 6rpx;
  1370. }
  1371. .next-button {
  1372. background-color: #0039b3;
  1373. color: #ffffff;
  1374. border-radius: 10rpx;
  1375. font-size: 30rpx;
  1376. height: 80rpx;
  1377. line-height: 80rpx;
  1378. width: 90%;
  1379. text-align: center;
  1380. margin: 0;
  1381. }
  1382. .footer {
  1383. height: 100rpx;
  1384. background-color: #000000;
  1385. display: flex;
  1386. justify-content: space-between;
  1387. align-items: center;
  1388. padding: 0 30rpx;
  1389. color: #ffffff;
  1390. }
  1391. .timer {
  1392. font-size: 28rpx;
  1393. }
  1394. .next-step {
  1395. font-size: 28rpx;
  1396. }
  1397. .interview-end-modal {
  1398. position: fixed;
  1399. top: 0;
  1400. left: 0;
  1401. right: 0;
  1402. bottom: 0;
  1403. background-color: rgba(0, 0, 0, 0.5);
  1404. display: flex;
  1405. align-items: center;
  1406. justify-content: center;
  1407. z-index: 999;
  1408. }
  1409. .modal-content {
  1410. width: 80%;
  1411. background-color: #ffffff;
  1412. border-radius: 20rpx;
  1413. padding: 40rpx;
  1414. display: flex;
  1415. flex-direction: column;
  1416. align-items: center;
  1417. }
  1418. .modal-title {
  1419. font-size: 36rpx;
  1420. font-weight: bold;
  1421. margin-bottom: 30rpx;
  1422. }
  1423. .score-display {
  1424. font-size: 48rpx;
  1425. font-weight: bold;
  1426. color: #0039b3;
  1427. margin: 20rpx 0;
  1428. }
  1429. .modal-message {
  1430. font-size: 28rpx;
  1431. color: #666;
  1432. text-align: center;
  1433. margin-bottom: 40rpx;
  1434. }
  1435. .modal-buttons {
  1436. display: flex;
  1437. justify-content: space-between;
  1438. width: 100%;
  1439. margin-top: 20rpx;
  1440. }
  1441. .modal-button {
  1442. width: 45%;
  1443. }
  1444. @keyframes speaking {
  1445. 0% {
  1446. opacity: 0.8;
  1447. }
  1448. 50% {
  1449. opacity: 1;
  1450. }
  1451. 100% {
  1452. opacity: 0.8;
  1453. }
  1454. }
  1455. .speaking {
  1456. animation: speaking 1.5s infinite;
  1457. }
  1458. .digital-avatar {
  1459. display: flex;
  1460. flex-direction: row;
  1461. align-items: flex-start;
  1462. justify-content: space-between;
  1463. width: 100%;
  1464. margin-bottom: 20rpx;
  1465. }
  1466. .message-box {
  1467. width: 65%;
  1468. min-height: 120rpx;
  1469. background-color: #f5f5f5;
  1470. border-radius: 10rpx;
  1471. padding: 15rpx;
  1472. margin-right: 20rpx;
  1473. display: flex;
  1474. align-items: center;
  1475. }
  1476. .message-text {
  1477. font-size: 24rpx;
  1478. color: #333;
  1479. line-height: 1.5;
  1480. }
  1481. .user-avatar {
  1482. width: 110px;
  1483. height: 160px;
  1484. border-radius: 10rpx;
  1485. overflow: hidden;
  1486. }
  1487. .camera {
  1488. width: 100%;
  1489. height: 100%;
  1490. border-radius: 10rpx;
  1491. border: 2rpx solid #e0e0e0;
  1492. }
  1493. .avatar-image {
  1494. width: 100%;
  1495. height: 100%;
  1496. border-radius: 10rpx;
  1497. border: 2rpx solid #e0e0e0;
  1498. }
  1499. .digital-human-webview {
  1500. width: 100%;
  1501. height: 100%;
  1502. border-radius: 10rpx;
  1503. border: 2rpx solid #e0e0e0;
  1504. }
  1505. .interview-complete-screen {
  1506. position: fixed;
  1507. top: 0;
  1508. left: 0;
  1509. right: 0;
  1510. bottom: 0;
  1511. background-color: #f0f5ff;
  1512. display: flex;
  1513. flex-direction: column;
  1514. align-items: center;
  1515. justify-content: center;
  1516. z-index: 1000;
  1517. padding: 40rpx;
  1518. }
  1519. .digital-avatar-large {
  1520. width: 200rpx;
  1521. height: 200rpx;
  1522. margin-bottom: 60rpx;
  1523. }
  1524. .avatar-image-large {
  1525. width: 100%;
  1526. height: 100%;
  1527. border-radius: 30rpx;
  1528. }
  1529. .complete-message {
  1530. font-size: 40rpx;
  1531. font-weight: bold;
  1532. color: #333;
  1533. margin-bottom: 30rpx;
  1534. }
  1535. .complete-description {
  1536. font-size: 28rpx;
  1537. color: #666;
  1538. text-align: center;
  1539. margin-bottom: 80rpx;
  1540. line-height: 1.5;
  1541. }
  1542. .complete-button {
  1543. background-color: #0039b3;
  1544. color: #ffffff;
  1545. border-radius: 10rpx;
  1546. font-size: 32rpx;
  1547. padding: 20rpx 60rpx;
  1548. margin-top: 40rpx;
  1549. }
  1550. /* 添加加载状态样式 */
  1551. .loading-container {
  1552. position: absolute;
  1553. top: 0;
  1554. left: 0;
  1555. right: 0;
  1556. bottom: 0;
  1557. display: flex;
  1558. flex-direction: column;
  1559. align-items: center;
  1560. justify-content: center;
  1561. background-color: rgba(255, 255, 255, 0.9);
  1562. z-index: 100;
  1563. }
  1564. .loading-text {
  1565. margin-top: 20rpx;
  1566. font-size: 28rpx;
  1567. color: #666;
  1568. }
  1569. .error-container {
  1570. text-align: center;
  1571. }
  1572. .error-message {
  1573. font-size: 28rpx;
  1574. color: #ff4d4f;
  1575. margin-bottom: 30rpx;
  1576. }
  1577. .retry-button {
  1578. background-color: #0039b3;
  1579. color: #ffffff;
  1580. border-radius: 10rpx;
  1581. font-size: 28rpx;
  1582. padding: 10rpx 30rpx;
  1583. }
  1584. .question-type {
  1585. display: inline-block;
  1586. /* background-color: #0039b3; */
  1587. color: white;
  1588. font-size: 24rpx;
  1589. /* padding: 4rpx 5rpx; */
  1590. border-radius: 6rpx;
  1591. /* margin-right: 10rpx; */
  1592. }
  1593. /* 新增的开放问题样式 */
  1594. .open-question-container {
  1595. display: flex;
  1596. flex-direction: column;
  1597. width: 100%;
  1598. margin-bottom: 20rpx;
  1599. }
  1600. .open-question-input {
  1601. width: 100%;
  1602. height: 300rpx;
  1603. background-color: #f9f9f9;
  1604. border: 1px solid #e0e0e0;
  1605. border-radius: 10rpx;
  1606. padding: 20rpx;
  1607. font-size: 28rpx;
  1608. color: #333;
  1609. }
  1610. .word-count {
  1611. text-align: right;
  1612. font-size: 24rpx;
  1613. color: #999;
  1614. margin-top: 10rpx;
  1615. }
  1616. .option-prefix {
  1617. margin-right: 10rpx;
  1618. font-weight: bold;
  1619. color: #333;
  1620. min-width: 30rpx;
  1621. }
  1622. /* 新增的图片显示样式 */
  1623. .question-image-container {
  1624. width: 100%;
  1625. margin: 20rpx 0;
  1626. display: flex;
  1627. justify-content: center;
  1628. align-items: center;
  1629. }
  1630. .question-image {
  1631. width: 100%;
  1632. max-width: 600rpx;
  1633. border-radius: 10rpx;
  1634. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
  1635. }
  1636. /* 添加滚动视图样式 */
  1637. .content-scroll {
  1638. flex: 1;
  1639. height: calc(100vh - 200px); /* 只减去顶部相机的高度 */
  1640. margin-top: 10px;
  1641. }
  1642. /* 添加底部空白区域,防止内容被固定按钮遮挡 */
  1643. .bottom-space {
  1644. height: 50rpx; /* 减小底部空白区域 */
  1645. }
  1646. /* 添加流式布局相关样式 */
  1647. .interview-content {
  1648. margin-bottom: 40rpx;
  1649. padding: 20rpx;
  1650. border-bottom: 1px solid #eee;
  1651. }
  1652. .option-disabled {
  1653. opacity: 0.7;
  1654. background-color: #f0f0f0;
  1655. }
  1656. .question-button-container {
  1657. margin-top: 20rpx;
  1658. display: flex;
  1659. justify-content: center;
  1660. }
  1661. .bottom-timer-container {
  1662. display: none;
  1663. }
  1664. /* 添加固定相机容器样式 */
  1665. .fixed-camera-container {
  1666. position: sticky;
  1667. top: 0;
  1668. width: 100%;
  1669. padding: 20rpx;
  1670. background-color: #fff;
  1671. z-index: 10;
  1672. display: flex;
  1673. justify-content: flex-start;
  1674. border-bottom: 1px solid #eee;
  1675. }
  1676. .camera-warning {
  1677. animation: camera-warning-flash 1s ease-in-out infinite;
  1678. border: 2px solid #ff0000;
  1679. }
  1680. @keyframes camera-warning-flash {
  1681. 0% {
  1682. border-color: #ff0000;
  1683. box-shadow: 0 0 15px rgba(255, 0, 0, 0.8);
  1684. }
  1685. 50% {
  1686. border-color: rgba(255, 0, 0, 0.3);
  1687. box-shadow: 0 0 5px rgba(255, 0, 0, 0.4);
  1688. }
  1689. 100% {
  1690. border-color: #ff0000;
  1691. box-shadow: 0 0 15px rgba(255, 0, 0, 0.8);
  1692. }
  1693. }
  1694. .user-avatar {
  1695. width: 110px;
  1696. height: 160px;
  1697. border-radius: 10rpx;
  1698. overflow: hidden;
  1699. }
  1700. /* 添加继续按钮样式 */
  1701. .continue-button-container {
  1702. display: flex;
  1703. justify-content: center;
  1704. padding: 20rpx;
  1705. margin-top: 20rpx;
  1706. }
  1707. .continue-button {
  1708. background-color: #0039b3;
  1709. color: #ffffff;
  1710. border-radius: 10rpx;
  1711. font-size: 30rpx;
  1712. height: 80rpx;
  1713. line-height: 80rpx;
  1714. width: 90%;
  1715. text-align: center;
  1716. }
  1717. /* 添加新的样式 */
  1718. .prompt-modal {
  1719. position: fixed;
  1720. top: 0;
  1721. left: 0;
  1722. right: 0;
  1723. bottom: 0;
  1724. background-color: rgba(0, 0, 0, 0.5);
  1725. display: flex;
  1726. align-items: center;
  1727. justify-content: center;
  1728. z-index: 1000;
  1729. }
  1730. .prompt-content {
  1731. width: 85%;
  1732. background-color: #ffffff;
  1733. border-radius: 20rpx;
  1734. padding: 40rpx;
  1735. display: flex;
  1736. flex-direction: column;
  1737. align-items: center;
  1738. }
  1739. .prompt-title {
  1740. font-size: 36rpx;
  1741. font-weight: bold;
  1742. color: #333;
  1743. margin-bottom: 30rpx;
  1744. }
  1745. .prompt-text {
  1746. font-size: 28rpx;
  1747. color: #666;
  1748. line-height: 1.6;
  1749. margin-bottom: 20rpx;
  1750. text-align: justify;
  1751. }
  1752. .bold-text {
  1753. font-weight: bold;
  1754. color: #333;
  1755. }
  1756. .prompt-button {
  1757. background-color: #0039b3;
  1758. color: #ffffff;
  1759. border-radius: 10rpx;
  1760. font-size: 30rpx;
  1761. height: 80rpx;
  1762. line-height: 80rpx;
  1763. width: 60%;
  1764. text-align: center;
  1765. margin-top: 30rpx;
  1766. }
  1767. </style>