camera.vue 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025
  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) 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'//'/pages/interview-question/interview-question'
  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'//'/pages/interview-question/interview-question'
  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) {
  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. this.selectOption(index);
  916. // 设置延时,防止快速重复点击
  917. this._clickTimer = setTimeout(() => {
  918. this._isClicking = false;
  919. }, 1000);
  920. } catch (error) {
  921. console.error('处理选项点击失败:', error);
  922. uni.showToast({
  923. title: '操作失败,请重试',
  924. icon: 'none'
  925. });
  926. this._isClicking = false;
  927. }
  928. },
  929. // 处理题目分组
  930. processQuestionGroups(questions) {
  931. // 创建两个分组
  932. const group1 = []; // category 为 5 的题目
  933. const group2 = []; // 其他题目
  934. // 对题目进行分类
  935. questions.forEach(q => {
  936. if (q.category === 5) {
  937. group1.push(q);
  938. } else {
  939. group2.push(q);
  940. }
  941. });
  942. // 按照要求的顺序组合题目组:先显示其他题目,再显示 category 为 5 的题目
  943. this.questionGroups = [group2, group1].filter(group => group.length > 0);
  944. // 设置当前显示的题目
  945. this.questions = this.questionGroups[0] || [];
  946. },
  947. // 处理继续按钮点击
  948. handleContinue() {
  949. if (this.currentGroupIndex < this.questionGroups.length - 1) {
  950. // 检查是否是第一组结束
  951. if (this.currentGroupIndex === 0) {
  952. this.showPromptModal = true; // 显示提示弹窗
  953. } else {
  954. this.proceedToNextGroup();
  955. }
  956. } else {
  957. // 所有组都完成了,跳转到下一个页面
  958. uni.navigateTo({
  959. url: '/pages/posture-guide/posture-guide'//'/pages/interview-question/interview-question'
  960. });
  961. }
  962. },
  963. // 添加新的方法处理弹窗确认
  964. handlePromptConfirm() {
  965. this.showPromptModal = false;
  966. this.proceedToNextGroup();
  967. },
  968. // 添加新的方法处理组切换逻辑
  969. proceedToNextGroup() {
  970. this.currentGroupIndex++;
  971. this.questions = this.questionGroups[this.currentGroupIndex];
  972. this.currentQuestionIndex = 0;
  973. this.showContinueButton = false;
  974. this.currentScrollId = 'question-0';
  975. // 重置滚动位置
  976. this.scrollTop = 0;
  977. // 重置相关状态
  978. this.selectedOption = null;
  979. this.selectedOptions = [];
  980. this.showResult = false;
  981. },
  982. // 保存当前题目的答案
  983. saveAnswer() {
  984. let answer;
  985. if (this.currentQuestion.questionType === 0) { // 开放问题
  986. answer = {
  987. questionId: this.currentQuestion.id,
  988. questionType: this.currentQuestion.questionType,
  989. answer: this.openQuestionAnswer,
  990. answerDuration: this.getAnswerDuration() // 添加答题时长
  991. };
  992. } else if (this.currentQuestion.questionType === 1 || this.currentQuestion.questionType === 3 || this.currentQuestion.questionType === 4) { // 单选题、看图答题或类型4题目
  993. answer = {
  994. questionId: this.currentQuestion.id,
  995. questionType: this.currentQuestion.questionType,
  996. answer: this.selectedOption,
  997. answerDuration: this.getAnswerDuration() // 添加答题时长
  998. };
  999. } else { // 多选题
  1000. answer = {
  1001. questionId: this.currentQuestion.id,
  1002. questionType: this.currentQuestion.questionType,
  1003. answer: this.selectedOptions,
  1004. answerDuration: this.getAnswerDuration() // 添加答题时长
  1005. };
  1006. }
  1007. // 检查是否已存在该题目的答案,如果存在则更新
  1008. const existingIndex = this.answers.findIndex(a => a.questionId === answer.questionId);
  1009. if (existingIndex > -1) {
  1010. this.answers[existingIndex] = answer;
  1011. } else {
  1012. this.answers.push(answer);
  1013. }
  1014. // 保存当前答案以便提交
  1015. this.currentAnswer = answer;
  1016. console.log('已保存答案:', this.answers);
  1017. },
  1018. // 获取答题时长(秒)
  1019. getAnswerDuration() {
  1020. // 这里假设每题默认30秒,根据剩余时间计算用时
  1021. // 您可以根据实际情况调整计算逻辑
  1022. const remainingTimeArr = this.remainingTime.split(':');
  1023. const remainingSeconds = parseInt(remainingTimeArr[0]) * 60 + parseInt(remainingTimeArr[1]);
  1024. return 30 - remainingSeconds; // 假设每题30秒
  1025. },
  1026. // 提交当前答案
  1027. async submitCurrentAnswer() {
  1028. if (!this.currentAnswer || this.isSubmitting) return; // 如果正在提交或没有答案,则不执行
  1029. try {
  1030. // 设置提交状态为true
  1031. this.isSubmitting = true;
  1032. // 显示提交中提示
  1033. uni.showLoading({
  1034. title: '正在提交答案...'
  1035. });
  1036. // 构建提交数据
  1037. let answerContent = '';
  1038. let answerOptions = [];
  1039. if (this.currentAnswer.questionType === 0) {
  1040. // 开放题直接使用文本答案
  1041. answerContent = this.currentAnswer.answer;
  1042. answerOptions = [];
  1043. } else if (this.currentAnswer.questionType === 1 || this.currentAnswer.questionType === 3 || this.currentAnswer.questionType === 4) {
  1044. // 单选题或看图答题,获取选项ID而不是索引
  1045. const selectedIndex = this.currentAnswer.answer;
  1046. const selectedOption = this.currentQuestion.options[selectedIndex];
  1047. console.log('selectedOption',selectedOption);
  1048. const optionId = selectedOption.id ? selectedOption.id : selectedIndex;
  1049. answerContent = optionId.toString();
  1050. answerOptions = [optionId];
  1051. } else if (this.currentAnswer.questionType === 2) {
  1052. // 多选题,将选项ID数组转为逗号分隔的字符串
  1053. const selectedIndices = this.currentAnswer.answer;
  1054. const selectedOptionIds = selectedIndices.map(index => {
  1055. const option = this.currentQuestion.options[index];
  1056. // 使用选项的ID或其他唯一标识符
  1057. return option.id ? option.id : index;
  1058. });
  1059. answerOptions = selectedOptionIds;
  1060. }
  1061. const submitData = {
  1062. position_id: JSON.parse(uni.getStorageSync('selectedJob')).id,
  1063. applicant_id: JSON.parse(uni.getStorageSync('userInfo')).id,
  1064. job_position_question_id: this.currentAnswer.questionId,
  1065. // answer_content: answerContent,
  1066. answer_options: answerOptions,
  1067. answer_duration: this.currentAnswer.answerDuration || 0,
  1068. tenant_id:JSON.parse(uni.getStorageSync('userInfo')).tenant_id || 1
  1069. };
  1070. console.log('提交数据:', submitData);
  1071. // 调用API提交答案
  1072. const res = await this.$http.post(`${apiBaseUrl}/api/job/submit_answer`, submitData);
  1073. console.log('提交答案响应:', res);
  1074. return res;
  1075. } catch (error) {
  1076. console.error('提交答案失败:', error);
  1077. // 显示错误提示
  1078. uni.showToast({
  1079. title: '提交答案失败,请重试',
  1080. icon: 'none'
  1081. });
  1082. throw error;
  1083. } finally {
  1084. // 隐藏加载提示
  1085. uni.hideLoading();
  1086. // 重置提交状态
  1087. this.isSubmitting = false;
  1088. }
  1089. },
  1090. // 修改 goToNextQuestion 方法
  1091. async goToNextQuestion() {
  1092. // 检查是否完成当前组的所有题目
  1093. if (this.currentQuestionIndex >= this.questions.length - 1) {
  1094. // 当前组的所有题目都已完成,显示继续按钮
  1095. this.showContinueButton = true;
  1096. // 使用延时确保按钮渲染完成后再滚动
  1097. setTimeout(() => {
  1098. // 先重置 scrollTop,然后再设置新值,强制触发更新
  1099. this.scrollTop = 0;
  1100. // 使用 nextTick 确保视图已更新
  1101. this.$nextTick(() => {
  1102. // 延迟设置新的滚动位置
  1103. setTimeout(() => {
  1104. this.scrollTop = 10000; // 一个足够大的值
  1105. }, 100);
  1106. });
  1107. }, 200);
  1108. return;
  1109. }
  1110. // 如果还有下一题,继续下一题
  1111. this.currentQuestionIndex++;
  1112. this.currentScrollId = 'question-' + this.currentQuestionIndex;
  1113. // 重置状态(只在非最后一题时重置)
  1114. this.showResult = false;
  1115. this.selectedOption = null;
  1116. this.selectedOptions = [];
  1117. this.openQuestionAnswer = '';
  1118. // 如果有下一题的详情
  1119. if (this.questions[this.currentQuestionIndex]) {
  1120. // 更新进度
  1121. this.progressWidth = (this.currentQuestionIndex + 1) / this.questions.length * 100;
  1122. // 重置计时器
  1123. this.resetTimer();
  1124. // 播放AI介绍下一题
  1125. this.playAiSpeaking();
  1126. setTimeout(() => {
  1127. this.pauseAiSpeaking();
  1128. }, 2000);
  1129. }
  1130. },
  1131. },
  1132. // 添加生命周期钩子,确保在组件销毁时清除计时器
  1133. beforeDestroy() {
  1134. if (this.timerInterval) {
  1135. clearInterval(this.timerInterval);
  1136. }
  1137. }
  1138. }
  1139. </script>
  1140. <style>
  1141. .camera-container {
  1142. position: relative;
  1143. margin-top: 25px;
  1144. width: 100%;
  1145. height: 96vh;
  1146. background-color: #ffffff;
  1147. display: flex;
  1148. flex-direction: column;
  1149. overflow: hidden; /* 防止内容溢出 */
  1150. }
  1151. .header {
  1152. height: 90rpx;
  1153. /* background-color: #000000; */
  1154. display: flex;
  1155. align-items: center;
  1156. padding: 0 30rpx;
  1157. /* color: #ffffff; */
  1158. }
  1159. .back-button {
  1160. width: 60rpx;
  1161. height: 60rpx;
  1162. display: flex;
  1163. align-items: center;
  1164. justify-content: center;
  1165. }
  1166. .title {
  1167. flex: 1;
  1168. text-align: center;
  1169. font-size: 32rpx;
  1170. font-weight: bold;
  1171. }
  1172. .controls {
  1173. display: flex;
  1174. gap: 30rpx;
  1175. }
  1176. .iconfont {
  1177. font-size: 40rpx;
  1178. }
  1179. .content {
  1180. flex: 1;
  1181. display: flex;
  1182. flex-direction: column;
  1183. position: relative;
  1184. padding: 50rpx 20rpx 0;
  1185. }
  1186. .progress-container {
  1187. display: flex;
  1188. flex-direction: column;
  1189. justify-content: space-between;
  1190. margin-bottom: 20rpx;
  1191. }
  1192. .progress-step {
  1193. display: flex;
  1194. align-items: center;
  1195. margin-bottom: 10rpx;
  1196. }
  1197. .step-circle {
  1198. width: 40rpx;
  1199. height: 40rpx;
  1200. border-radius: 50%;
  1201. background-color: #e0e0e0;
  1202. display: flex;
  1203. align-items: center;
  1204. justify-content: center;
  1205. font-size: 24rpx;
  1206. margin-right: 10rpx;
  1207. }
  1208. .step-circle.active {
  1209. background-color: #ff9500;
  1210. color: #ffffff;
  1211. }
  1212. .step-text {
  1213. font-size: 24rpx;
  1214. color: #666666;
  1215. }
  1216. .progress-bar {
  1217. height: 10rpx;
  1218. background-color: #e0e0e0;
  1219. border-radius: 5rpx;
  1220. overflow: hidden;
  1221. margin-bottom: 20rpx;
  1222. }
  1223. .progress-fill {
  1224. height: 100%;
  1225. background-color: #00c853;
  1226. transition: width 0.3s;
  1227. }
  1228. .interview-content {
  1229. flex: 1;
  1230. display: flex;
  1231. flex-direction: column;
  1232. margin-bottom: 40rpx;
  1233. padding: 20rpx;
  1234. border-bottom: 1px solid #eee;
  1235. }
  1236. .video-area {
  1237. display: flex;
  1238. /* flex-direction: column; */
  1239. justify-content: space-between;
  1240. height: auto;
  1241. margin-bottom: 20rpx;
  1242. }
  1243. .video-camera {
  1244. display: flex;
  1245. flex-direction: row;
  1246. align-items: center;
  1247. justify-content: space-between;
  1248. width: 65%;
  1249. }
  1250. .interviewer {
  1251. background-color: #f5f5f5;
  1252. display: flex;
  1253. align-items: center;
  1254. justify-content: center;
  1255. position: relative;
  1256. width: 48% !important;
  1257. height: 300rpx;
  1258. }
  1259. .interviewer-video {
  1260. width: 100%;
  1261. height: 100%;
  1262. object-fit: cover;
  1263. }
  1264. .interviewer-avatar {
  1265. width: 80%;
  1266. height: 80%;
  1267. object-fit: contain;
  1268. }
  1269. .user-camera-container {
  1270. width: 48%;
  1271. height: 300rpx;
  1272. border-radius: 10rpx;
  1273. overflow: hidden;
  1274. border: 4rpx solid #ffffff;
  1275. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.2);
  1276. }
  1277. .question-area {
  1278. flex: 1;
  1279. display: flex;
  1280. flex-direction: column;
  1281. }
  1282. .question-number {
  1283. font-size: 28rpx;
  1284. color: #666;
  1285. margin-bottom: 20rpx;
  1286. }
  1287. .question-importance {
  1288. background-color: #f9f9f9;
  1289. padding: 20rpx;
  1290. border-radius: 10rpx;
  1291. margin-bottom: 20rpx;
  1292. font-size: 28rpx;
  1293. color: #333;
  1294. }
  1295. .question-importance text {
  1296. color: #ff0000;
  1297. /* margin-right: 10rpx; */
  1298. }
  1299. .options {
  1300. display: flex;
  1301. flex-direction: column;
  1302. gap: 20rpx;
  1303. margin-bottom: 30rpx;
  1304. }
  1305. .option-item {
  1306. padding: 20rpx;
  1307. background-color: #f5f5f5;
  1308. border-radius: 10rpx;
  1309. font-size: 28rpx;
  1310. transition: all 0.3s;
  1311. border: 1px solid #e0e0e0;
  1312. display: flex;
  1313. align-items: center;
  1314. cursor: pointer; /* 添加指针样式 */
  1315. }
  1316. .option-item:active {
  1317. transform: scale(0.98); /* 点击时轻微缩小效果 */
  1318. opacity: 0.9;
  1319. }
  1320. .option-selected {
  1321. background-color: #e6f7ff;
  1322. border: 1px solid #1890ff;
  1323. }
  1324. /* 添加选中后的动画效果 */
  1325. @keyframes selectedPulse {
  1326. 0% { box-shadow: 0 0 0 0 rgba(24, 144, 255, 0.4); }
  1327. 70% { box-shadow: 0 0 0 10px rgba(24, 144, 255, 0); }
  1328. 100% { box-shadow: 0 0 0 0 rgba(24, 144, 255, 0); }
  1329. }
  1330. .option-selected {
  1331. animation: selectedPulse 1.5s ease-out;
  1332. }
  1333. .option-correct {
  1334. background-color: #d4f7d4;
  1335. border: 1px solid #52c41a;
  1336. }
  1337. .option-wrong {
  1338. background-color: #fff1f0;
  1339. border: 1px solid #ff4d4f;
  1340. }
  1341. .option-text {
  1342. color: #333;
  1343. }
  1344. .timer-container {
  1345. text-align: right;
  1346. margin: 20rpx 0;
  1347. }
  1348. .timer-text {
  1349. font-size: 24rpx;
  1350. color: #666;
  1351. background-color: #f0f0f0;
  1352. padding: 6rpx 12rpx;
  1353. border-radius: 6rpx;
  1354. }
  1355. .bottom-button-container {
  1356. position: fixed;
  1357. bottom: 50px;
  1358. left: 5%;
  1359. right: 0;
  1360. padding: 20rpx;
  1361. display: flex;
  1362. justify-content: center;
  1363. z-index: 10;
  1364. }
  1365. .bottom-button-wrapper {
  1366. display: flex;
  1367. width: 100%;
  1368. justify-content: space-between;
  1369. align-items: center;
  1370. }
  1371. .timer-display {
  1372. font-size: 28rpx;
  1373. color: #666;
  1374. padding: 10rpx 20rpx;
  1375. border-radius: 6rpx;
  1376. }
  1377. .next-button {
  1378. background-color: #0039b3;
  1379. color: #ffffff;
  1380. border-radius: 10rpx;
  1381. font-size: 30rpx;
  1382. height: 80rpx;
  1383. line-height: 80rpx;
  1384. width: 90%;
  1385. text-align: center;
  1386. margin: 0;
  1387. }
  1388. .footer {
  1389. height: 100rpx;
  1390. background-color: #000000;
  1391. display: flex;
  1392. justify-content: space-between;
  1393. align-items: center;
  1394. padding: 0 30rpx;
  1395. color: #ffffff;
  1396. }
  1397. .timer {
  1398. font-size: 28rpx;
  1399. }
  1400. .next-step {
  1401. font-size: 28rpx;
  1402. }
  1403. .interview-end-modal {
  1404. position: fixed;
  1405. top: 0;
  1406. left: 0;
  1407. right: 0;
  1408. bottom: 0;
  1409. background-color: rgba(0, 0, 0, 0.5);
  1410. display: flex;
  1411. align-items: center;
  1412. justify-content: center;
  1413. z-index: 999;
  1414. }
  1415. .modal-content {
  1416. width: 80%;
  1417. background-color: #ffffff;
  1418. border-radius: 20rpx;
  1419. padding: 40rpx;
  1420. display: flex;
  1421. flex-direction: column;
  1422. align-items: center;
  1423. }
  1424. .modal-title {
  1425. font-size: 36rpx;
  1426. font-weight: bold;
  1427. margin-bottom: 30rpx;
  1428. }
  1429. .score-display {
  1430. font-size: 48rpx;
  1431. font-weight: bold;
  1432. color: #0039b3;
  1433. margin: 20rpx 0;
  1434. }
  1435. .modal-message {
  1436. font-size: 28rpx;
  1437. color: #666;
  1438. text-align: center;
  1439. margin-bottom: 40rpx;
  1440. }
  1441. .modal-buttons {
  1442. display: flex;
  1443. justify-content: space-between;
  1444. width: 100%;
  1445. margin-top: 20rpx;
  1446. }
  1447. .modal-button {
  1448. width: 45%;
  1449. }
  1450. @keyframes speaking {
  1451. 0% {
  1452. opacity: 0.8;
  1453. }
  1454. 50% {
  1455. opacity: 1;
  1456. }
  1457. 100% {
  1458. opacity: 0.8;
  1459. }
  1460. }
  1461. .speaking {
  1462. animation: speaking 1.5s infinite;
  1463. }
  1464. .digital-avatar {
  1465. display: flex;
  1466. flex-direction: row;
  1467. align-items: flex-start;
  1468. justify-content: space-between;
  1469. width: 100%;
  1470. margin-bottom: 20rpx;
  1471. }
  1472. .message-box {
  1473. width: 65%;
  1474. min-height: 120rpx;
  1475. background-color: #f5f5f5;
  1476. border-radius: 10rpx;
  1477. padding: 15rpx;
  1478. margin-right: 20rpx;
  1479. display: flex;
  1480. align-items: center;
  1481. }
  1482. .message-text {
  1483. font-size: 24rpx;
  1484. color: #333;
  1485. line-height: 1.5;
  1486. }
  1487. .user-avatar {
  1488. width: 110px;
  1489. height: 160px;
  1490. border-radius: 10rpx;
  1491. overflow: hidden;
  1492. }
  1493. .camera {
  1494. width: 100%;
  1495. height: 100%;
  1496. border-radius: 10rpx;
  1497. border: 2rpx solid #e0e0e0;
  1498. }
  1499. .avatar-image {
  1500. width: 100%;
  1501. height: 100%;
  1502. border-radius: 10rpx;
  1503. border: 2rpx solid #e0e0e0;
  1504. }
  1505. .digital-human-webview {
  1506. width: 100%;
  1507. height: 100%;
  1508. border-radius: 10rpx;
  1509. border: 2rpx solid #e0e0e0;
  1510. }
  1511. .interview-complete-screen {
  1512. position: fixed;
  1513. top: 0;
  1514. left: 0;
  1515. right: 0;
  1516. bottom: 0;
  1517. background-color: #f0f5ff;
  1518. display: flex;
  1519. flex-direction: column;
  1520. align-items: center;
  1521. justify-content: center;
  1522. z-index: 1000;
  1523. padding: 40rpx;
  1524. }
  1525. .digital-avatar-large {
  1526. width: 200rpx;
  1527. height: 200rpx;
  1528. margin-bottom: 60rpx;
  1529. }
  1530. .avatar-image-large {
  1531. width: 100%;
  1532. height: 100%;
  1533. border-radius: 30rpx;
  1534. }
  1535. .complete-message {
  1536. font-size: 40rpx;
  1537. font-weight: bold;
  1538. color: #333;
  1539. margin-bottom: 30rpx;
  1540. }
  1541. .complete-description {
  1542. font-size: 28rpx;
  1543. color: #666;
  1544. text-align: center;
  1545. margin-bottom: 80rpx;
  1546. line-height: 1.5;
  1547. }
  1548. .complete-button {
  1549. background-color: #0039b3;
  1550. color: #ffffff;
  1551. border-radius: 10rpx;
  1552. font-size: 32rpx;
  1553. padding: 20rpx 60rpx;
  1554. margin-top: 40rpx;
  1555. }
  1556. /* 添加加载状态样式 */
  1557. .loading-container {
  1558. position: absolute;
  1559. top: 0;
  1560. left: 0;
  1561. right: 0;
  1562. bottom: 0;
  1563. display: flex;
  1564. flex-direction: column;
  1565. align-items: center;
  1566. justify-content: center;
  1567. background-color: rgba(255, 255, 255, 0.9);
  1568. z-index: 100;
  1569. }
  1570. .loading-text {
  1571. margin-top: 20rpx;
  1572. font-size: 28rpx;
  1573. color: #666;
  1574. }
  1575. .error-container {
  1576. text-align: center;
  1577. }
  1578. .error-message {
  1579. font-size: 28rpx;
  1580. color: #ff4d4f;
  1581. margin-bottom: 30rpx;
  1582. }
  1583. .retry-button {
  1584. background-color: #0039b3;
  1585. color: #ffffff;
  1586. border-radius: 10rpx;
  1587. font-size: 28rpx;
  1588. padding: 10rpx 30rpx;
  1589. }
  1590. .question-type {
  1591. display: inline-block;
  1592. /* background-color: #0039b3; */
  1593. color: white;
  1594. font-size: 24rpx;
  1595. /* padding: 4rpx 5rpx; */
  1596. border-radius: 6rpx;
  1597. /* margin-right: 10rpx; */
  1598. }
  1599. /* 新增的开放问题样式 */
  1600. .open-question-container {
  1601. display: flex;
  1602. flex-direction: column;
  1603. width: 100%;
  1604. margin-bottom: 20rpx;
  1605. }
  1606. .open-question-input {
  1607. width: 100%;
  1608. height: 300rpx;
  1609. background-color: #f9f9f9;
  1610. border: 1px solid #e0e0e0;
  1611. border-radius: 10rpx;
  1612. padding: 20rpx;
  1613. font-size: 28rpx;
  1614. color: #333;
  1615. }
  1616. .word-count {
  1617. text-align: right;
  1618. font-size: 24rpx;
  1619. color: #999;
  1620. margin-top: 10rpx;
  1621. }
  1622. .option-prefix {
  1623. margin-right: 10rpx;
  1624. font-weight: bold;
  1625. color: #333;
  1626. min-width: 30rpx;
  1627. }
  1628. /* 新增的图片显示样式 */
  1629. .question-image-container {
  1630. width: 100%;
  1631. margin: 20rpx 0;
  1632. display: flex;
  1633. justify-content: center;
  1634. align-items: center;
  1635. }
  1636. .question-image {
  1637. width: 100%;
  1638. max-width: 600rpx;
  1639. border-radius: 10rpx;
  1640. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
  1641. }
  1642. /* 添加滚动视图样式 */
  1643. .content-scroll {
  1644. flex: 1;
  1645. height: calc(100vh - 200px); /* 只减去顶部相机的高度 */
  1646. margin-top: 10px;
  1647. }
  1648. /* 添加底部空白区域,防止内容被固定按钮遮挡 */
  1649. .bottom-space {
  1650. height: 50rpx; /* 减小底部空白区域 */
  1651. }
  1652. /* 添加流式布局相关样式 */
  1653. .interview-content {
  1654. margin-bottom: 40rpx;
  1655. padding: 20rpx;
  1656. border-bottom: 1px solid #eee;
  1657. }
  1658. .option-disabled {
  1659. opacity: 0.7;
  1660. background-color: #f0f0f0;
  1661. }
  1662. .question-button-container {
  1663. margin-top: 20rpx;
  1664. display: flex;
  1665. justify-content: center;
  1666. }
  1667. .bottom-timer-container {
  1668. display: none;
  1669. }
  1670. /* 添加固定相机容器样式 */
  1671. .fixed-camera-container {
  1672. position: sticky;
  1673. top: 0;
  1674. width: 100%;
  1675. padding: 20rpx;
  1676. background-color: #fff;
  1677. z-index: 10;
  1678. display: flex;
  1679. justify-content: flex-start;
  1680. border-bottom: 1px solid #eee;
  1681. }
  1682. .camera-warning {
  1683. animation: camera-warning-flash 1s ease-in-out infinite;
  1684. border: 2px solid #ff0000;
  1685. }
  1686. @keyframes camera-warning-flash {
  1687. 0% {
  1688. border-color: #ff0000;
  1689. box-shadow: 0 0 15px rgba(255, 0, 0, 0.8);
  1690. }
  1691. 50% {
  1692. border-color: rgba(255, 0, 0, 0.3);
  1693. box-shadow: 0 0 5px rgba(255, 0, 0, 0.4);
  1694. }
  1695. 100% {
  1696. border-color: #ff0000;
  1697. box-shadow: 0 0 15px rgba(255, 0, 0, 0.8);
  1698. }
  1699. }
  1700. .user-avatar {
  1701. width: 110px;
  1702. height: 160px;
  1703. border-radius: 10rpx;
  1704. overflow: hidden;
  1705. }
  1706. /* 添加继续按钮样式 */
  1707. .continue-button-container {
  1708. display: flex;
  1709. justify-content: center;
  1710. padding: 20rpx;
  1711. margin-top: 20rpx;
  1712. }
  1713. .continue-button {
  1714. background-color: #0039b3;
  1715. color: #ffffff;
  1716. border-radius: 10rpx;
  1717. font-size: 30rpx;
  1718. height: 80rpx;
  1719. line-height: 80rpx;
  1720. width: 90%;
  1721. text-align: center;
  1722. }
  1723. /* 添加新的样式 */
  1724. .prompt-modal {
  1725. position: fixed;
  1726. top: 0;
  1727. left: 0;
  1728. right: 0;
  1729. bottom: 0;
  1730. background-color: rgba(0, 0, 0, 0.5);
  1731. display: flex;
  1732. align-items: center;
  1733. justify-content: center;
  1734. z-index: 1000;
  1735. }
  1736. .prompt-content {
  1737. width: 85%;
  1738. background-color: #ffffff;
  1739. border-radius: 20rpx;
  1740. padding: 40rpx;
  1741. display: flex;
  1742. flex-direction: column;
  1743. align-items: center;
  1744. }
  1745. .prompt-title {
  1746. font-size: 36rpx;
  1747. font-weight: bold;
  1748. color: #333;
  1749. margin-bottom: 30rpx;
  1750. }
  1751. .prompt-text {
  1752. font-size: 28rpx;
  1753. color: #666;
  1754. line-height: 1.6;
  1755. margin-bottom: 20rpx;
  1756. text-align: justify;
  1757. }
  1758. .bold-text {
  1759. font-weight: bold;
  1760. color: #333;
  1761. }
  1762. .prompt-button {
  1763. background-color: #0039b3;
  1764. color: #ffffff;
  1765. border-radius: 10rpx;
  1766. font-size: 30rpx;
  1767. height: 80rpx;
  1768. line-height: 80rpx;
  1769. width: 60%;
  1770. text-align: center;
  1771. margin-top: 30rpx;
  1772. }
  1773. .custom-navbar {
  1774. position: fixed;
  1775. top: 0;
  1776. left: 0;
  1777. right: 0;
  1778. height: 44px;
  1779. background-color: #ffffff;
  1780. display: flex;
  1781. align-items: center;
  1782. justify-content: center;
  1783. z-index: 999;
  1784. }
  1785. .navbar-title {
  1786. font-size: 16px;
  1787. font-weight: bold;
  1788. }
  1789. .content {
  1790. margin-top: 44px;
  1791. padding-top: var(--status-bar-height);
  1792. }
  1793. </style>