camera.vue 53 KB

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