camera.vue 53 KB

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