camera.vue 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059
  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. }, 5000);
  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'//'/pages/interview-question/interview-question'
  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) {
  558. this.showResult = false;
  559. }
  560. console.log('selectOption', index);
  561. // 判断当前题目类型
  562. if (this.currentQuestion.questionType === 2) {
  563. // 如果已经选中,则取消选中
  564. const optionIndex = this.selectedOptions.indexOf(index);
  565. if (optionIndex > -1) {
  566. this.selectedOptions.splice(optionIndex, 1);
  567. } else {
  568. // 否则添加到已选中数组
  569. this.selectedOptions.push(index);
  570. }
  571. // 多选题不自动提交,需要用户手动点击"提交答案"按钮
  572. } else if (this.currentQuestion.questionType === 1 || this.currentQuestion.questionType === 3 || this.currentQuestion.questionType === 4) {
  573. this.selectedOption = index;
  574. this.playAiSpeaking();
  575. setTimeout(() => {
  576. this.checkAnswer();
  577. this.saveAnswer();
  578. this.submitCurrentAnswer().then(() => {
  579. setTimeout(() => {
  580. // 如果是在回答上一题,完成后要回到当前题目
  581. if (this.currentQuestionIndex < this.answers.length - 1) {
  582. this.currentQuestionIndex++;
  583. this.currentScrollId = 'question-' + this.currentQuestionIndex;
  584. } else {
  585. this.goToNextQuestion();
  586. }
  587. }, 800);
  588. }).catch(error => {
  589. console.error('提交答案失败:', error);
  590. setTimeout(() => {
  591. if (this.currentQuestionIndex < this.answers.length - 1) {
  592. this.currentQuestionIndex++;
  593. this.currentScrollId = 'question-' + this.currentQuestionIndex;
  594. } else {
  595. this.goToNextQuestion();
  596. }
  597. }, 1000);
  598. });
  599. }, 500);
  600. } else {
  601. // 单选题逻辑
  602. this.selectedOption = index;
  603. // 保存答案到 answers 数组
  604. const answer = {
  605. questionId: this.currentQuestion.id,
  606. questionType: this.currentQuestion.questionType,
  607. answer: index
  608. };
  609. const existingIndex = this.answers.findIndex(a => a.questionId === answer.questionId);
  610. if (existingIndex > -1) {
  611. this.answers[existingIndex] = answer;
  612. } else {
  613. this.answers.push(answer);
  614. }
  615. this.playAiSpeaking();
  616. setTimeout(() => {
  617. this.checkAnswer();
  618. this.saveAnswer();
  619. this.submitCurrentAnswer().then(() => {
  620. setTimeout(() => {
  621. // 如果是在回答上一题,完成后要回到当前题目
  622. if (this.currentQuestionIndex < this.answers.length - 1) {
  623. this.currentQuestionIndex++;
  624. this.currentScrollId = 'question-' + this.currentQuestionIndex;
  625. } else {
  626. this.goToNextQuestion();
  627. }
  628. }, 800);
  629. }).catch(error => {
  630. console.error('提交答案失败:', error);
  631. setTimeout(() => {
  632. if (this.currentQuestionIndex < this.answers.length - 1) {
  633. this.currentQuestionIndex++;
  634. this.currentScrollId = 'question-' + this.currentQuestionIndex;
  635. } else {
  636. this.goToNextQuestion();
  637. }
  638. }, 1000);
  639. });
  640. }, 500);
  641. }
  642. },
  643. checkAnswer() {
  644. // 如果已经显示结果,说明已经提交过答案,不再重复提交
  645. if (this.showResult) return;
  646. clearInterval(this.timerInterval); // 停止计时
  647. // 确保当前问题存在
  648. if (!this.currentQuestion) {
  649. console.error('当前问题不存在');
  650. return;
  651. }
  652. // 根据题目类型检查答案是否正确
  653. if (this.currentQuestion.questionType === 0) {
  654. this.isAnswerCorrect = true;
  655. } else if (this.currentQuestion.questionType === 2) {
  656. const sortedSelected = [...this.selectedOptions].sort();
  657. const sortedCorrect = [...this.currentQuestion.correctAnswers].sort();
  658. if (sortedSelected.length !== sortedCorrect.length) {
  659. this.isAnswerCorrect = false;
  660. } else {
  661. this.isAnswerCorrect = sortedSelected.every((value, index) => value === sortedCorrect[index]);
  662. }
  663. } else {
  664. this.isAnswerCorrect = this.selectedOption === this.currentQuestion.correctAnswer;
  665. }
  666. // 显示结果
  667. this.showResult = true;
  668. // 保存当前题目的答案
  669. this.saveAnswer();
  670. // 如果是最后一题,确保状态被保存
  671. if (this.currentQuestionIndex === this.questions.length - 1) {
  672. this.$nextTick(() => {
  673. // 强制更新视图
  674. this.$forceUpdate();
  675. });
  676. }
  677. },
  678. // 修改 nextQuestion 方法,只处理多选题
  679. nextQuestion() {
  680. // 确保当前是多选题
  681. if (this.currentQuestion.questionType !== 2) return;
  682. // 检查答案并提交
  683. this.checkAnswer();
  684. // 保存当前题目的答案
  685. this.saveAnswer();
  686. // 提交答案
  687. this.submitCurrentAnswer().then(() => {
  688. // 提交成功后,短暂延迟后自动进入下一题
  689. setTimeout(() => {
  690. // 如果是最后一题,检查是否是最后一组题目
  691. if (this.currentQuestionIndex >= this.questions.length - 1) {
  692. if (this.currentGroupIndex < this.questionGroups.length - 1) {
  693. // 如果还有下一组题目,显示继续按钮
  694. this.showContinueButton = true;
  695. // 使用延时确保按钮渲染完成后再滚动
  696. setTimeout(() => {
  697. // 先重置 scrollTop,然后再设置新值,强制触发更新
  698. this.scrollTop = 0;
  699. // 使用 nextTick 确保视图已更新
  700. this.$nextTick(() => {
  701. // 延迟设置新的滚动位置
  702. setTimeout(() => {
  703. this.scrollTop = 10000; // 一个足够大的值
  704. }, 100);
  705. });
  706. }, 200);
  707. } else {
  708. // 如果是最后一组的最后一题,跳转到面试页面
  709. uni.navigateTo({
  710. url: '/pages/posture-guide/posture-guide'//'/pages/interview-question/interview-question'
  711. });
  712. }
  713. } else {
  714. // 否则进入下一题
  715. this.goToNextQuestion();
  716. }
  717. }, 500); // 0.5秒后自动进入下一题
  718. }).catch(error => {
  719. console.error('提交答案失败:', error);
  720. // 即使提交失败也继续下一题
  721. setTimeout(() => {
  722. if (this.currentQuestionIndex >= this.questions.length - 1) {
  723. if (this.currentGroupIndex < this.questionGroups.length - 1) {
  724. // 如果还有下一组题目,显示继续按钮
  725. this.showContinueButton = true;
  726. // 滚动到底部
  727. setTimeout(() => {
  728. this.scrollTop = 10000;
  729. }, 200);
  730. } else {
  731. // 如果是最后一组的最后一题,跳转到面试页面
  732. uni.navigateTo({
  733. url: '/pages/posture-guide/posture-guide'//'/pages/interview-question/interview-question'
  734. });
  735. }
  736. } else {
  737. this.goToNextQuestion();
  738. }
  739. }, 1000);
  740. });
  741. },
  742. toggleSettings() {
  743. // 打开设置面板
  744. uni.showToast({
  745. title: '设置功能开发中',
  746. icon: 'none'
  747. });
  748. },
  749. back(target) {
  750. // 清除计时器
  751. if (this.timerInterval) {
  752. clearInterval(this.timerInterval);
  753. }
  754. // 如果指定了跳转目标
  755. if (target) {
  756. uni.navigateTo({
  757. url: target
  758. });
  759. return;
  760. }
  761. // 否则尝试返回上一页,如果失败则跳转到首页
  762. // try {
  763. // const pages = getCurrentPages();
  764. // if (pages.length > 1) {
  765. // uni.reLaunch({
  766. // url: '/pages/index/index'
  767. // });
  768. // } else {
  769. // // 如果当前是第一页,则跳转到首页
  770. // uni.reLaunch({
  771. // url: '/pages/index/index'
  772. // });
  773. // }
  774. // } catch (e) {
  775. // console.error('导航错误:', e);
  776. // // 出错时也跳转到首页
  777. // uni.reLaunch({
  778. // url: '/pages/index/index'
  779. // });
  780. // }
  781. },
  782. error(e) {
  783. // 相机错误事件
  784. console.error(e.detail);
  785. uni.showToast({
  786. title: '相机启动失败,请检查权限设置',
  787. icon: 'none'
  788. });
  789. },
  790. playAiSpeaking() {
  791. if (this.useVideo && this.aiVideoContext) {
  792. this.aiVideoContext.play();
  793. }
  794. // 触发数字人说话动画
  795. if (this.digitalHumanUrl) {
  796. // 假设当前问题的文本作为数字人要说的内容
  797. const speakText = this.currentQuestion ? this.currentQuestion.text : '';
  798. this.interactWithDigitalHuman(speakText);
  799. }
  800. },
  801. pauseAiSpeaking() {
  802. if (this.useVideo && this.aiVideoContext) {
  803. this.aiVideoContext.pause();
  804. }
  805. },
  806. // 修改 restartTest 方法,添加可选的跳转目标
  807. restartTest(target) {
  808. this.currentQuestionIndex = 0;
  809. this.score = 0;
  810. this.showEndModal = false;
  811. this.showResult = false;
  812. this.selectedOption = null;
  813. this.selectedOptions = [];
  814. this.resetTimer();
  815. // 如果指定了跳转目标
  816. if (target) {
  817. uni.navigateTo({
  818. url: target
  819. });
  820. }
  821. },
  822. // 在methods中添加测试方法
  823. testEndScreen() {
  824. this.interviewCompleted = true;
  825. this.showEndModal = false;
  826. },
  827. // 初始化数字人
  828. initDigitalHuman() {
  829. // 移除不可用的示例URL
  830. // this.digitalHumanUrl = 'https://your-digital-human-service.com/avatar?id=123';
  831. // 暂时不使用数字人服务,直接使用本地图片
  832. this.digitalHumanUrl = '';
  833. // 如果您有实际可用的数字人服务,可以在这里设置
  834. // 例如:this.digitalHumanUrl = 'https://your-actual-service.com/avatar';
  835. // 或者使用本地HTML文件(如果有的话)
  836. // this.digitalHumanUrl = '/hybrid/html/digital-human.html';
  837. },
  838. // 与数字人交互的方法
  839. interactWithDigitalHuman(message) {
  840. // 如果数字人是通过web-view加载的,可以使用postMessage与其通信
  841. const webview = this.$mp.page.$getAppWebview().children()[0];
  842. if (webview) {
  843. webview.evalJS(`receiveMessage('${message}')`);
  844. }
  845. },
  846. // 添加 navigateToInterview 方法
  847. navigateToInterview() {
  848. // 关闭模态框
  849. this.showEndModal = false;
  850. // 跳转到interview页面
  851. uni.navigateTo({
  852. url: '/pages/interview/interview',
  853. success: () => {
  854. console.log('成功跳转到interview页面');
  855. },
  856. fail: (err) => {
  857. console.error('跳转失败:', err);
  858. uni.showToast({
  859. title: '跳转失败,请手动返回首页',
  860. icon: 'none'
  861. });
  862. }
  863. });
  864. },
  865. // 添加 handleCameraError 方法
  866. handleCameraError(e) {
  867. console.error('相机错误:', e.detail);
  868. uni.showToast({
  869. title: '相机启动失败,请检查权限设置',
  870. icon: 'none'
  871. });
  872. },
  873. // 修改 isOptionSelected 方法
  874. isOptionSelected(question, qIndex, optionIndex) {
  875. // 获取该题的答案
  876. const answer = this.answers.find(a => a.questionId === question.id);
  877. // 如果是当前正在回答的题目
  878. if (qIndex === this.currentQuestionIndex) {
  879. if (question.questionType === 1 || question.questionType === 3 || question.questionType === 4) {
  880. return this.selectedOption === optionIndex;
  881. } else if (question.questionType === 2) {
  882. return this.selectedOptions.includes(optionIndex);
  883. }
  884. }
  885. // 如果是已回答过的题目,使用保存的答案
  886. else if (answer) {
  887. if (question.questionType === 1 || question.questionType === 3 || question.questionType === 4) {
  888. return answer.answer === optionIndex;
  889. } else if (question.questionType === 2 && Array.isArray(answer.answer)) {
  890. return answer.answer.includes(optionIndex);
  891. }
  892. }
  893. return false;
  894. },
  895. // 修改 handleOptionClick 方法
  896. handleOptionClick(qIndex, index) {
  897. // 如果点击的是已完成的题目,但不是上一题
  898. if (qIndex < this.currentQuestionIndex - 1) {
  899. /* uni.showToast({
  900. title: '只能修改上一题的答案',
  901. icon: 'none',
  902. duration: 2000
  903. }); */
  904. return;
  905. }
  906. // 如果是最后一题且已经显示继续按钮,不允许重复作答
  907. if (qIndex === this.questions.length - 1 && this.showContinueButton) {
  908. uni.showToast({
  909. title: '该题目已完成,请继续下一部分',
  910. icon: 'none',
  911. duration: 2000
  912. });
  913. return;
  914. }
  915. // 如果点击的是还未到的题目
  916. if (qIndex > this.currentQuestionIndex) {
  917. // 查找第一个未完成的题目索引
  918. const firstUnansweredIndex = this.currentQuestionIndex;
  919. uni.showToast({
  920. title: `请先完成第 ${firstUnansweredIndex + 1} 题`,
  921. icon: 'none',
  922. duration: 2000
  923. });
  924. // 滚动到当前应该做的题目
  925. this.currentScrollId = 'question-' + firstUnansweredIndex;
  926. return;
  927. }
  928. // 防重复点击
  929. if (this._isClicking) {
  930. return;
  931. }
  932. this._isClicking = true;
  933. // 清除之前的计时器
  934. if (this._clickTimer) {
  935. clearTimeout(this._clickTimer);
  936. }
  937. try {
  938. // 如果是上一题,先切换到上一题
  939. if (qIndex === this.currentQuestionIndex - 1) {
  940. this.currentQuestionIndex = qIndex;
  941. this.currentScrollId = 'question-' + qIndex;
  942. // 重置相关状态
  943. this.showResult = false;
  944. this.selectedOption = null;
  945. this.selectedOptions = [];
  946. }
  947. // 调用选择逻辑
  948. this.selectOption(index);
  949. // 设置延时,防止快速重复点击
  950. this._clickTimer = setTimeout(() => {
  951. this._isClicking = false;
  952. }, 1000);
  953. } catch (error) {
  954. console.error('处理选项点击失败:', error);
  955. uni.showToast({
  956. title: '操作失败,请重试',
  957. icon: 'none'
  958. });
  959. this._isClicking = false;
  960. }
  961. },
  962. // 处理题目分组
  963. processQuestionGroups(questions) {
  964. // 创建两个分组
  965. const group1 = []; // category 为 5 的题目
  966. const group2 = []; // 其他题目
  967. // 对题目进行分类
  968. questions.forEach(q => {
  969. if (q.category === 5) {
  970. group1.push(q);
  971. } else {
  972. group2.push(q);
  973. }
  974. });
  975. // 按照要求的顺序组合题目组:先显示其他题目,再显示 category 为 5 的题目
  976. this.questionGroups = [group2, group1].filter(group => group.length > 0);
  977. // 设置当前显示的题目
  978. this.questions = this.questionGroups[0] || [];
  979. },
  980. // 处理继续按钮点击
  981. handleContinue() {
  982. if (this.currentGroupIndex < this.questionGroups.length - 1) {
  983. // 检查是否是第一组结束
  984. if (this.currentGroupIndex === 0) {
  985. this.showPromptModal = true; // 显示提示弹窗
  986. } else {
  987. this.proceedToNextGroup();
  988. }
  989. } else {
  990. // 所有组都完成了,跳转到下一个页面
  991. uni.navigateTo({
  992. url: '/pages/posture-guide/posture-guide'//'/pages/interview-question/interview-question'
  993. });
  994. }
  995. },
  996. // 添加新的方法处理弹窗确认
  997. handlePromptConfirm() {
  998. this.showPromptModal = false;
  999. this.proceedToNextGroup();
  1000. },
  1001. // 添加新的方法处理组切换逻辑
  1002. proceedToNextGroup() {
  1003. this.currentGroupIndex++;
  1004. this.questions = this.questionGroups[this.currentGroupIndex];
  1005. this.currentQuestionIndex = 0;
  1006. this.showContinueButton = false;
  1007. this.currentScrollId = 'question-0';
  1008. // 重置滚动位置
  1009. this.scrollTop = 0;
  1010. // 重置相关状态
  1011. this.selectedOption = null;
  1012. this.selectedOptions = [];
  1013. this.showResult = false;
  1014. },
  1015. // 保存当前题目的答案
  1016. saveAnswer() {
  1017. let answer;
  1018. if (this.currentQuestion.questionType === 0) { // 开放问题
  1019. answer = {
  1020. questionId: this.currentQuestion.id,
  1021. questionType: this.currentQuestion.questionType,
  1022. answer: this.openQuestionAnswer,
  1023. answerDuration: this.getAnswerDuration() // 添加答题时长
  1024. };
  1025. } else if (this.currentQuestion.questionType === 1 || this.currentQuestion.questionType === 3 || this.currentQuestion.questionType === 4) { // 单选题、看图答题或类型4题目
  1026. answer = {
  1027. questionId: this.currentQuestion.id,
  1028. questionType: this.currentQuestion.questionType,
  1029. answer: this.selectedOption,
  1030. answerDuration: this.getAnswerDuration() // 添加答题时长
  1031. };
  1032. } else { // 多选题
  1033. answer = {
  1034. questionId: this.currentQuestion.id,
  1035. questionType: this.currentQuestion.questionType,
  1036. answer: this.selectedOptions,
  1037. answerDuration: this.getAnswerDuration() // 添加答题时长
  1038. };
  1039. }
  1040. // 检查是否已存在该题目的答案,如果存在则更新
  1041. const existingIndex = this.answers.findIndex(a => a.questionId === answer.questionId);
  1042. if (existingIndex > -1) {
  1043. this.answers[existingIndex] = answer;
  1044. } else {
  1045. this.answers.push(answer);
  1046. }
  1047. // 保存当前答案以便提交
  1048. this.currentAnswer = answer;
  1049. console.log('已保存答案:', this.answers);
  1050. },
  1051. // 获取答题时长(秒)
  1052. getAnswerDuration() {
  1053. // 这里假设每题默认30秒,根据剩余时间计算用时
  1054. // 您可以根据实际情况调整计算逻辑
  1055. const remainingTimeArr = this.remainingTime.split(':');
  1056. const remainingSeconds = parseInt(remainingTimeArr[0]) * 60 + parseInt(remainingTimeArr[1]);
  1057. return 30 - remainingSeconds; // 假设每题30秒
  1058. },
  1059. // 提交当前答案
  1060. async submitCurrentAnswer() {
  1061. if (!this.currentAnswer || this.isSubmitting) return; // 如果正在提交或没有答案,则不执行
  1062. try {
  1063. // 设置提交状态为true
  1064. this.isSubmitting = true;
  1065. // 显示提交中提示
  1066. // uni.showLoading({
  1067. // title: '正在提交答案...'
  1068. // });
  1069. // 构建提交数据
  1070. let answerContent = '';
  1071. let answerOptions = [];
  1072. if (this.currentAnswer.questionType === 0) {
  1073. // 开放题直接使用文本答案
  1074. answerContent = this.currentAnswer.answer;
  1075. answerOptions = [];
  1076. } else if (this.currentAnswer.questionType === 1 || this.currentAnswer.questionType === 3 || this.currentAnswer.questionType === 4) {
  1077. // 单选题或看图答题,获取选项ID而不是索引
  1078. const selectedIndex = this.currentAnswer.answer;
  1079. const selectedOption = this.currentQuestion.options[selectedIndex];
  1080. console.log('selectedOption',selectedOption);
  1081. const optionId = selectedOption.id ? selectedOption.id : selectedIndex;
  1082. answerContent = optionId.toString();
  1083. answerOptions = [optionId];
  1084. } else if (this.currentAnswer.questionType === 2) {
  1085. // 多选题,将选项ID数组转为逗号分隔的字符串
  1086. const selectedIndices = this.currentAnswer.answer;
  1087. const selectedOptionIds = selectedIndices.map(index => {
  1088. const option = this.currentQuestion.options[index];
  1089. // 使用选项的ID或其他唯一标识符
  1090. return option.id ? option.id : index;
  1091. });
  1092. answerOptions = selectedOptionIds;
  1093. }
  1094. const submitData = {
  1095. position_id: JSON.parse(uni.getStorageSync('selectedJob')).id,
  1096. applicant_id: JSON.parse(uni.getStorageSync('userInfo')).id,
  1097. job_position_question_id: this.currentAnswer.questionId,
  1098. // answer_content: answerContent,
  1099. answer_options: answerOptions,
  1100. answer_duration: this.currentAnswer.answerDuration || 0,
  1101. tenant_id:JSON.parse(uni.getStorageSync('userInfo')).tenant_id || 1
  1102. };
  1103. console.log('提交数据:', submitData);
  1104. // 调用API提交答案
  1105. const res = await this.$http.post(`${apiBaseUrl}/api/job/submit_answer`, submitData);
  1106. console.log('提交答案响应:', res);
  1107. return res;
  1108. } catch (error) {
  1109. console.error('提交答案失败:', error);
  1110. // 显示错误提示
  1111. uni.showToast({
  1112. title: '提交答案失败,请重试',
  1113. icon: 'none'
  1114. });
  1115. throw error;
  1116. } finally {
  1117. // 隐藏加载提示
  1118. uni.hideLoading();
  1119. // 重置提交状态
  1120. this.isSubmitting = false;
  1121. }
  1122. },
  1123. // 修改 goToNextQuestion 方法
  1124. async goToNextQuestion() {
  1125. // 检查是否完成当前组的所有题目
  1126. if (this.currentQuestionIndex >= this.questions.length - 1) {
  1127. // 当前组的所有题目都已完成,显示继续按钮
  1128. this.showContinueButton = true;
  1129. // 使用延时确保按钮渲染完成后再滚动
  1130. setTimeout(() => {
  1131. // 先重置 scrollTop,然后再设置新值,强制触发更新
  1132. this.scrollTop = 0;
  1133. // 使用 nextTick 确保视图已更新
  1134. this.$nextTick(() => {
  1135. // 延迟设置新的滚动位置
  1136. setTimeout(() => {
  1137. this.scrollTop = 10000; // 一个足够大的值
  1138. }, 100);
  1139. });
  1140. }, 200);
  1141. return;
  1142. }
  1143. // 如果还有下一题,继续下一题
  1144. this.currentQuestionIndex++;
  1145. this.currentScrollId = 'question-' + this.currentQuestionIndex;
  1146. // 重置状态(只在非最后一题时重置)
  1147. this.showResult = false;
  1148. this.selectedOption = null;
  1149. this.selectedOptions = [];
  1150. this.openQuestionAnswer = '';
  1151. // 如果有下一题的详情
  1152. if (this.questions[this.currentQuestionIndex]) {
  1153. // 更新进度
  1154. this.progressWidth = (this.currentQuestionIndex + 1) / this.questions.length * 100;
  1155. // 重置计时器
  1156. this.resetTimer();
  1157. // 播放AI介绍下一题
  1158. this.playAiSpeaking();
  1159. setTimeout(() => {
  1160. this.pauseAiSpeaking();
  1161. }, 2000);
  1162. }
  1163. },
  1164. },
  1165. // 添加生命周期钩子,确保在组件销毁时清除计时器
  1166. beforeDestroy() {
  1167. if (this.timerInterval) {
  1168. clearInterval(this.timerInterval);
  1169. }
  1170. }
  1171. }
  1172. </script>
  1173. <style>
  1174. .camera-container {
  1175. position: relative;
  1176. margin-top: 25px;
  1177. width: 100%;
  1178. height: 96vh;
  1179. background-color: #ffffff;
  1180. display: flex;
  1181. flex-direction: column;
  1182. overflow: hidden; /* 防止内容溢出 */
  1183. }
  1184. .header {
  1185. height: 90rpx;
  1186. /* background-color: #000000; */
  1187. display: flex;
  1188. align-items: center;
  1189. padding: 0 30rpx;
  1190. /* color: #ffffff; */
  1191. }
  1192. .back-button {
  1193. width: 60rpx;
  1194. height: 60rpx;
  1195. display: flex;
  1196. align-items: center;
  1197. justify-content: center;
  1198. }
  1199. .title {
  1200. flex: 1;
  1201. text-align: center;
  1202. font-size: 32rpx;
  1203. font-weight: bold;
  1204. }
  1205. .controls {
  1206. display: flex;
  1207. gap: 30rpx;
  1208. }
  1209. .iconfont {
  1210. font-size: 40rpx;
  1211. }
  1212. .content {
  1213. flex: 1;
  1214. display: flex;
  1215. flex-direction: column;
  1216. position: relative;
  1217. padding: 50rpx 20rpx 0;
  1218. }
  1219. .progress-container {
  1220. display: flex;
  1221. flex-direction: column;
  1222. justify-content: space-between;
  1223. margin-bottom: 20rpx;
  1224. }
  1225. .progress-step {
  1226. display: flex;
  1227. align-items: center;
  1228. margin-bottom: 10rpx;
  1229. }
  1230. .step-circle {
  1231. width: 40rpx;
  1232. height: 40rpx;
  1233. border-radius: 50%;
  1234. background-color: #e0e0e0;
  1235. display: flex;
  1236. align-items: center;
  1237. justify-content: center;
  1238. font-size: 24rpx;
  1239. margin-right: 10rpx;
  1240. }
  1241. .step-circle.active {
  1242. background-color: #ff9500;
  1243. color: #ffffff;
  1244. }
  1245. .step-text {
  1246. font-size: 24rpx;
  1247. color: #666666;
  1248. }
  1249. .progress-bar {
  1250. height: 10rpx;
  1251. background-color: #e0e0e0;
  1252. border-radius: 5rpx;
  1253. overflow: hidden;
  1254. margin-bottom: 20rpx;
  1255. }
  1256. .progress-fill {
  1257. height: 100%;
  1258. background-color: #00c853;
  1259. transition: width 0.3s;
  1260. }
  1261. .interview-content {
  1262. flex: 1;
  1263. display: flex;
  1264. flex-direction: column;
  1265. margin-bottom: 40rpx;
  1266. padding: 20rpx;
  1267. border-bottom: 1px solid #eee;
  1268. }
  1269. .video-area {
  1270. display: flex;
  1271. /* flex-direction: column; */
  1272. justify-content: space-between;
  1273. height: auto;
  1274. margin-bottom: 20rpx;
  1275. }
  1276. .video-camera {
  1277. display: flex;
  1278. flex-direction: row;
  1279. align-items: center;
  1280. justify-content: space-between;
  1281. width: 65%;
  1282. }
  1283. .interviewer {
  1284. background-color: #f5f5f5;
  1285. display: flex;
  1286. align-items: center;
  1287. justify-content: center;
  1288. position: relative;
  1289. width: 48% !important;
  1290. height: 300rpx;
  1291. }
  1292. .interviewer-video {
  1293. width: 100%;
  1294. height: 100%;
  1295. object-fit: cover;
  1296. }
  1297. .interviewer-avatar {
  1298. width: 80%;
  1299. height: 80%;
  1300. object-fit: contain;
  1301. }
  1302. .user-camera-container {
  1303. width: 48%;
  1304. height: 300rpx;
  1305. border-radius: 10rpx;
  1306. overflow: hidden;
  1307. border: 4rpx solid #ffffff;
  1308. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.2);
  1309. }
  1310. .question-area {
  1311. flex: 1;
  1312. display: flex;
  1313. flex-direction: column;
  1314. }
  1315. .question-number {
  1316. font-size: 28rpx;
  1317. color: #666;
  1318. margin-bottom: 20rpx;
  1319. }
  1320. .question-importance {
  1321. background-color: #f9f9f9;
  1322. padding: 20rpx;
  1323. border-radius: 10rpx;
  1324. margin-bottom: 20rpx;
  1325. font-size: 28rpx;
  1326. color: #333;
  1327. }
  1328. .question-importance text {
  1329. color: #ff0000;
  1330. /* margin-right: 10rpx; */
  1331. }
  1332. .options {
  1333. display: flex;
  1334. flex-direction: column;
  1335. gap: 20rpx;
  1336. margin-bottom: 30rpx;
  1337. }
  1338. .option-item {
  1339. padding: 20rpx;
  1340. background-color: #f5f5f5;
  1341. border-radius: 10rpx;
  1342. font-size: 28rpx;
  1343. transition: all 0.3s;
  1344. border: 1px solid #e0e0e0;
  1345. display: flex;
  1346. align-items: center;
  1347. cursor: pointer; /* 添加指针样式 */
  1348. }
  1349. .option-item:active {
  1350. transform: scale(0.98); /* 点击时轻微缩小效果 */
  1351. opacity: 0.9;
  1352. }
  1353. .option-selected {
  1354. background-color: #e6f7ff;
  1355. border: 1px solid #1890ff;
  1356. }
  1357. /* 添加选中后的动画效果 */
  1358. @keyframes selectedPulse {
  1359. 0% { box-shadow: 0 0 0 0 rgba(24, 144, 255, 0.4); }
  1360. 70% { box-shadow: 0 0 0 10px rgba(24, 144, 255, 0); }
  1361. 100% { box-shadow: 0 0 0 0 rgba(24, 144, 255, 0); }
  1362. }
  1363. .option-selected {
  1364. animation: selectedPulse 1.5s ease-out;
  1365. }
  1366. .option-correct {
  1367. background-color: #d4f7d4;
  1368. border: 1px solid #52c41a;
  1369. }
  1370. .option-wrong {
  1371. background-color: #fff1f0;
  1372. border: 1px solid #ff4d4f;
  1373. }
  1374. .option-text {
  1375. color: #333;
  1376. }
  1377. .timer-container {
  1378. text-align: right;
  1379. margin: 20rpx 0;
  1380. }
  1381. .timer-text {
  1382. font-size: 24rpx;
  1383. color: #666;
  1384. background-color: #f0f0f0;
  1385. padding: 6rpx 12rpx;
  1386. border-radius: 6rpx;
  1387. }
  1388. .bottom-button-container {
  1389. position: fixed;
  1390. bottom: 50px;
  1391. left: 5%;
  1392. right: 0;
  1393. padding: 20rpx;
  1394. display: flex;
  1395. justify-content: center;
  1396. z-index: 10;
  1397. }
  1398. .bottom-button-wrapper {
  1399. display: flex;
  1400. width: 100%;
  1401. justify-content: space-between;
  1402. align-items: center;
  1403. }
  1404. .timer-display {
  1405. font-size: 28rpx;
  1406. color: #666;
  1407. padding: 10rpx 20rpx;
  1408. border-radius: 6rpx;
  1409. }
  1410. .next-button {
  1411. background-color: #0039b3;
  1412. color: #ffffff;
  1413. border-radius: 10rpx;
  1414. font-size: 30rpx;
  1415. height: 80rpx;
  1416. line-height: 80rpx;
  1417. width: 90%;
  1418. text-align: center;
  1419. margin: 0;
  1420. }
  1421. .footer {
  1422. height: 100rpx;
  1423. background-color: #000000;
  1424. display: flex;
  1425. justify-content: space-between;
  1426. align-items: center;
  1427. padding: 0 30rpx;
  1428. color: #ffffff;
  1429. }
  1430. .timer {
  1431. font-size: 28rpx;
  1432. }
  1433. .next-step {
  1434. font-size: 28rpx;
  1435. }
  1436. .interview-end-modal {
  1437. position: fixed;
  1438. top: 0;
  1439. left: 0;
  1440. right: 0;
  1441. bottom: 0;
  1442. background-color: rgba(0, 0, 0, 0.5);
  1443. display: flex;
  1444. align-items: center;
  1445. justify-content: center;
  1446. z-index: 999;
  1447. }
  1448. .modal-content {
  1449. width: 80%;
  1450. background-color: #ffffff;
  1451. border-radius: 20rpx;
  1452. padding: 40rpx;
  1453. display: flex;
  1454. flex-direction: column;
  1455. align-items: center;
  1456. }
  1457. .modal-title {
  1458. font-size: 36rpx;
  1459. font-weight: bold;
  1460. margin-bottom: 30rpx;
  1461. }
  1462. .score-display {
  1463. font-size: 48rpx;
  1464. font-weight: bold;
  1465. color: #0039b3;
  1466. margin: 20rpx 0;
  1467. }
  1468. .modal-message {
  1469. font-size: 28rpx;
  1470. color: #666;
  1471. text-align: center;
  1472. margin-bottom: 40rpx;
  1473. }
  1474. .modal-buttons {
  1475. display: flex;
  1476. justify-content: space-between;
  1477. width: 100%;
  1478. margin-top: 20rpx;
  1479. }
  1480. .modal-button {
  1481. width: 45%;
  1482. }
  1483. @keyframes speaking {
  1484. 0% {
  1485. opacity: 0.8;
  1486. }
  1487. 50% {
  1488. opacity: 1;
  1489. }
  1490. 100% {
  1491. opacity: 0.8;
  1492. }
  1493. }
  1494. .speaking {
  1495. animation: speaking 1.5s infinite;
  1496. }
  1497. .digital-avatar {
  1498. display: flex;
  1499. flex-direction: row;
  1500. align-items: flex-start;
  1501. justify-content: space-between;
  1502. width: 100%;
  1503. margin-bottom: 20rpx;
  1504. }
  1505. .message-box {
  1506. width: 65%;
  1507. min-height: 120rpx;
  1508. background-color: #f5f5f5;
  1509. border-radius: 10rpx;
  1510. padding: 15rpx;
  1511. margin-right: 20rpx;
  1512. display: flex;
  1513. align-items: center;
  1514. }
  1515. .message-text {
  1516. font-size: 24rpx;
  1517. color: #333;
  1518. line-height: 1.5;
  1519. }
  1520. .user-avatar {
  1521. width: 110px;
  1522. height: 160px;
  1523. border-radius: 10rpx;
  1524. overflow: hidden;
  1525. }
  1526. .camera {
  1527. width: 100%;
  1528. height: 100%;
  1529. border-radius: 10rpx;
  1530. border: 2rpx solid #e0e0e0;
  1531. }
  1532. .avatar-image {
  1533. width: 100%;
  1534. height: 100%;
  1535. border-radius: 10rpx;
  1536. border: 2rpx solid #e0e0e0;
  1537. }
  1538. .digital-human-webview {
  1539. width: 100%;
  1540. height: 100%;
  1541. border-radius: 10rpx;
  1542. border: 2rpx solid #e0e0e0;
  1543. }
  1544. .interview-complete-screen {
  1545. position: fixed;
  1546. top: 0;
  1547. left: 0;
  1548. right: 0;
  1549. bottom: 0;
  1550. background-color: #f0f5ff;
  1551. display: flex;
  1552. flex-direction: column;
  1553. align-items: center;
  1554. justify-content: center;
  1555. z-index: 1000;
  1556. padding: 40rpx;
  1557. }
  1558. .digital-avatar-large {
  1559. width: 200rpx;
  1560. height: 200rpx;
  1561. margin-bottom: 60rpx;
  1562. }
  1563. .avatar-image-large {
  1564. width: 100%;
  1565. height: 100%;
  1566. border-radius: 30rpx;
  1567. }
  1568. .complete-message {
  1569. font-size: 40rpx;
  1570. font-weight: bold;
  1571. color: #333;
  1572. margin-bottom: 30rpx;
  1573. }
  1574. .complete-description {
  1575. font-size: 28rpx;
  1576. color: #666;
  1577. text-align: center;
  1578. margin-bottom: 80rpx;
  1579. line-height: 1.5;
  1580. }
  1581. .complete-button {
  1582. background-color: #0039b3;
  1583. color: #ffffff;
  1584. border-radius: 10rpx;
  1585. font-size: 32rpx;
  1586. padding: 20rpx 60rpx;
  1587. margin-top: 40rpx;
  1588. }
  1589. /* 添加加载状态样式 */
  1590. .loading-container {
  1591. position: absolute;
  1592. top: 0;
  1593. left: 0;
  1594. right: 0;
  1595. bottom: 0;
  1596. display: flex;
  1597. flex-direction: column;
  1598. align-items: center;
  1599. justify-content: center;
  1600. background-color: rgba(255, 255, 255, 0.9);
  1601. z-index: 100;
  1602. }
  1603. .loading-text {
  1604. margin-top: 20rpx;
  1605. font-size: 28rpx;
  1606. color: #666;
  1607. }
  1608. .error-container {
  1609. text-align: center;
  1610. }
  1611. .error-message {
  1612. font-size: 28rpx;
  1613. color: #ff4d4f;
  1614. margin-bottom: 30rpx;
  1615. }
  1616. .retry-button {
  1617. background-color: #0039b3;
  1618. color: #ffffff;
  1619. border-radius: 10rpx;
  1620. font-size: 28rpx;
  1621. padding: 10rpx 30rpx;
  1622. }
  1623. .question-type {
  1624. display: inline-block;
  1625. /* background-color: #0039b3; */
  1626. color: white;
  1627. font-size: 24rpx;
  1628. /* padding: 4rpx 5rpx; */
  1629. border-radius: 6rpx;
  1630. /* margin-right: 10rpx; */
  1631. }
  1632. /* 新增的开放问题样式 */
  1633. .open-question-container {
  1634. display: flex;
  1635. flex-direction: column;
  1636. width: 100%;
  1637. margin-bottom: 20rpx;
  1638. }
  1639. .open-question-input {
  1640. width: 100%;
  1641. height: 300rpx;
  1642. background-color: #f9f9f9;
  1643. border: 1px solid #e0e0e0;
  1644. border-radius: 10rpx;
  1645. padding: 20rpx;
  1646. font-size: 28rpx;
  1647. color: #333;
  1648. }
  1649. .word-count {
  1650. text-align: right;
  1651. font-size: 24rpx;
  1652. color: #999;
  1653. margin-top: 10rpx;
  1654. }
  1655. .option-prefix {
  1656. margin-right: 10rpx;
  1657. font-weight: bold;
  1658. color: #333;
  1659. min-width: 30rpx;
  1660. }
  1661. /* 新增的图片显示样式 */
  1662. .question-image-container {
  1663. width: 100%;
  1664. margin: 20rpx 0;
  1665. display: flex;
  1666. justify-content: center;
  1667. align-items: center;
  1668. }
  1669. .question-image {
  1670. width: 100%;
  1671. max-width: 600rpx;
  1672. border-radius: 10rpx;
  1673. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
  1674. }
  1675. /* 添加滚动视图样式 */
  1676. .content-scroll {
  1677. flex: 1;
  1678. height: calc(100vh - 200px); /* 只减去顶部相机的高度 */
  1679. margin-top: 10px;
  1680. }
  1681. /* 添加底部空白区域,防止内容被固定按钮遮挡 */
  1682. .bottom-space {
  1683. height: 50rpx; /* 减小底部空白区域 */
  1684. }
  1685. /* 添加流式布局相关样式 */
  1686. .interview-content {
  1687. margin-bottom: 40rpx;
  1688. padding: 20rpx;
  1689. border-bottom: 1px solid #eee;
  1690. }
  1691. .option-disabled {
  1692. opacity: 0.7;
  1693. background-color: #f0f0f0;
  1694. }
  1695. .question-button-container {
  1696. margin-top: 20rpx;
  1697. display: flex;
  1698. justify-content: center;
  1699. }
  1700. .bottom-timer-container {
  1701. display: none;
  1702. }
  1703. /* 添加固定相机容器样式 */
  1704. .fixed-camera-container {
  1705. position: sticky;
  1706. top: 0;
  1707. width: 100%;
  1708. padding: 20rpx;
  1709. background-color: #fff;
  1710. z-index: 10;
  1711. display: flex;
  1712. justify-content: flex-start;
  1713. border-bottom: 1px solid #eee;
  1714. }
  1715. .camera-warning {
  1716. animation: camera-warning-flash 1s ease-in-out infinite;
  1717. border: 2px solid #ff0000;
  1718. }
  1719. @keyframes camera-warning-flash {
  1720. 0% {
  1721. border-color: #ff0000;
  1722. box-shadow: 0 0 15px rgba(255, 0, 0, 0.8);
  1723. }
  1724. 50% {
  1725. border-color: rgba(255, 0, 0, 0.3);
  1726. box-shadow: 0 0 5px rgba(255, 0, 0, 0.4);
  1727. }
  1728. 100% {
  1729. border-color: #ff0000;
  1730. box-shadow: 0 0 15px rgba(255, 0, 0, 0.8);
  1731. }
  1732. }
  1733. .user-avatar {
  1734. width: 110px;
  1735. height: 160px;
  1736. border-radius: 10rpx;
  1737. overflow: hidden;
  1738. }
  1739. /* 添加继续按钮样式 */
  1740. .continue-button-container {
  1741. display: flex;
  1742. justify-content: center;
  1743. padding: 20rpx;
  1744. margin-top: 20rpx;
  1745. }
  1746. .continue-button {
  1747. background-color: #0039b3;
  1748. color: #ffffff;
  1749. border-radius: 10rpx;
  1750. font-size: 30rpx;
  1751. height: 80rpx;
  1752. line-height: 80rpx;
  1753. width: 90%;
  1754. text-align: center;
  1755. }
  1756. /* 添加新的样式 */
  1757. .prompt-modal {
  1758. position: fixed;
  1759. top: 0;
  1760. left: 0;
  1761. right: 0;
  1762. bottom: 0;
  1763. background-color: rgba(0, 0, 0, 0.5);
  1764. display: flex;
  1765. align-items: center;
  1766. justify-content: center;
  1767. z-index: 1000;
  1768. }
  1769. .prompt-content {
  1770. width: 85%;
  1771. background-color: #ffffff;
  1772. border-radius: 20rpx;
  1773. padding: 40rpx;
  1774. display: flex;
  1775. flex-direction: column;
  1776. align-items: center;
  1777. }
  1778. .prompt-title {
  1779. font-size: 36rpx;
  1780. font-weight: bold;
  1781. color: #333;
  1782. margin-bottom: 30rpx;
  1783. }
  1784. .prompt-text {
  1785. font-size: 28rpx;
  1786. color: #666;
  1787. line-height: 1.6;
  1788. margin-bottom: 20rpx;
  1789. text-align: justify;
  1790. }
  1791. .bold-text {
  1792. font-weight: bold;
  1793. color: #333;
  1794. }
  1795. .prompt-button {
  1796. background-color: #0039b3;
  1797. color: #ffffff;
  1798. border-radius: 10rpx;
  1799. font-size: 30rpx;
  1800. height: 80rpx;
  1801. line-height: 80rpx;
  1802. width: 60%;
  1803. text-align: center;
  1804. margin-top: 30rpx;
  1805. }
  1806. .custom-navbar {
  1807. position: fixed;
  1808. top: 0;
  1809. left: 0;
  1810. right: 0;
  1811. height: 44px;
  1812. background-color: #ffffff;
  1813. display: flex;
  1814. align-items: center;
  1815. justify-content: center;
  1816. z-index: 999;
  1817. }
  1818. .navbar-title {
  1819. font-size: 16px;
  1820. font-weight: bold;
  1821. }
  1822. .content {
  1823. margin-top: 44px;
  1824. padding-top: var(--status-bar-height);
  1825. }
  1826. </style>