identity-verify.vue 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843
  1. <template>
  2. <div class="identity-verify-container">
  3. <div class="digital-human-container">
  4. <!-- AI数字人视频/图像显示区域 -->
  5. <div class="digital-human-video">
  6. <!-- <image v-if="!videoPlaying" src="/static/images/digital-human-placeholder.jpg" mode="aspectFit"></image> -->
  7. <video
  8. :src="videoUrl"
  9. id="myVideo"
  10. ref="videoPlayer"
  11. autoplay
  12. playsinline
  13. disablePictureInPicture
  14. controlsList="nodownload nofullscreen noremoteplayback"
  15. class="video-player"
  16. :controls="false"
  17. @error="handleVideoError"
  18. @ended="handleVideoEnded"
  19. @timeupdate="handleTimeUpdate">
  20. </video>
  21. <!-- 添加字幕覆盖层 -->
  22. <div class="subtitle-overlay" v-if="currentSubtitle">
  23. {{ currentSubtitle }}
  24. </div>
  25. <!-- 添加答题按钮 -->
  26. <div class="answer-button-container" v-if="showAnswerButton">
  27. <button class="answer-button" @click="handleAnswerButtonClick">
  28. 开始面试
  29. </button>
  30. </div>
  31. </div>
  32. <!-- 用户摄像头视频显示区域 -->
  33. <div class="user-camera-container">
  34. <!-- 在小程序环境中使用camera组件 -->
  35. <camera v-if="useMiniProgramCameraComponent"
  36. device-position="front"
  37. flash="off"
  38. class="user-camera-video"
  39. @error="handleCameraError"
  40. :record-audio="true"
  41. frame-size="small"
  42. resolution="low"
  43. :disable-zoom="true"
  44. :enable-camera="true"
  45. :enable-record="true"
  46. mode="normal">
  47. </camera>
  48. <!-- 在H5/App环境中使用video元素 -->
  49. <video v-else
  50. id="userCamera"
  51. ref="userCameraVideo"
  52. autoplay
  53. playsinline
  54. muted
  55. class="user-camera-video"
  56. :controls="false">
  57. </video>
  58. </div>
  59. <!-- 字幕/文本覆盖区域 -->
  60. <!-- <div class="subtitle-overlay" v-if="assistantResponse">
  61. {{ assistantResponse }}
  62. </div> -->
  63. </div>
  64. <!-- 加载状态 -->
  65. <div v-if="loading" class="loading">加载中...</div>
  66. <!-- 控制面板(可选,可以隐藏) -->
  67. <!-- 响应数据(可以设为隐藏,仅用于调试) -->
  68. <div v-if="showDebugInfo" class="response-container">
  69. <div v-if="assistantResponse" class="response-item">
  70. <div class="response-content">
  71. <span>助手回复: {{ assistantResponse }}</span>
  72. </div>
  73. </div>
  74. <div v-if="audioTranscript" class="response-item">
  75. <div class="response-content">
  76. <span>音频转写: {{ audioTranscript }}</span>
  77. </div>
  78. </div>
  79. <div v-for="(item, index) in processedResponses" :key="index" class="response-item">
  80. <div class="response-content">
  81. <span v-if="item.role">角色: {{ item.role }}</span>
  82. <span v-if="item.transcript">文本: {{ item.transcript }}</span>
  83. </div>
  84. </div>
  85. </div>
  86. <!-- 添加停止录制按钮 -->
  87. <div class="stop-recording-button-container" v-if="showStopRecordingButton">
  88. <button class="stop-recording-button" @click="stopRecordingAnswer">
  89. 完成作答
  90. </button>
  91. </div>
  92. <!-- 添加录制指示器 -->
  93. <div class="recording-indicator" v-if="isRecording">
  94. <div class="recording-dot"></div>
  95. <span class="recording-text">正在录制...</span>
  96. </div>
  97. <!-- 添加开始回答按钮 -->
  98. <div class="start-recording-button-container" v-if="showStartRecordingButton">
  99. <button class="start-recording-button" @click="handleStartRecordingClick">
  100. 开始作答
  101. </button>
  102. </div>
  103. <!-- 添加重试上传按钮 -->
  104. <div class="retry-button-container" v-if="showRetryButton">
  105. <button class="retry-button" @click="retryVideoUpload">
  106. 重新上传
  107. </button>
  108. </div>
  109. <!-- 在模板部分添加录制时长显示 -->
  110. <!-- <div class="recording-timer" v-if="isRecording">
  111. <span class="timer-text">{{ recordingTimeDisplay || '00:00' }}</span>
  112. </div> -->
  113. <!-- 添加上传状态指示器 -->
  114. <div class="upload-status-indicator" v-if="showUploadStatus && uploadStatusText">
  115. <div class="upload-status-content">
  116. <div class="upload-status-icon" :class="{'uploading': isUploading}"></div>
  117. <span class="upload-status-text">{{ uploadStatusText }}</span>
  118. </div>
  119. </div>
  120. <!-- 修改录制时长显示 -->
  121. <div class="recording-timer" v-if="isRecording">
  122. <span class="timer-text">{{ recordingTimeDisplay || '00:00 / 05:00' }}</span>
  123. <!-- <span class="remaining-time" :class="{'warning': remainingTime <= 10}">
  124. 剩余: {{ formatTime(remainingTime) }}
  125. </span> -->
  126. </div>
  127. </div>
  128. </template>
  129. <script>
  130. import { apiBaseUrl } from '@/common/config.js';
  131. export default {
  132. name: 'IdentityVerify',
  133. data() {
  134. return {
  135. loading: false,
  136. responses: [],
  137. processedResponses: [],
  138. assistantResponse: '',
  139. audioTranscript: '',
  140. videoPlaying: false,
  141. showDebugInfo: false, // 设置为true可以显示调试信息
  142. videoUrl: 'http://121.36.251.245:9000/minlong/9c139c99-a613-49f2-986b-8a3ac20a9b1b.mp4', // 用于存储AI数字人视频URL
  143. showReplayButton: false,
  144. cameraStream: null, // 存储摄像头流
  145. cameraError: null, // 存储摄像头错误信息
  146. useMiniProgramCameraComponent: false, // 添加小程序相机组件标志
  147. cameraContext: null, // 添加相机上下文
  148. currentSubtitle: '',
  149. subtitles: [
  150. {
  151. startTime: 0, // 开始时间(秒)
  152. endTime: 5, // 结束时间(秒)
  153. text: '你好,我是本次面试的面试官,欢迎参加本公司的线上面试!'
  154. },
  155. {
  156. startTime: 5,
  157. endTime: 13,
  158. text: '面试预计需要15分钟,请你提前安排在网络良好、光线亮度合适、且相对安静的环境参加这次面试'
  159. },
  160. {
  161. startTime: 13,
  162. endTime: 20,
  163. text: '以免影响本次面试的结果。如果你在面试过程中遇到问题,请与我们的招聘人员联系。'
  164. }
  165. ],
  166. secondVideoSubtitles: [
  167. {
  168. startTime: 0,
  169. endTime: 10,
  170. text: '请结合您的基本信息与过往履历进行简单的自我介绍,并讲一讲您有哪些优势胜任本岗位:'
  171. }
  172. ],
  173. thirdVideoSubtitles: [
  174. {
  175. startTime: 0,
  176. endTime: 3,
  177. text: '在工作中,你如何确保个人防护装备的正确使用?'
  178. }
  179. ],
  180. fourthVideoSubtitles: [
  181. {
  182. startTime: 0,
  183. endTime: 3,
  184. text: '描述一次你与团队合作改善生产流程的经历。'
  185. }
  186. ],
  187. fifthVideoSubtitles: [
  188. {
  189. startTime: 0,
  190. endTime: 6,
  191. text: '你在团队合作中曾遇到过哪些挑战?如何解决团队内部的分歧?'
  192. }
  193. ],
  194. sixthVideoSubtitles: [
  195. {
  196. startTime: 0,
  197. endTime: 5,
  198. text: '您已完成本次面试全部题目,请问您对于这个岗位还有什么想要了解的吗?'
  199. }
  200. ],
  201. showAnswerButton: false, // 控制答题按钮显示
  202. currentVideoIndex: 0, // 当前播放的视频索引
  203. videoList: [
  204. 'http://121.36.251.245:9000/minlong/9c139c99-a613-49f2-986b-8a3ac20a9b1b.mp4', // 第一段视频
  205. 'http://121.36.251.245:9000/minlong/15467aca-2c1e-4d40-bebc-11fc984f0a24.mp4', // 第二段视频
  206. 'http://121.36.251.245:9000/minlong/a96f295c-ecba-4b08-b627-0ed0dc72d727.mp4', // 第三段视频
  207. 'http://121.36.251.245:9000/minlong/e152eb38-7e03-4bb0-8b8d-73d51342d2aa.mp4',
  208. 'http://121.36.251.245:9000/minlong/6381eec3-1373-400f-aa8c-e229b60522ea.mp4',
  209. 'http://121.36.251.245:9000/minlong/2a11fe78-38d5-4af3-91c8-a080feb122e0.mp4'//结束
  210. ],
  211. isRecording: false,
  212. recordingTimer: null,
  213. showStopRecordingButton: false,
  214. mediaRecorder: null,
  215. recordedChunks: [],
  216. recorder: null,
  217. lastUploadedVideoUrl: '',
  218. showStartRecordingButton: false,
  219. showRetryButton: false, // 控制重试按钮显示
  220. lastVideoToRetry: null, // 存储上次失败的视频URL,用于重试
  221. recordingStartTime: null, // 录制开始时间
  222. recordingTimerCount: 0, // 录制计时器计数
  223. recordingTimeDisplay: '00:00', // 格式化的录制时间显示
  224. // 添加上传队列相关数据
  225. uploadQueue: [], // 存储待上传的视频
  226. isUploading: false, // 标记是否正在上传
  227. uploadProgress: {}, // 存储每个视频的上传进度
  228. uploadStatus: {}, // 存储每个视频的上传状态
  229. showUploadStatus: false, // 是否显示上传状态指示器
  230. uploadStatusText: '', // 上传状态文本
  231. mediaRecorderTimeout: null, // 用于存储MediaRecorder的超时机制
  232. maxRecordingTime: 300, // 最大录制时间(秒)- 从60秒改为300秒(5分钟)
  233. remainingTime: 300, // 剩余录制时间(秒)- 从60秒改为300秒
  234. }
  235. },
  236. mounted() {
  237. /* this.fetchData() */
  238. this.playDigitalHumanVideo();
  239. this.checkAudioPermission();
  240. this.initCamera();
  241. this.checkIOSCameraRecordPermission();
  242. // 添加防御性检查,避免渲染错误
  243. this.checkAndFixRenderingIssues();
  244. // 添加音频测试
  245. setTimeout(() => {
  246. if (this.cameraStream && !this.useMiniProgramCameraComponent) {
  247. this.testAudioInput();
  248. }
  249. }, 3000);
  250. },
  251. beforeDestroy() {
  252. // 组件销毁前停止摄像头
  253. this.stopUserCamera();
  254. },
  255. methods: {
  256. // 初始化相机
  257. async initCamera() {
  258. // 检查平台
  259. const systemInfo = uni.getSystemInfoSync();
  260. // 判断是否在小程序环境中
  261. const isMiniProgram = systemInfo.uniPlatform === 'mp-weixin' ||
  262. systemInfo.uniPlatform === 'mp-alipay' ||
  263. systemInfo.uniPlatform === 'mp-baidu';
  264. if (isMiniProgram) {
  265. // 小程序环境使用小程序的相机API
  266. this.useMiniProgramCameraComponent = true;
  267. // 创建相机上下文
  268. this.cameraContext = uni.createCameraContext();
  269. // 确保已获取录音和相机权限
  270. uni.getSetting({
  271. success: (res) => {
  272. // 检查录音权限
  273. if (!res.authSetting['scope.record']) {
  274. uni.authorize({
  275. scope: 'scope.record',
  276. success: () => {
  277. console.log('录音权限已获取');
  278. },
  279. fail: (err) => {
  280. console.error('录音权限获取失败:', err);
  281. this.showPermissionDialog('录音');
  282. }
  283. });
  284. }
  285. // 检查相机权限
  286. if (!res.authSetting['scope.camera']) {
  287. uni.authorize({
  288. scope: 'scope.camera',
  289. success: () => {
  290. console.log('相机权限已获取');
  291. },
  292. fail: (err) => {
  293. console.error('相机权限获取失败:', err);
  294. this.showPermissionDialog('相机');
  295. }
  296. });
  297. }
  298. // 在iOS上,可能需要额外的权限检查
  299. const systemInfo = uni.getSystemInfoSync();
  300. if (systemInfo.platform === 'ios') {
  301. // 在iOS上,不要使用无效的权限范围
  302. // 移除以下代码块
  303. /*
  304. if (!res.authSetting['scope.camera.record']) {
  305. uni.authorize({
  306. scope: 'scope.camera.record',
  307. success: () => {
  308. console.log('相机录制权限已获取');
  309. },
  310. fail: (err) => {
  311. console.error('相机录制权限获取失败:', err);
  312. this.showPermissionDialog('相机录制');
  313. }
  314. });
  315. }
  316. */
  317. // 确保同时获取了相机和录音权限
  318. if (!res.authSetting['scope.camera'] || !res.authSetting['scope.record']) {
  319. console.log('iOS需要同时获取相机和录音权限');
  320. }
  321. }
  322. }
  323. });
  324. } else {
  325. // H5/App环境使用浏览器的API
  326. try {
  327. // 请求摄像头和麦克风权限并获取媒体流,添加更多约束
  328. const constraints = {
  329. audio: {
  330. echoCancellation: true,
  331. noiseSuppression: true,
  332. autoGainControl: true
  333. },
  334. video: {
  335. width: { ideal: 640, max: 1280 }, // 控制视频宽度
  336. height: { ideal: 480, max: 720 }, // 控制视频高度
  337. frameRate: { ideal: 15, max: 24 }, // 控制帧率
  338. facingMode: 'user'
  339. }
  340. };
  341. const stream = await navigator.mediaDevices.getUserMedia(constraints);
  342. // 保存流以便后续使用
  343. this.cameraStream = stream;
  344. // 检查音频轨道
  345. const audioTracks = stream.getAudioTracks();
  346. console.log('音频轨道数量:', audioTracks.length);
  347. if (audioTracks.length > 0) {
  348. console.log('音频轨道已获取:', audioTracks[0].label);
  349. // 确保音频轨道已启用
  350. audioTracks[0].enabled = true;
  351. } else {
  352. console.warn('未检测到音频轨道,尝试单独获取音频');
  353. this.tryGetAudioOnly();
  354. }
  355. // 将流设置到视频元素
  356. const videoElement = this.$refs.userCameraVideo;
  357. if (videoElement) {
  358. videoElement.srcObject = stream;
  359. videoElement.muted = true; // 避免回声,但仍然录制声音
  360. }
  361. } catch (error) {
  362. console.error('获取摄像头失败:', error);
  363. this.cameraError = error.message || '无法访问摄像头';
  364. // 显示错误提示
  365. uni.showToast({
  366. title: '无法访问摄像头,请检查权限设置',
  367. icon: 'none'
  368. });
  369. }
  370. }
  371. },
  372. // 停止用户摄像头
  373. stopUserCamera() {
  374. if (this.cameraStream) {
  375. // 停止所有轨道
  376. this.cameraStream.getTracks().forEach(track => {
  377. track.stop();
  378. });
  379. this.cameraStream = null;
  380. }
  381. },
  382. async fetchData() {
  383. this.loading = true
  384. this.assistantResponse = ''
  385. this.audioTranscript = ''
  386. this.processedResponses = []
  387. try {
  388. // 使用uni.request代替fetch
  389. const requestTask = uni.request({
  390. url: 'https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions',
  391. method: 'POST',
  392. header: {
  393. 'Content-Type': 'application/json',
  394. 'Authorization': 'Bearer sk-9e1ec73a7d97493b8613c63f06b6110c'
  395. },
  396. data: {
  397. "model": "qwen-omni-turbo",
  398. "messages": [
  399. {
  400. "role": "user",
  401. "content": [
  402. {
  403. "type": "input_audio",
  404. "input_audio": {
  405. "data": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250211/tixcef/cherry.wav",
  406. "format": "wav"
  407. }
  408. },
  409. {
  410. "type": "text",
  411. "text": "这段音频在说什么"
  412. }
  413. ]
  414. }
  415. ],
  416. "stream":true,
  417. "stream_options":{
  418. "include_usage":true
  419. },
  420. "modalities":["text","audio"],
  421. "audio":{"voice":"Cherry","format":"wav"}
  422. },
  423. success: (res) => {
  424. console.log('请求成功,响应数据:', res.data);
  425. // 检查响应数据是否包含多个JSON对象
  426. if (typeof res.data === 'string' && res.data.includes('data: {')) {
  427. // 处理包含多个JSON对象的情况
  428. const chunks = res.data.split('data: ').filter(chunk => chunk.trim() !== '');
  429. chunks.forEach(chunk => {
  430. this.handleStreamResponse(chunk);
  431. });
  432. } else {
  433. // 处理单个响应对象的情况
  434. this.handleStreamResponse(res.data);
  435. }
  436. // 模拟获取到数字人视频并播放
  437. this.playDigitalHumanVideo();
  438. },
  439. fail: (err) => {
  440. console.error('请求失败:', err);
  441. },
  442. complete: () => {
  443. this.loading = false;
  444. }
  445. });
  446. } catch (error) {
  447. console.error('获取数据失败:', error);
  448. this.loading = false;
  449. }
  450. },
  451. handleStreamResponse(data) {
  452. // 处理流式响应数据
  453. if (typeof data === 'string') {
  454. // 处理字符串格式的响应
  455. if (data === '[DONE]') return;
  456. try {
  457. // 移除可能存在的换行符和多余空格
  458. const cleanData = data.trim();
  459. // 检查是否是有效的JSON字符串
  460. if (cleanData.startsWith('{') && cleanData.endsWith('}')) {
  461. const jsonData = JSON.parse(cleanData);
  462. this.processStreamChunk(jsonData);
  463. }
  464. } catch (e) {
  465. console.error('解析JSON失败:', e, '原始数据:', data);
  466. }
  467. } else {
  468. // 处理对象格式的响应
  469. this.processStreamChunk(data);
  470. }
  471. },
  472. processStreamChunk(chunk) {
  473. if (chunk.choices && chunk.choices.length > 0) {
  474. const choice = chunk.choices[0];
  475. // 处理助手回复内容
  476. if (choice.delta && choice.delta.content) {
  477. this.assistantResponse += choice.delta.content;
  478. }
  479. // 处理音频转写内容
  480. if (choice.delta && choice.delta.audio && choice.delta.audio.transcript) {
  481. this.audioTranscript += choice.delta.audio.transcript;
  482. }
  483. // 处理角色和音频转写
  484. if (choice.delta) {
  485. const result = {};
  486. if (choice.delta.role) {
  487. result.role = choice.delta.role;
  488. }
  489. if (choice.delta.audio && choice.delta.audio.transcript) {
  490. result.transcript = choice.delta.audio.transcript;
  491. }
  492. if (Object.keys(result).length > 0) {
  493. this.processedResponses.push(result);
  494. }
  495. }
  496. }
  497. },
  498. processResponseData() {
  499. // 处理返回的数据
  500. this.processedResponses = this.responses.map(item => {
  501. const result = {}
  502. // 处理角色信息
  503. if (item.delta && item.delta.role) {
  504. result.role = item.delta.role
  505. }
  506. // 处理音频转写文本
  507. if (item.delta && item.delta.audio && item.delta.audio.transcript) {
  508. result.transcript = item.delta.audio.transcript
  509. }
  510. return result
  511. }).filter(item => Object.keys(item).length > 0)
  512. },
  513. // 播放数字人视频
  514. playDigitalHumanVideo() {
  515. // 设置第一个视频
  516. this.videoUrl = this.videoList[this.currentVideoIndex];
  517. this.videoPlaying = true;
  518. // 使用 uni.createVideoContext 来控制视频
  519. this.$nextTick(() => {
  520. const videoContext = uni.createVideoContext('myVideo', this);
  521. if (videoContext) {
  522. videoContext.play();
  523. // 设置超时检查,确认视频是否真的在播放
  524. setTimeout(() => {
  525. if (this.videoPlaying && this.$refs.videoPlayer) {
  526. console.log('视频应该正在播放');
  527. } else {
  528. console.log('视频可能未成功播放,尝试替代方案');
  529. this.tryAlternativeVideoPath();
  530. }
  531. }, 1000);
  532. } else {
  533. console.error('无法创建视频上下文');
  534. this.tryAlternativeVideoPath();
  535. }
  536. });
  537. },
  538. // 修改 tryAlternativeVideoPath 方法
  539. tryAlternativeVideoPath() {
  540. console.log('尝试使用替代路径');
  541. // 尝试不同的路径格式
  542. const alternativePaths = [
  543. './static/demo.mp4',
  544. '../static/demo.mp4',
  545. 'static/demo.mp4',
  546. '/static/demo.mp4',
  547. // 添加绝对路径
  548. `${window.location.origin}/static/demo.mp4`
  549. ];
  550. // 获取当前路径索引
  551. const currentPathIndex = alternativePaths.indexOf(this.videoUrl);
  552. const nextPathIndex = (currentPathIndex + 1) % alternativePaths.length;
  553. // 设置下一个路径
  554. this.videoUrl = alternativePaths[nextPathIndex];
  555. console.log('尝试新路径:', this.videoUrl);
  556. this.$nextTick(() => {
  557. const videoContext = uni.createVideoContext('myVideo', this);
  558. if (videoContext) {
  559. videoContext.stop();
  560. videoContext.play();
  561. // 检查是否成功播放
  562. setTimeout(() => {
  563. if (nextPathIndex === alternativePaths.length - 1 && !this.videoPlaying) {
  564. console.log('所有路径均失败,尝试使用uni.getVideoInfo检查视频');
  565. this.checkVideoWithAPI();
  566. }
  567. }, 1000);
  568. }
  569. });
  570. },
  571. // 添加新方法:使用uni API检查视频
  572. checkVideoWithAPI() {
  573. // 尝试使用uni.getVideoInfo API检查视频是否可用
  574. uni.getVideoInfo({
  575. src: '/static/demo.mp4',
  576. success: (res) => {
  577. console.log('视频信息获取成功:', res);
  578. // 如果能获取到视频信息,再次尝试播放
  579. this.videoUrl = '/static/demo.mp4';
  580. this.$nextTick(() => {
  581. const videoContext = uni.createVideoContext('myVideo', this);
  582. if (videoContext) {
  583. videoContext.play();
  584. }
  585. });
  586. },
  587. fail: (err) => {
  588. console.error('视频信息获取失败:', err);
  589. // 最后尝试使用uni.chooseVideo API
  590. this.fallbackToLocalVideo();
  591. }
  592. });
  593. },
  594. // 添加新方法:回退到本地视频
  595. fallbackToLocalVideo() {
  596. console.log('尝试使用本地视频资源');
  597. // 检查平台
  598. const platform = uni.getSystemInfoSync().platform;
  599. if (platform === 'android' || platform === 'ios') {
  600. // 移动端可以尝试使用本地资源
  601. this.videoUrl = platform === 'android' ? 'android.resource://package_name/raw/demo' : 'file:///assets/demo.mp4';
  602. this.$nextTick(() => {
  603. const videoContext = uni.createVideoContext('myVideo', this);
  604. if (videoContext) {
  605. videoContext.play();
  606. }
  607. });
  608. } else {
  609. // 最终回退到静态图片
  610. this.videoPlaying = false;
  611. uni.showToast({
  612. title: '视频加载失败,显示静态图片',
  613. icon: 'none'
  614. });
  615. }
  616. },
  617. // 修改 handleVideoError 方法
  618. handleVideoError(e) {
  619. console.error('视频加载错误:', e);
  620. // 记录更详细的错误信息
  621. if (e && e.detail) {
  622. console.error('详细错误信息:', e.detail);
  623. }
  624. // 检查视频文件是否存在
  625. uni.getFileInfo({
  626. filePath: this.videoUrl.startsWith('/') ? this.videoUrl.substring(1) : this.videoUrl,
  627. success: (res) => {
  628. console.log('文件存在,大小:', res.size);
  629. // 文件存在但播放失败,可能是格式问题
  630. this.tryDifferentFormat();
  631. },
  632. fail: (err) => {
  633. console.error('文件不存在或无法访问:', err);
  634. // 尝试不同路径
  635. this.tryAlternativeVideoPath();
  636. }
  637. });
  638. // 如果多次尝试后仍然失败,显示错误信息
  639. uni.showToast({
  640. title: '视频加载失败,请检查文件是否存在',
  641. icon: 'none',
  642. duration: 2000
  643. });
  644. },
  645. // 添加新方法:尝试不同格式
  646. tryDifferentFormat() {
  647. console.log('尝试不同的视频格式');
  648. // 尝试不同的视频格式
  649. const formats = [
  650. { ext: 'mp4', mime: 'video/mp4' },
  651. { ext: 'webm', mime: 'video/webm' },
  652. { ext: 'ogg', mime: 'video/ogg' },
  653. { ext: 'mov', mime: 'video/quicktime' }
  654. ];
  655. // 获取当前文件名(不含扩展名)
  656. const currentPath = this.videoUrl;
  657. const basePath = currentPath.substring(0, currentPath.lastIndexOf('.')) || '/static/demo';
  658. // 尝试下一个格式
  659. let nextFormat = formats.find(f => !currentPath.endsWith(f.ext));
  660. if (nextFormat) {
  661. this.videoUrl = `${basePath}.${nextFormat.ext}`;
  662. console.log('尝试新格式:', this.videoUrl);
  663. this.$nextTick(() => {
  664. const videoContext = uni.createVideoContext('myVideo', this);
  665. if (videoContext) {
  666. videoContext.stop();
  667. videoContext.play();
  668. }
  669. });
  670. } else {
  671. // 所有格式都尝试过了,使用内置资源
  672. this.useBuiltInResource();
  673. }
  674. },
  675. // 添加新方法:使用内置资源
  676. useBuiltInResource() {
  677. console.log('尝试使用内置资源');
  678. // 检查平台
  679. const platform = uni.getSystemInfoSync().platform;
  680. // 根据平台选择合适的视频源
  681. if (platform === 'windows') {
  682. // Windows平台特定处理
  683. // 尝试使用相对于应用根目录的路径
  684. const appRoot = process.env.UNI_INPUT_DIR || '';
  685. this.videoUrl = `./static/demo.mp4`;
  686. // 或者尝试使用file://协议
  687. // this.videoUrl = `file:///${appRoot.replace(/\\/g, '/')}/static/demo.mp4`;
  688. console.log('Windows平台尝试路径:', this.videoUrl);
  689. } else if (platform === 'android' || platform === 'ios') {
  690. // 移动端
  691. this.useNativeVideo();
  692. } else {
  693. // Web平台
  694. // 尝试使用完整URL
  695. const baseUrl = window.location.origin;
  696. this.videoUrl = `${baseUrl}/static/demo.mp4`;
  697. console.log('Web平台尝试URL:', this.videoUrl);
  698. }
  699. this.$nextTick(() => {
  700. const videoContext = uni.createVideoContext('myVideo', this);
  701. if (videoContext) {
  702. videoContext.play();
  703. }
  704. });
  705. },
  706. // 添加新方法:使用原生视频能力
  707. useNativeVideo() {
  708. console.log('尝试使用原生视频能力');
  709. // 在移动端,可以尝试使用原生视频播放器
  710. uni.chooseVideo({
  711. sourceType: ['album'],
  712. success: (res) => {
  713. this.videoUrl = res.tempFilePath;
  714. this.$nextTick(() => {
  715. const videoContext = uni.createVideoContext('myVideo', this);
  716. if (videoContext) {
  717. videoContext.play();
  718. }
  719. });
  720. },
  721. fail: () => {
  722. // 如果用户取消选择,回退到静态图片
  723. this.videoPlaying = false;
  724. uni.showToast({
  725. title: '无法加载视频,显示静态图片',
  726. icon: 'none'
  727. });
  728. }
  729. });
  730. },
  731. // 处理视频结束事件
  732. handleVideoEnded() {
  733. console.log('视频播放结束');
  734. this.videoPlaying = false;
  735. // 对于所有视频,都显示相应的按钮
  736. if (this.currentVideoIndex >= 1) {
  737. // 对于问题视频,显示"开始回答"按钮
  738. this.showStartRecordingButton = true;
  739. } else {
  740. // 对于介绍视频(第一个视频),显示"开始面试"按钮
  741. this.showAnswerButton = true;
  742. }
  743. },
  744. // 添加新方法:开始录制用户回答
  745. startRecordingAnswer() {
  746. console.log('开始录制用户回答');
  747. this.isRecording = true;
  748. // 记录录制开始时间
  749. this.recordingStartTime = Date.now();
  750. this.recordingTimerCount = 0;
  751. this.remainingTime = this.maxRecordingTime;
  752. // 启动计时器,每秒更新计时
  753. this.recordingTimer = setInterval(() => {
  754. this.recordingTimerCount++;
  755. this.remainingTime = Math.max(0, this.maxRecordingTime - this.recordingTimerCount);
  756. // 更新UI显示录制时长和剩余时间
  757. this.recordingTimeDisplay = this.formatTime(this.recordingTimerCount) +
  758. ' / ' + this.formatTime(this.maxRecordingTime);
  759. // 检查是否达到最大录制时间
  760. if (this.recordingTimerCount >= this.maxRecordingTime) {
  761. console.log('已达到最大录制时间(60秒),自动停止录制');
  762. this.stopRecordingAnswer();
  763. }
  764. }, 1000);
  765. // 显示录制中的提示
  766. // uni.showLoading({
  767. // title: '正在录制...',
  768. // mask: true
  769. // });
  770. // 根据平台选择不同的录制方法
  771. const systemInfo = uni.getSystemInfoSync();
  772. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith('mp-');
  773. if (isMiniProgram) {
  774. // 小程序环境使用小程序的录制API
  775. this.startMiniProgramRecording();
  776. } else {
  777. // H5/App环境使用MediaRecorder API
  778. this.startBrowserRecording();
  779. }
  780. // 显示停止录制按钮
  781. this.showStopRecordingButton = true;
  782. },
  783. // 添加一个新方法:重置相机组件
  784. resetCamera() {
  785. console.log('重置相机组件');
  786. // 先完全移除相机组件
  787. this.useMiniProgramCameraComponent = false;
  788. // 释放相机上下文
  789. if (this.cameraContext) {
  790. this.cameraContext = null;
  791. }
  792. // 延迟后重新创建相机组件
  793. setTimeout(() => {
  794. this.useMiniProgramCameraComponent = true;
  795. // 再次延迟创建相机上下文,确保组件已完全渲染
  796. setTimeout(() => {
  797. this.cameraContext = uni.createCameraContext();
  798. console.log('相机组件已重置');
  799. }, 500);
  800. }, 500);
  801. },
  802. // 修改 startMiniProgramRecording 方法
  803. startMiniProgramRecording() {
  804. console.log('开始小程序录制方法');
  805. // 获取平台信息
  806. const systemInfo = uni.getSystemInfoSync();
  807. const isIOS = systemInfo.platform === 'ios';
  808. // 在iOS上,先重置相机
  809. if (isIOS) {
  810. // 先重置相机组件
  811. this.resetCamera();
  812. // 延迟执行录制,给相机组件足够的初始化时间
  813. setTimeout(() => {
  814. this.actualStartRecording(isIOS);
  815. }, 1000);
  816. } else {
  817. // Android直接开始
  818. this.actualStartRecording(isIOS);
  819. }
  820. },
  821. // 添加新方法:实际开始录制
  822. actualStartRecording(isIOS) {
  823. if (!this.cameraContext) {
  824. this.cameraContext = uni.createCameraContext();
  825. console.log('创建新的相机上下文');
  826. }
  827. // 确保有录音权限
  828. uni.getSetting({
  829. success: (res) => {
  830. const hasRecordAuth = res.authSetting['scope.record'];
  831. const hasCameraAuth = res.authSetting['scope.camera'];
  832. if (!hasRecordAuth || !hasCameraAuth) {
  833. console.warn('缺少必要权限,请求权限');
  834. this.requestMiniProgramPermissions();
  835. return;
  836. }
  837. // 在iOS上,先检查相机状态
  838. if (isIOS) {
  839. console.log('iOS: 检查相机状态');
  840. // 使用最简单的选项,设置最大录制时间为5分钟
  841. const options = {
  842. timeout: 300000, // 300秒超时 (5分钟)
  843. quality: 'low', // 降低质量
  844. compressed: true,
  845. success: () => {
  846. console.log('iOS录制开始成功');
  847. },
  848. fail: (err) => {
  849. console.error('iOS录制失败:', err);
  850. // 如果失败,尝试使用不同的方法
  851. this.useAlternativeRecordingMethod();
  852. }
  853. };
  854. try {
  855. console.log('尝试开始录制');
  856. this.recorder = this.cameraContext.startRecord(options);
  857. } catch (e) {
  858. console.error('开始录制异常:', e);
  859. this.useAlternativeRecordingMethod();
  860. }
  861. } else {
  862. // Android使用标准选项,设置最大录制时间为5分钟
  863. const options = {
  864. timeout: 300000, // 300秒超时 (5分钟)
  865. quality: 'medium',
  866. compressed: true,
  867. success: () => {
  868. console.log('Android录制开始成功');
  869. },
  870. fail: (err) => {
  871. console.error('Android录制失败:', err);
  872. uni.showToast({
  873. title: '录制失败,请检查相机权限',
  874. icon: 'none'
  875. });
  876. this.proceedToNextQuestion();
  877. }
  878. };
  879. this.recorder = this.cameraContext.startRecord(options);
  880. }
  881. }
  882. });
  883. },
  884. // 添加新方法:使用替代录制方法
  885. useAlternativeRecordingMethod() {
  886. console.log('使用替代录制方法');
  887. // 在iOS上,可以尝试使用chooseVideo API作为备选
  888. uni.showActionSheet({
  889. itemList: ['使用相册中的视频', '跳过此问题'],
  890. success: (res) => {
  891. if (res.tapIndex === 0) {
  892. // 选择相册中的视频
  893. uni.chooseVideo({
  894. sourceType: ['album'],
  895. maxDuration: 300, // 从60秒改为300秒
  896. camera: 'front',
  897. success: (res) => {
  898. console.log('选择视频成功:', res.tempFilePath);
  899. // 停止录制状态
  900. this.isRecording = false;
  901. this.showStopRecordingButton = false;
  902. // 上传选择的视频
  903. this.uploadRecordedVideo(res.tempFilePath);
  904. },
  905. fail: () => {
  906. console.log('用户取消选择视频');
  907. this.proceedToNextQuestion();
  908. }
  909. });
  910. } else {
  911. // 跳过此问题
  912. console.log('用户选择跳过问题');
  913. this.proceedToNextQuestion();
  914. }
  915. },
  916. fail: () => {
  917. console.log('操作取消');
  918. this.proceedToNextQuestion();
  919. }
  920. });
  921. },
  922. // 添加新方法:请求小程序权限
  923. requestMiniProgramPermissions() {
  924. // 请求录音权限
  925. uni.authorize({
  926. scope: 'scope.record',
  927. success: () => {
  928. console.log('录音权限已获取');
  929. // 请求相机权限
  930. uni.authorize({
  931. scope: 'scope.camera',
  932. success: () => {
  933. console.log('相机权限已获取');
  934. // 权限都获取到后,开始录制
  935. this.startMiniProgramRecording();
  936. },
  937. fail: (err) => {
  938. console.error('相机权限获取失败:', err);
  939. this.showPermissionDialog('相机');
  940. }
  941. });
  942. },
  943. fail: (err) => {
  944. console.error('录音权限获取失败:', err);
  945. this.showPermissionDialog('录音');
  946. }
  947. });
  948. },
  949. // 修改浏览器环境下的录制方法
  950. startBrowserRecording() {
  951. if (!this.cameraStream) {
  952. console.error('没有可用的摄像头流');
  953. uni.showToast({
  954. title: '录制失败,摄像头未就绪',
  955. icon: 'none'
  956. });
  957. this.proceedToNextQuestion();
  958. return;
  959. }
  960. try {
  961. // 检查流中是否包含音频轨道
  962. const hasAudio = this.cameraStream.getAudioTracks().length > 0;
  963. if (!hasAudio) {
  964. console.warn('警告:媒体流中没有音频轨道,尝试重新获取带音频的媒体流');
  965. // 尝试重新获取带音频的媒体流
  966. navigator.mediaDevices.getUserMedia({
  967. audio: {
  968. echoCancellation: true,
  969. noiseSuppression: true,
  970. autoGainControl: true
  971. },
  972. video: true
  973. })
  974. .then(newStream => {
  975. // 检查新流是否包含音频轨道
  976. const audioTracks = newStream.getAudioTracks();
  977. if (audioTracks.length > 0) {
  978. console.log('成功获取音频轨道:', audioTracks[0].label);
  979. // 合并视频和音频轨道
  980. const videoTrack = this.cameraStream.getVideoTracks()[0];
  981. const audioTrack = newStream.getAudioTracks()[0];
  982. // 创建新的媒体流,包含视频和音频轨道
  983. const combinedStream = new MediaStream();
  984. if (videoTrack) combinedStream.addTrack(videoTrack);
  985. if (audioTrack) combinedStream.addTrack(audioTrack);
  986. this.cameraStream = combinedStream;
  987. // 更新视频元素的源
  988. const videoElement = this.$refs.userCameraVideo;
  989. if (videoElement) {
  990. videoElement.srcObject = combinedStream;
  991. videoElement.muted = true; // 避免回声,但仍然录制声音
  992. }
  993. // 继续录制过程
  994. this.setupMediaRecorder(combinedStream);
  995. } else {
  996. console.warn('仍然无法获取音频轨道');
  997. // 使用现有流继续
  998. this.setupMediaRecorder(this.cameraStream);
  999. }
  1000. })
  1001. .catch(err => {
  1002. console.error('获取音频失败:', err);
  1003. // 使用现有流继续
  1004. this.setupMediaRecorder(this.cameraStream);
  1005. });
  1006. } else {
  1007. console.log('检测到音频轨道,直接使用');
  1008. // 已有音频轨道,直接使用
  1009. this.setupMediaRecorder(this.cameraStream);
  1010. }
  1011. } catch (error) {
  1012. console.error('浏览器录制失败:', error);
  1013. uni.showToast({
  1014. title: '录制失败,浏览器可能不支持此功能',
  1015. icon: 'none'
  1016. });
  1017. this.proceedToNextQuestion();
  1018. }
  1019. },
  1020. // 修改 setupMediaRecorder 方法
  1021. setupMediaRecorder(stream) {
  1022. // 检查流中的轨道
  1023. const videoTracks = stream.getVideoTracks();
  1024. const audioTracks = stream.getAudioTracks();
  1025. console.log('设置MediaRecorder - 视频轨道:', videoTracks.length, '音频轨道:', audioTracks.length);
  1026. // 尝试使用支持度更广的编码格式
  1027. let mimeType = '';
  1028. const supportedTypes = [
  1029. 'video/webm;codecs=vp9,opus',
  1030. 'video/webm;codecs=vp8,opus',
  1031. 'video/webm;codecs=h264,opus',
  1032. 'video/mp4;codecs=h264,aac',
  1033. 'video/webm',
  1034. 'video/mp4'
  1035. ];
  1036. for (const type of supportedTypes) {
  1037. if (MediaRecorder.isTypeSupported(type)) {
  1038. mimeType = type;
  1039. console.log('使用支持的MIME类型:', mimeType);
  1040. break;
  1041. }
  1042. }
  1043. // 创建MediaRecorder实例,设置较低的比特率以减小文件大小
  1044. const options = {
  1045. mimeType: mimeType || '',
  1046. audioBitsPerSecond: 64000, // 降低音频比特率
  1047. videoBitsPerSecond: 1000000, // 降低视频比特率到1Mbps
  1048. };
  1049. try {
  1050. this.mediaRecorder = new MediaRecorder(stream, options);
  1051. console.log('MediaRecorder创建成功,使用选项:', options);
  1052. } catch (e) {
  1053. console.warn('使用指定选项创建MediaRecorder失败,尝试使用默认选项');
  1054. this.mediaRecorder = new MediaRecorder(stream);
  1055. }
  1056. // 存储录制的数据块
  1057. this.recordedChunks = [];
  1058. // 监听数据可用事件
  1059. this.mediaRecorder.ondataavailable = (event) => {
  1060. if (event.data && event.data.size > 0) {
  1061. this.recordedChunks.push(event.data);
  1062. console.log(`收到数据块: ${event.data.size} 字节`);
  1063. }
  1064. };
  1065. // 监听录制停止事件
  1066. this.mediaRecorder.onstop = async () => {
  1067. console.log('MediaRecorder停止,数据块数量:', this.recordedChunks.length);
  1068. if (this.recordedChunks.length === 0) {
  1069. console.error('没有录制到数据');
  1070. uni.showToast({
  1071. title: '录制失败,未捕获到数据',
  1072. icon: 'none'
  1073. });
  1074. this.proceedToNextQuestion();
  1075. return;
  1076. }
  1077. // 创建Blob对象
  1078. const mimeType = this.mediaRecorder.mimeType || 'video/webm';
  1079. const blob = new Blob(this.recordedChunks, { type: mimeType });
  1080. console.log('创建Blob,原始大小:', blob.size, '类型:', mimeType);
  1081. // 显示压缩中提示
  1082. uni.showLoading({
  1083. title: '正在处理视频...',
  1084. mask: true
  1085. });
  1086. try {
  1087. // 压缩视频
  1088. const compressedBlob = await this.compressVideo(blob);
  1089. // 将Blob转换为File对象
  1090. const fileName = `answer_${this.currentVideoIndex}_${Date.now()}.webm`;
  1091. const file = new File([compressedBlob], fileName, { type: mimeType });
  1092. // 隐藏压缩提示
  1093. uni.hideLoading();
  1094. // 上传文件
  1095. this.uploadRecordedVideo(file);
  1096. } catch (error) {
  1097. console.error('视频处理失败:', error);
  1098. uni.hideLoading();
  1099. // 如果压缩失败,使用原始视频
  1100. const fileName = `answer_${this.currentVideoIndex}_${Date.now()}.webm`;
  1101. const file = new File([blob], fileName, { type: mimeType });
  1102. this.uploadRecordedVideo(file);
  1103. }
  1104. };
  1105. // 监听错误
  1106. this.mediaRecorder.onerror = (event) => {
  1107. console.error('MediaRecorder错误:', event.error);
  1108. };
  1109. // 开始录制
  1110. try {
  1111. this.mediaRecorder.start(1000); // 每秒触发一次dataavailable事件
  1112. console.log('MediaRecorder开始录制');
  1113. // 设置最大录制时间为60秒
  1114. // 注意:我们已经在startRecordingAnswer方法中设置了全局计时器
  1115. // 这里作为备份机制,确保即使全局计时器失效,也能停止录制
  1116. this.mediaRecorderTimeout = setTimeout(() => {
  1117. if (this.mediaRecorder && this.mediaRecorder.state === 'recording') {
  1118. console.log('MediaRecorder备份超时机制触发,停止录制');
  1119. this.mediaRecorder.stop();
  1120. }
  1121. }, 300000); // 300秒 (5分钟)
  1122. } catch (e) {
  1123. console.error('开始录制失败:', e);
  1124. }
  1125. },
  1126. // 添加新方法:停止录制用户回答
  1127. stopRecordingAnswer() {
  1128. console.log('停止录制用户回答');
  1129. // 检查录制时长
  1130. const recordingDuration = this.getRecordingDuration();
  1131. const minimumDuration = 3; // 最小录制时长(秒)
  1132. if (recordingDuration < minimumDuration) {
  1133. // 录制时间过短,显示提示
  1134. uni.showModal({
  1135. title: '录制时间过短',
  1136. content: '您的回答时间过短,请至少录制' + minimumDuration + '秒。是否重新录制?',
  1137. confirmText: '重新录制',
  1138. cancelText: '仍然提交',
  1139. success: (res) => {
  1140. if (res.confirm) {
  1141. // 用户选择重新录制
  1142. console.log('用户选择重新录制');
  1143. // 重置录制状态但不停止当前录制
  1144. this.resetRecording();
  1145. return;
  1146. } else {
  1147. // 用户选择仍然提交,继续执行停止录制逻辑
  1148. console.log('用户选择继续提交短视频');
  1149. this.completeRecordingStop();
  1150. }
  1151. }
  1152. });
  1153. } else {
  1154. // 录制时长足够,直接停止
  1155. this.completeRecordingStop();
  1156. }
  1157. },
  1158. // 添加新方法:获取录制时长
  1159. getRecordingDuration() {
  1160. // 如果有明确的录制开始时间,计算实际录制时长
  1161. if (this.recordingStartTime) {
  1162. return (Date.now() - this.recordingStartTime) / 1000;
  1163. }
  1164. // 如果没有明确记录开始时间,尝试从视频元素获取
  1165. if (this.mediaRecorder && this.$refs.userCameraVideo) {
  1166. return this.$refs.userCameraVideo.currentTime || 0;
  1167. }
  1168. // 如果无法获取准确时长,返回估计值(如果有计时器)
  1169. if (this.recordingTimerCount) {
  1170. return this.recordingTimerCount;
  1171. }
  1172. // 默认返回0
  1173. return 0;
  1174. },
  1175. // 添加新方法:重置录制
  1176. resetRecording() {
  1177. // 保持录制状态,但重置计时器
  1178. if (this.recordingTimer) {
  1179. clearTimeout(this.recordingTimer);
  1180. }
  1181. // 重置录制开始时间
  1182. this.recordingStartTime = Date.now();
  1183. this.recordingTimerCount = 0;
  1184. // 如果是浏览器环境,需要重置MediaRecorder
  1185. if (this.mediaRecorder && this.mediaRecorder.state !== 'inactive') {
  1186. // 停止当前录制
  1187. this.mediaRecorder.stop();
  1188. // 清空已录制的数据块
  1189. this.recordedChunks = [];
  1190. // 短暂延迟后重新开始录制
  1191. setTimeout(() => {
  1192. this.startBrowserRecording();
  1193. }, 500);
  1194. }
  1195. // 如果是小程序环境,需要重置相机录制
  1196. else if (this.cameraContext) {
  1197. // 停止当前录制
  1198. this.cameraContext.stopRecord({
  1199. success: () => {
  1200. console.log('重置录制:停止当前录制成功');
  1201. // 短暂延迟后重新开始录制
  1202. setTimeout(() => {
  1203. this.startMiniProgramRecording();
  1204. }, 500);
  1205. },
  1206. fail: (err) => {
  1207. console.error('重置录制:停止当前录制失败', err);
  1208. // 尝试直接重新开始录制
  1209. this.startMiniProgramRecording();
  1210. }
  1211. });
  1212. }
  1213. // 显示提示
  1214. uni.showToast({
  1215. title: '请重新开始回答',
  1216. icon: 'none',
  1217. duration: 2000
  1218. });
  1219. },
  1220. // 添加新方法:完成录制停止流程
  1221. completeRecordingStop() {
  1222. this.isRecording = false;
  1223. // 清除定时器
  1224. if (this.recordingTimer) {
  1225. clearInterval(this.recordingTimer);
  1226. this.recordingTimer = null;
  1227. }
  1228. // 清除MediaRecorder超时定时器
  1229. if (this.mediaRecorderTimeout) {
  1230. clearTimeout(this.mediaRecorderTimeout);
  1231. this.mediaRecorderTimeout = null;
  1232. }
  1233. // 隐藏录制中提示
  1234. uni.hideLoading();
  1235. // 隐藏停止录制按钮
  1236. this.showStopRecordingButton = false;
  1237. // 根据平台选择不同的停止录制方法
  1238. const systemInfo = uni.getSystemInfoSync();
  1239. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith('mp-');
  1240. if (isMiniProgram) {
  1241. // 小程序环境停止录制
  1242. this.stopMiniProgramRecording();
  1243. } else {
  1244. // H5/App环境停止录制
  1245. this.stopBrowserRecording();
  1246. }
  1247. },
  1248. // 修改 stopMiniProgramRecording 方法
  1249. stopMiniProgramRecording() {
  1250. if (!this.cameraContext) {
  1251. console.error('相机上下文不存在');
  1252. this.proceedToNextQuestion();
  1253. return;
  1254. }
  1255. const systemInfo = uni.getSystemInfoSync();
  1256. const isIOS = systemInfo.platform === 'ios';
  1257. // 在iOS上添加额外的错误处理
  1258. const stopOptions = {
  1259. success: (res) => {
  1260. console.log('小程序录像停止成功:', res);
  1261. // 获取临时文件路径
  1262. const tempFilePath = res.tempVideoPath;
  1263. if (!tempFilePath) {
  1264. console.error('未获取到视频文件路径');
  1265. uni.showToast({
  1266. title: '录制失败,未获取到视频文件',
  1267. icon: 'none'
  1268. });
  1269. this.proceedToNextQuestion();
  1270. return;
  1271. }
  1272. // 在iOS上,检查文件是否存在
  1273. if (isIOS) {
  1274. uni.getFileInfo({
  1275. filePath: tempFilePath,
  1276. success: () => {
  1277. // 文件存在,上传视频
  1278. this.uploadRecordedVideo(tempFilePath);
  1279. },
  1280. fail: (err) => {
  1281. console.error('视频文件不存在:', err);
  1282. uni.showToast({
  1283. title: '录制失败,视频文件不存在',
  1284. icon: 'none'
  1285. });
  1286. this.proceedToNextQuestion();
  1287. }
  1288. });
  1289. } else {
  1290. // Android直接上传
  1291. this.uploadRecordedVideo(tempFilePath);
  1292. }
  1293. },
  1294. fail: (err) => {
  1295. console.error('小程序录像停止失败:', err);
  1296. uni.showToast({
  1297. title: '录制失败',
  1298. icon: 'none'
  1299. });
  1300. this.proceedToNextQuestion();
  1301. }
  1302. };
  1303. // 停止录制
  1304. this.cameraContext.stopRecord(stopOptions);
  1305. },
  1306. // 添加新方法:停止浏览器录制
  1307. stopBrowserRecording() {
  1308. if (this.mediaRecorder && this.mediaRecorder.state !== 'inactive') {
  1309. this.mediaRecorder.stop();
  1310. console.log('浏览器录制停止成功');
  1311. } else {
  1312. console.error('MediaRecorder不存在或已经停止');
  1313. this.proceedToNextQuestion();
  1314. }
  1315. },
  1316. // 修改上传录制的视频方法
  1317. uploadRecordedVideo(fileOrPath) {
  1318. console.log('准备上传视频:', typeof fileOrPath === 'string' ? fileOrPath : fileOrPath.name);
  1319. // 根据当前视频索引映射到正确的问题ID
  1320. let questionId;
  1321. switch(this.currentVideoIndex) {
  1322. case 1: // 第一个问题
  1323. questionId = 10;
  1324. break;
  1325. case 2: // 第二个问题
  1326. questionId = 11;
  1327. break;
  1328. case 3: // 第三个问题
  1329. questionId = 12;
  1330. break;
  1331. case 4: // 第四个问题
  1332. questionId = 13;
  1333. break;
  1334. default:
  1335. questionId = 10; // 默认值
  1336. }
  1337. // 创建上传任务对象
  1338. const uploadTask = {
  1339. id: Date.now().toString(), // 生成唯一ID
  1340. file: fileOrPath,
  1341. questionId: questionId,
  1342. attempts: 0, // 上传尝试次数
  1343. maxAttempts: 3, // 最大尝试次数
  1344. };
  1345. // 添加到上传队列
  1346. this.uploadQueue.push(uploadTask);
  1347. // 初始化上传进度和状态
  1348. this.uploadProgress[uploadTask.id] = 0;
  1349. this.uploadStatus[uploadTask.id] = 'pending'; // pending, uploading, success, failed
  1350. // 显示简短的上传状态提示
  1351. uni.showToast({
  1352. title: '视频已加入上传队列',
  1353. icon: 'none',
  1354. duration: 1500
  1355. });
  1356. // 更新上传状态文本
  1357. this.updateUploadStatusText();
  1358. // 如果当前没有上传任务在进行,开始处理队列
  1359. if (!this.isUploading) {
  1360. this.processUploadQueue();
  1361. }
  1362. // 立即进入下一个问题,不等待上传完成
  1363. this.proceedToNextQuestion();
  1364. },
  1365. // 添加新方法:处理上传队列
  1366. processUploadQueue() {
  1367. // 如果队列为空,结束处理
  1368. if (this.uploadQueue.length === 0) {
  1369. this.isUploading = false;
  1370. this.showUploadStatus = false;
  1371. return;
  1372. }
  1373. // 标记为正在上传
  1374. this.isUploading = true;
  1375. this.showUploadStatus = true;
  1376. // 获取队列中的第一个任务
  1377. const task = this.uploadQueue[0];
  1378. // 更新任务状态
  1379. this.uploadStatus[task.id] = 'uploading';
  1380. this.updateUploadStatusText();
  1381. // 增加尝试次数
  1382. task.attempts++;
  1383. // 根据文件类型选择上传方法
  1384. if (typeof task.file !== 'string') {
  1385. // 浏览器环境,使用XMLHttpRequest上传
  1386. this.uploadFileWithXHR(task);
  1387. } else {
  1388. // 小程序环境,使用uni.uploadFile上传
  1389. this.uploadFileWithUni(task);
  1390. }
  1391. },
  1392. // 添加新方法:使用XMLHttpRequest上传文件
  1393. uploadFileWithXHR(task) {
  1394. // 获取用户信息
  1395. const userInfo = uni.getStorageSync('userInfo');
  1396. const openid = userInfo ? (JSON.parse(userInfo).openid || '') : '';
  1397. const tenant_id = uni.getStorageSync('tenant_id') || '1';
  1398. // 创建FormData
  1399. const formData = new FormData();
  1400. formData.append('file', task.file);
  1401. formData.append('openid', openid);
  1402. formData.append('tenant_id', tenant_id);
  1403. formData.append('application_id', uni.getStorageSync('appId'));
  1404. formData.append('question_id', task.questionId);
  1405. formData.append('video_duration', 0);
  1406. formData.append('has_audio', 'true');
  1407. // 创建XMLHttpRequest
  1408. const xhr = new XMLHttpRequest();
  1409. xhr.open('POST', `${apiBaseUrl}/api/upload/`, true);
  1410. xhr.timeout = 120000; // 2分钟超时
  1411. // 监听上传进度
  1412. xhr.upload.onprogress = (event) => {
  1413. if (event.lengthComputable) {
  1414. const percentComplete = Math.round((event.loaded / event.total) * 100);
  1415. this.uploadProgress[task.id] = percentComplete;
  1416. this.updateUploadStatusText();
  1417. }
  1418. };
  1419. // 监听请求完成
  1420. xhr.onload = () => {
  1421. if (xhr.status === 200) {
  1422. try {
  1423. const res = JSON.parse(xhr.responseText);
  1424. console.log('上传响应:', res);
  1425. if (res.code === 2000) {
  1426. // 获取上传后的视频URL
  1427. const videoUrl = res.data.url || res.data.photoUrl || '';
  1428. if (videoUrl) {
  1429. // 上传成功,更新状态
  1430. this.uploadStatus[task.id] = 'success';
  1431. this.updateUploadStatusText();
  1432. // 提交到面试接口
  1433. this.submitVideoToInterview(videoUrl, task);
  1434. } else {
  1435. this.handleUploadFailure(task, '视频URL获取失败');
  1436. }
  1437. } else {
  1438. this.handleUploadFailure(task, res.msg || '上传失败');
  1439. }
  1440. } catch (e) {
  1441. this.handleUploadFailure(task, '解析响应失败');
  1442. }
  1443. } else {
  1444. this.handleUploadFailure(task, 'HTTP状态: ' + xhr.status);
  1445. }
  1446. };
  1447. // 监听错误
  1448. xhr.onerror = () => {
  1449. this.handleUploadFailure(task, '网络错误');
  1450. };
  1451. // 监听超时
  1452. xhr.ontimeout = () => {
  1453. this.handleUploadFailure(task, '上传超时');
  1454. };
  1455. // 发送请求
  1456. xhr.send(formData);
  1457. },
  1458. // 添加新方法:使用uni.uploadFile上传文件
  1459. uploadFileWithUni(task) {
  1460. // 获取用户信息
  1461. const userInfo = uni.getStorageSync('userInfo');
  1462. const openid = userInfo ? (JSON.parse(userInfo).openid || '') : '';
  1463. const tenant_id = uni.getStorageSync('tenant_id') || '1';
  1464. // 创建上传任务
  1465. const uploadTask = uni.uploadFile({
  1466. url: `${apiBaseUrl}/api/upload/`,
  1467. filePath: task.file,
  1468. name: 'file',
  1469. formData: {
  1470. openid: openid,
  1471. tenant_id: tenant_id,
  1472. application_id: uni.getStorageSync('appId'),
  1473. question_id: task.questionId,
  1474. video_duration: 0,
  1475. has_audio: 'true'
  1476. },
  1477. success: (uploadRes) => {
  1478. try {
  1479. const res = JSON.parse(uploadRes.data);
  1480. console.log('上传响应:', res);
  1481. if (res.code === 2000) {
  1482. // 获取上传后的视频URL
  1483. const videoUrl = res.data.permanent_link || res.data.url || '';
  1484. if (videoUrl) {
  1485. // 上传成功,更新状态
  1486. this.uploadStatus[task.id] = 'success';
  1487. this.updateUploadStatusText();
  1488. // 提交到面试接口
  1489. this.submitVideoToInterview(videoUrl, task);
  1490. } else {
  1491. this.handleUploadFailure(task, '视频URL获取失败');
  1492. }
  1493. } else {
  1494. this.handleUploadFailure(task, res.msg || '上传失败');
  1495. }
  1496. } catch (e) {
  1497. this.handleUploadFailure(task, '解析响应失败');
  1498. }
  1499. },
  1500. fail: (err) => {
  1501. this.handleUploadFailure(task, err.errMsg || '上传失败');
  1502. }
  1503. });
  1504. // 监听上传进度
  1505. uploadTask.onProgressUpdate((res) => {
  1506. this.uploadProgress[task.id] = res.progress;
  1507. this.updateUploadStatusText();
  1508. });
  1509. },
  1510. // 添加新方法:处理上传失败
  1511. handleUploadFailure(task, errorMsg) {
  1512. console.error('上传失败:', errorMsg);
  1513. // 更新任务状态
  1514. this.uploadStatus[task.id] = 'failed';
  1515. this.updateUploadStatusText();
  1516. // 检查是否还有重试机会
  1517. if (task.attempts < task.maxAttempts) {
  1518. console.log(`将在5秒后重试上传,当前尝试次数: ${task.attempts}/${task.maxAttempts}`);
  1519. // 5秒后重试
  1520. setTimeout(() => {
  1521. // 重置进度
  1522. this.uploadProgress[task.id] = 0;
  1523. // 重新开始上传
  1524. if (typeof task.file !== 'string') {
  1525. this.uploadFileWithXHR(task);
  1526. } else {
  1527. this.uploadFileWithUni(task);
  1528. }
  1529. }, 5000);
  1530. } else {
  1531. // 超过最大重试次数,移除任务并继续处理队列
  1532. console.log('超过最大重试次数,放弃上传');
  1533. // 显示错误提示
  1534. uni.showToast({
  1535. title: '视频上传失败,请稍后重试',
  1536. icon: 'none',
  1537. duration: 2000
  1538. });
  1539. // 从队列中移除当前任务
  1540. this.uploadQueue.shift();
  1541. // 继续处理队列中的下一个任务
  1542. this.processUploadQueue();
  1543. }
  1544. },
  1545. // 修改 submitVideoToInterview 方法
  1546. submitVideoToInterview(videoUrl, task = null) {
  1547. console.log('提交视频URL到面试接口:', videoUrl);
  1548. // 确定问题ID
  1549. let questionId;
  1550. if (task) {
  1551. questionId = task.questionId;
  1552. } else {
  1553. // 根据当前视频索引映射到正确的问题ID(兼容旧代码)
  1554. switch(this.currentVideoIndex) {
  1555. case 1:
  1556. questionId = 10;
  1557. break;
  1558. case 2:
  1559. questionId = 11;
  1560. break;
  1561. case 3:
  1562. questionId = 12;
  1563. break;
  1564. case 4:
  1565. questionId = 13;
  1566. break;
  1567. default:
  1568. questionId = 10;
  1569. }
  1570. }
  1571. // 准备请求参数
  1572. const requestData = {
  1573. application_id: uni.getStorageSync('appId'),
  1574. question_id: questionId,
  1575. video_url: videoUrl,
  1576. tenant_id: uni.getStorageSync('tenant_id') || '1'
  1577. };
  1578. // 发送请求到面试接口
  1579. uni.request({
  1580. url: `${apiBaseUrl}/api/job/upload_video`,
  1581. method: 'POST',
  1582. data: requestData,
  1583. header: {
  1584. 'content-type': 'application/x-www-form-urlencoded'
  1585. },
  1586. success: (res) => {
  1587. console.log('面试接口提交成功:', res);
  1588. if (res.data.code === 0 || res.data.code === 2000) {
  1589. // 提交成功
  1590. if (task) {
  1591. // 从队列中移除当前任务
  1592. this.uploadQueue.shift();
  1593. // 显示简短的成功提示
  1594. uni.showToast({
  1595. title: '视频提交成功',
  1596. icon: 'success',
  1597. duration: 1500
  1598. });
  1599. // 继续处理队列中的下一个任务
  1600. this.processUploadQueue();
  1601. } else {
  1602. // 兼容旧代码的处理逻辑
  1603. uni.showToast({
  1604. title: '回答已提交',
  1605. icon: 'success'
  1606. });
  1607. // 保存最后上传的视频URL
  1608. this.lastUploadedVideoUrl = videoUrl;
  1609. // 隐藏重试按钮(如果之前显示了)
  1610. this.showRetryButton = false;
  1611. this.lastVideoToRetry = null;
  1612. }
  1613. } else {
  1614. // 提交失败
  1615. if (task) {
  1616. this.handleSubmitFailure(task, res.data.msg || '提交失败');
  1617. } else {
  1618. // 兼容旧代码的处理逻辑
  1619. uni.showToast({
  1620. title: res.data.msg || '提交失败,请重试',
  1621. icon: 'none'
  1622. });
  1623. // 保存失败的视频URL,用于重试
  1624. this.lastVideoToRetry = videoUrl;
  1625. // 显示重试按钮
  1626. this.showRetryButton = true;
  1627. }
  1628. }
  1629. },
  1630. fail: (err) => {
  1631. console.error('面试接口提交失败:', err);
  1632. if (task) {
  1633. this.handleSubmitFailure(task, err.errMsg || '网络错误');
  1634. } else {
  1635. // 兼容旧代码的处理逻辑
  1636. uni.hideLoading();
  1637. uni.showToast({
  1638. title: '网络错误,请重试',
  1639. icon: 'none'
  1640. });
  1641. // 保存失败的视频URL,用于重试
  1642. this.lastVideoToRetry = videoUrl;
  1643. // 显示重试按钮
  1644. this.showRetryButton = true;
  1645. }
  1646. }
  1647. });
  1648. },
  1649. // 添加新方法:处理提交失败
  1650. handleSubmitFailure(task, errorMsg) {
  1651. console.error('提交失败:', errorMsg);
  1652. // 更新任务状态
  1653. this.uploadStatus[task.id] = 'failed';
  1654. this.updateUploadStatusText();
  1655. // 检查是否还有重试机会
  1656. if (task.attempts < task.maxAttempts) {
  1657. console.log(`将在5秒后重试提交,当前尝试次数: ${task.attempts}/${task.maxAttempts}`);
  1658. // 5秒后重试
  1659. setTimeout(() => {
  1660. // 重新提交
  1661. this.submitVideoToInterview(task.videoUrl, task);
  1662. }, 5000);
  1663. } else {
  1664. // 超过最大重试次数,移除任务并继续处理队列
  1665. console.log('超过最大重试次数,放弃提交');
  1666. // 显示错误提示
  1667. uni.showToast({
  1668. title: '视频提交失败,请稍后重试',
  1669. icon: 'none',
  1670. duration: 2000
  1671. });
  1672. // 从队列中移除当前任务
  1673. this.uploadQueue.shift();
  1674. // 继续处理队列中的下一个任务
  1675. this.processUploadQueue();
  1676. }
  1677. },
  1678. // 添加新方法:更新上传状态文本
  1679. updateUploadStatusText() {
  1680. if (this.uploadQueue.length === 0) {
  1681. this.uploadStatusText = '';
  1682. return;
  1683. }
  1684. const currentTask = this.uploadQueue[0];
  1685. const progress = this.uploadProgress[currentTask.id] || 0;
  1686. const status = this.uploadStatus[currentTask.id] || 'pending';
  1687. let statusText = '';
  1688. switch (status) {
  1689. case 'pending':
  1690. statusText = '等待上传';
  1691. break;
  1692. case 'uploading':
  1693. statusText = `上传中 ${progress}%`;
  1694. break;
  1695. case 'success':
  1696. statusText = '上传成功,提交中...';
  1697. break;
  1698. case 'failed':
  1699. statusText = `上传失败,${currentTask.attempts < currentTask.maxAttempts ? '即将重试' : '已放弃'}`;
  1700. break;
  1701. }
  1702. this.uploadStatusText = `问题${currentTask.questionId - 9}:${statusText}`;
  1703. // 如果队列中有多个任务,显示总数
  1704. if (this.uploadQueue.length > 1) {
  1705. this.uploadStatusText += ` (${this.uploadQueue.length}个视频待处理)`;
  1706. }
  1707. },
  1708. // 修改 proceedToNextQuestion 方法,不再等待上传完成
  1709. proceedToNextQuestion() {
  1710. // 检查是否完成了第五个视频问题(索引为4)
  1711. if (this.currentVideoIndex === 4) {
  1712. // 完成第五个问题后,跳转到相机页面
  1713. uni.navigateTo({
  1714. url: '/pages/camera/camera'
  1715. });
  1716. return;
  1717. }
  1718. // 切换到下一个视频
  1719. this.currentVideoIndex++;
  1720. if (this.currentVideoIndex < this.videoList.length) {
  1721. // 还有下一段视频,播放它
  1722. this.videoUrl = this.videoList[this.currentVideoIndex];
  1723. this.videoPlaying = true;
  1724. // 重置当前字幕
  1725. this.currentSubtitle = '';
  1726. // 使用 nextTick 确保 DOM 更新后再播放视频
  1727. this.$nextTick(() => {
  1728. const videoContext = uni.createVideoContext('myVideo', this);
  1729. if (videoContext) {
  1730. videoContext.play();
  1731. }
  1732. });
  1733. } else {
  1734. // 所有视频都播放完毕,可以进行下一步操作
  1735. uni.showToast({
  1736. title: '面试完成',
  1737. icon: 'success',
  1738. duration: 2000
  1739. });
  1740. // 可以在这里添加面试完成后的逻辑,比如跳转到下一个页面
  1741. setTimeout(() => {
  1742. uni.navigateTo({
  1743. url: '/pages/interview-result/interview-result'
  1744. });
  1745. }, 2000);
  1746. }
  1747. },
  1748. // 修改 handleAnswerButtonClick 方法
  1749. handleAnswerButtonClick() {
  1750. // 隐藏答题按钮
  1751. this.showAnswerButton = false;
  1752. // 直接进入下一个问题
  1753. this.proceedToNextQuestion();
  1754. },
  1755. // 处理相机错误
  1756. handleCameraError(e) {
  1757. console.error('相机错误:', e);
  1758. // 获取平台信息
  1759. const systemInfo = uni.getSystemInfoSync();
  1760. const isIOS = systemInfo.platform === 'ios';
  1761. if (isIOS) {
  1762. console.log('iOS相机错误,尝试重新初始化');
  1763. // 显示提示
  1764. uni.showToast({
  1765. title: '相机初始化中...',
  1766. icon: 'loading',
  1767. duration: 2000
  1768. });
  1769. // 重置相机
  1770. this.resetCamera();
  1771. // 如果正在录制,停止录制
  1772. if (this.isRecording) {
  1773. this.isRecording = false;
  1774. this.showStopRecordingButton = false;
  1775. // 提供替代选项
  1776. setTimeout(() => {
  1777. this.useAlternativeRecordingMethod();
  1778. }, 1000);
  1779. }
  1780. } else {
  1781. // 显示错误提示
  1782. uni.showToast({
  1783. title: '相机初始化失败,请检查权限设置',
  1784. icon: 'none'
  1785. });
  1786. // 尝试备用选项
  1787. this.tryFallbackOptions();
  1788. }
  1789. },
  1790. // 添加新方法:尝试备用选项
  1791. tryFallbackOptions() {
  1792. // 检查环境
  1793. const systemInfo = uni.getSystemInfoSync();
  1794. // 在小程序环境中使用小程序API
  1795. if (systemInfo.uniPlatform === 'mp-weixin' || systemInfo.uniPlatform === 'mp-alipay') {
  1796. this.useMiniProgramCamera();
  1797. }
  1798. // 在H5环境中显示静态图像
  1799. else {
  1800. this.showStaticCameraPlaceholder();
  1801. }
  1802. },
  1803. // 添加新方法:使用小程序相机API
  1804. useMiniProgramCamera() {
  1805. console.log('尝试使用小程序相机组件');
  1806. // 这里需要在模板中添加小程序相机组件
  1807. // 并设置一个标志来控制显示
  1808. this.useMiniProgramCameraComponent = true;
  1809. },
  1810. // 添加新方法:显示静态图像
  1811. showStaticCameraPlaceholder() {
  1812. console.log('显示静态摄像头占位图');
  1813. // 创建一个图像元素
  1814. const img = document.createElement('img');
  1815. img.src = '/static/images/camera-placeholder.png'; // 确保有这个图片资源
  1816. img.className = 'static-camera-image';
  1817. img.style.width = '100%';
  1818. img.style.height = '100%';
  1819. img.style.objectFit = 'cover';
  1820. // 获取容器并添加图像
  1821. const container = this.$refs.userCameraVideo.parentNode;
  1822. container.appendChild(img);
  1823. },
  1824. // 处理视频时间更新事件
  1825. handleTimeUpdate(e) {
  1826. // 获取当前视频播放时间
  1827. const currentTime = e.target.currentTime;
  1828. // 如果正在录制,更新录制时间显示
  1829. if (this.isRecording && this.recordingTimerCount) {
  1830. this.recordingTimeDisplay = this.formatTime(this.recordingTimerCount);
  1831. }
  1832. // 根据当前播放的视频索引选择对应的字幕数组
  1833. let currentSubtitles;
  1834. if (this.currentVideoIndex === 0) {
  1835. currentSubtitles = this.subtitles;
  1836. } else if (this.currentVideoIndex === 1) {
  1837. currentSubtitles = this.secondVideoSubtitles;
  1838. }else if (this.currentVideoIndex === 2) {
  1839. currentSubtitles = this.thirdVideoSubtitles;
  1840. }else if (this.currentVideoIndex === 3) {
  1841. currentSubtitles = this.fourthVideoSubtitles;
  1842. }else if (this.currentVideoIndex === 4) {
  1843. currentSubtitles = this.fifthVideoSubtitles;
  1844. }else if (this.currentVideoIndex === 5) {
  1845. currentSubtitles = this.sixthVideoSubtitles;
  1846. }else {
  1847. // 如果有更多视频,可以继续添加条件
  1848. currentSubtitles = [];
  1849. }
  1850. // 查找当前时间应该显示的字幕
  1851. const subtitle = currentSubtitles.find(
  1852. sub => currentTime >= sub.startTime && currentTime < sub.endTime
  1853. );
  1854. // 更新当前字幕
  1855. this.currentSubtitle = subtitle ? subtitle.text : '';
  1856. },
  1857. // Add a new method to handle the "Start Recording" button click
  1858. handleStartRecordingClick() {
  1859. // 隐藏"开始回答"按钮
  1860. this.showStartRecordingButton = false;
  1861. // 开始录制
  1862. this.startRecordingAnswer();
  1863. },
  1864. // 修改 checkAudioPermission 方法,确保在录制前获取音频权限
  1865. checkAudioPermission() {
  1866. // 在小程序环境中
  1867. const systemInfo = uni.getSystemInfoSync();
  1868. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith('mp-');
  1869. if (isMiniProgram) {
  1870. // 小程序环境下的权限请求
  1871. uni.getSetting({
  1872. success: (res) => {
  1873. if (!res.authSetting['scope.record']) {
  1874. uni.authorize({
  1875. scope: 'scope.record',
  1876. success: () => {
  1877. console.log('录音权限已获取');
  1878. },
  1879. fail: (err) => {
  1880. console.error('录音权限获取失败:', err);
  1881. this.showPermissionDialog('录音');
  1882. }
  1883. });
  1884. }
  1885. if (!res.authSetting['scope.camera']) {
  1886. uni.authorize({
  1887. scope: 'scope.camera',
  1888. success: () => {
  1889. console.log('相机权限已获取');
  1890. },
  1891. fail: (err) => {
  1892. console.error('相机权限获取失败:', err);
  1893. this.showPermissionDialog('相机');
  1894. }
  1895. });
  1896. }
  1897. }
  1898. });
  1899. } else {
  1900. // 浏览器环境下的权限请求
  1901. // ... 保持原有代码不变
  1902. }
  1903. },
  1904. // 添加新方法:测试音频输入
  1905. testAudioInput() {
  1906. if (!this.cameraStream) {
  1907. console.warn('没有可用的媒体流,无法测试音频');
  1908. return;
  1909. }
  1910. const audioTracks = this.cameraStream.getAudioTracks();
  1911. if (audioTracks.length === 0) {
  1912. console.warn('没有检测到音频轨道,尝试重新获取');
  1913. this.tryGetAudioOnly();
  1914. return;
  1915. }
  1916. console.log('音频轨道信息:', audioTracks[0].getSettings());
  1917. // 创建音频上下文和分析器
  1918. try {
  1919. const AudioContext = window.AudioContext || window.webkitAudioContext;
  1920. if (!AudioContext) {
  1921. console.warn('浏览器不支持AudioContext');
  1922. return;
  1923. }
  1924. const audioContext = new AudioContext();
  1925. const analyser = audioContext.createAnalyser();
  1926. const microphone = audioContext.createMediaStreamSource(this.cameraStream);
  1927. microphone.connect(analyser);
  1928. // 设置分析器
  1929. analyser.fftSize = 256;
  1930. const bufferLength = analyser.frequencyBinCount;
  1931. const dataArray = new Uint8Array(bufferLength);
  1932. // 检测音频输入
  1933. let silenceCounter = 0;
  1934. const checkAudio = () => {
  1935. if (this.isRecording) return; // 如果正在录制,停止检测
  1936. analyser.getByteFrequencyData(dataArray);
  1937. // 计算平均音量
  1938. let sum = 0;
  1939. for (let i = 0; i < bufferLength; i++) {
  1940. sum += dataArray[i];
  1941. }
  1942. const average = sum / bufferLength;
  1943. if (average > 10) {
  1944. console.log('检测到音频输入,音量:', average);
  1945. silenceCounter = 0;
  1946. } else {
  1947. silenceCounter++;
  1948. if (silenceCounter > 10) {
  1949. console.warn('持续检测不到音频输入,可能麦克风未正常工作');
  1950. silenceCounter = 0;
  1951. }
  1952. }
  1953. // 继续检测
  1954. requestAnimationFrame(checkAudio);
  1955. };
  1956. // 开始检测
  1957. checkAudio();
  1958. } catch (e) {
  1959. console.error('音频测试失败:', e);
  1960. }
  1961. },
  1962. // 添加新方法:尝试单独获取音频
  1963. tryGetAudioOnly() {
  1964. navigator.mediaDevices.getUserMedia({ audio: true })
  1965. .then(audioStream => {
  1966. // 如果已有视频流,合并音频和视频轨道
  1967. if (this.cameraStream) {
  1968. const videoTrack = this.cameraStream.getVideoTracks()[0];
  1969. const audioTrack = audioStream.getAudioTracks()[0];
  1970. // 创建新的媒体流,包含视频和音频轨道
  1971. const combinedStream = new MediaStream();
  1972. if (videoTrack) combinedStream.addTrack(videoTrack);
  1973. if (audioTrack) combinedStream.addTrack(audioTrack);
  1974. // 更新摄像头流
  1975. this.cameraStream = combinedStream;
  1976. // 更新视频元素的源
  1977. const videoElement = this.$refs.userCameraVideo;
  1978. if (videoElement) {
  1979. videoElement.srcObject = combinedStream;
  1980. videoElement.muted = true; // 避免回声,但仍然录制声音
  1981. }
  1982. console.log('成功合并音频和视频轨道');
  1983. } else {
  1984. console.warn('没有视频流可合并');
  1985. }
  1986. })
  1987. .catch(err => {
  1988. console.error('单独获取音频失败:', err);
  1989. });
  1990. },
  1991. // 添加新方法:显示权限对话框
  1992. showPermissionDialog(permissionType) {
  1993. uni.showModal({
  1994. title: '需要权限',
  1995. content: `请允许使用${permissionType}权限,否则可能影响面试功能`,
  1996. confirmText: '去设置',
  1997. success: (res) => {
  1998. if (res.confirm) {
  1999. uni.openSetting({
  2000. success: (settingRes) => {
  2001. console.log('设置页面打开成功', settingRes);
  2002. }
  2003. });
  2004. }
  2005. }
  2006. });
  2007. },
  2008. // 添加重试上传方法
  2009. retryVideoUpload() {
  2010. if (this.lastVideoToRetry) {
  2011. // 隐藏重试按钮
  2012. this.showRetryButton = false;
  2013. // 显示加载提示
  2014. uni.showLoading({
  2015. title: '正在重新提交...',
  2016. mask: true
  2017. });
  2018. // 重新提交视频
  2019. this.submitVideoToInterview(this.lastVideoToRetry);
  2020. } else {
  2021. uni.showToast({
  2022. title: '没有可重试的视频',
  2023. icon: 'none'
  2024. });
  2025. }
  2026. },
  2027. // 添加一个新方法用于压缩视频
  2028. async compressVideo(videoBlob) {
  2029. // 如果视频大小小于某个阈值,直接返回原视频
  2030. if (videoBlob.size < 5 * 1024 * 1024) { // 小于5MB
  2031. return videoBlob;
  2032. }
  2033. console.log('开始压缩视频,原始大小:', videoBlob.size);
  2034. // 创建一个视频元素来加载视频
  2035. const videoElement = document.createElement('video');
  2036. videoElement.muted = true;
  2037. videoElement.autoplay = false;
  2038. // 创建一个canvas元素用于绘制视频帧
  2039. const canvas = document.createElement('canvas');
  2040. const ctx = canvas.getContext('2d');
  2041. // 设置视频源
  2042. videoElement.src = URL.createObjectURL(videoBlob);
  2043. return new Promise((resolve) => {
  2044. videoElement.onloadedmetadata = () => {
  2045. // 设置canvas尺寸为视频的一半
  2046. const width = Math.floor(videoElement.videoWidth / 2);
  2047. const height = Math.floor(videoElement.videoHeight / 2);
  2048. canvas.width = width;
  2049. canvas.height = height;
  2050. // 创建MediaRecorder来录制canvas
  2051. const stream = canvas.captureStream(15); // 15fps
  2052. // 如果原视频有音轨,添加到新流中
  2053. if (videoElement.captureStream) {
  2054. const originalStream = videoElement.captureStream();
  2055. const audioTracks = originalStream.getAudioTracks();
  2056. if (audioTracks.length > 0) {
  2057. stream.addTrack(audioTracks[0]);
  2058. }
  2059. }
  2060. // 设置较低的比特率
  2061. const options = {
  2062. mimeType: 'video/webm;codecs=vp8,opus',
  2063. audioBitsPerSecond: 64000,
  2064. videoBitsPerSecond: 800000 // 800kbps
  2065. };
  2066. const mediaRecorder = new MediaRecorder(stream, options);
  2067. const chunks = [];
  2068. mediaRecorder.ondataavailable = (e) => {
  2069. if (e.data.size > 0) {
  2070. chunks.push(e.data);
  2071. }
  2072. };
  2073. mediaRecorder.onstop = () => {
  2074. const compressedBlob = new Blob(chunks, { type: 'video/webm' });
  2075. console.log('视频压缩完成,压缩后大小:', compressedBlob.size);
  2076. resolve(compressedBlob);
  2077. };
  2078. // 开始播放视频并录制
  2079. videoElement.onplay = () => {
  2080. mediaRecorder.start(100);
  2081. // 绘制视频帧到canvas
  2082. const drawFrame = () => {
  2083. if (videoElement.paused || videoElement.ended) {
  2084. mediaRecorder.stop();
  2085. return;
  2086. }
  2087. ctx.drawImage(videoElement, 0, 0, width, height);
  2088. requestAnimationFrame(drawFrame);
  2089. };
  2090. drawFrame();
  2091. };
  2092. videoElement.play();
  2093. };
  2094. });
  2095. },
  2096. // 修改 checkIOSCameraRecordPermission 方法
  2097. checkIOSCameraRecordPermission() {
  2098. const systemInfo = uni.getSystemInfoSync();
  2099. if (systemInfo.platform !== 'ios') return;
  2100. // 在iOS上,需要同时请求相机和录音权限
  2101. uni.getSetting({
  2102. success: (res) => {
  2103. // 检查相机权限
  2104. if (!res.authSetting['scope.camera']) {
  2105. uni.authorize({
  2106. scope: 'scope.camera',
  2107. success: () => {
  2108. console.log('iOS相机权限已获取');
  2109. },
  2110. fail: (err) => {
  2111. console.error('iOS相机权限获取失败:', err);
  2112. this.showPermissionDialog('相机');
  2113. }
  2114. });
  2115. }
  2116. // 检查录音权限
  2117. if (!res.authSetting['scope.record']) {
  2118. uni.authorize({
  2119. scope: 'scope.record',
  2120. success: () => {
  2121. console.log('iOS录音权限已获取');
  2122. },
  2123. fail: (err) => {
  2124. console.error('iOS录音权限获取失败:', err);
  2125. this.showPermissionDialog('录音');
  2126. }
  2127. });
  2128. }
  2129. }
  2130. });
  2131. },
  2132. // 添加新方法:检查并修复渲染问题
  2133. checkAndFixRenderingIssues() {
  2134. // 检查全局对象,防止渲染错误
  2135. try {
  2136. // 检查是否有全局变量u
  2137. if (typeof u !== 'undefined' && u) {
  2138. // 检查currentQuestion属性
  2139. if (!u.currentQuestion) {
  2140. console.log('修复: 创建缺失的currentQuestion对象');
  2141. u.currentQuestion = {};
  2142. }
  2143. // 确保isImportant属性存在
  2144. if (u.currentQuestion && typeof u.currentQuestion.isImportant === 'undefined') {
  2145. console.log('修复: 设置缺失的isImportant属性');
  2146. u.currentQuestion.isImportant = false;
  2147. }
  2148. }
  2149. } catch (e) {
  2150. console.log('防御性检查异常:', e);
  2151. }
  2152. },
  2153. // 添加格式化时间的辅助方法
  2154. formatTime(seconds) {
  2155. const minutes = Math.floor(seconds / 60);
  2156. const remainingSeconds = seconds % 60;
  2157. return `${minutes.toString().padStart(2, '0')}:${remainingSeconds.toString().padStart(2, '0')}`;
  2158. },
  2159. }
  2160. }
  2161. </script>
  2162. <style scoped>
  2163. .identity-verify-container {
  2164. padding: 0;
  2165. max-width: 100%;
  2166. margin: 0 auto;
  2167. height: 100vh;
  2168. display: flex;
  2169. flex-direction: column;
  2170. background-color: #f5f5f5;
  2171. }
  2172. .digital-human-container {
  2173. position: relative;
  2174. width: 100%;
  2175. height: 100vh;
  2176. overflow: hidden;
  2177. background-color: #f0f0f0;
  2178. }
  2179. .digital-human-video {
  2180. width: 100%;
  2181. height: 100%;
  2182. display: flex;
  2183. justify-content: center;
  2184. align-items: center;
  2185. }
  2186. /* 用户摄像头容器样式 */
  2187. .user-camera-container {
  2188. position: absolute;
  2189. top: 20px;
  2190. right: 20px;
  2191. width: 100px;
  2192. height: 150px;
  2193. border-radius: 8px;
  2194. overflow: hidden;
  2195. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  2196. z-index: 20;
  2197. border: 1px solid #fff;
  2198. }
  2199. /* 用户摄像头视频样式 */
  2200. .user-camera-video {
  2201. width: 100%;
  2202. height: 100%;
  2203. object-fit: cover;
  2204. background-color: #333;
  2205. }
  2206. .video-player {
  2207. width: 100%;
  2208. height: 100%;
  2209. object-fit: cover;
  2210. outline: none; /* 移除视频获得焦点时的轮廓 */
  2211. -webkit-tap-highlight-color: transparent; /* 移除移动设备上的点击高亮 */
  2212. }
  2213. /* 隐藏视频控制条 */
  2214. video::-webkit-media-controls {
  2215. display: none !important;
  2216. }
  2217. video::-webkit-media-controls-enclosure {
  2218. display: none !important;
  2219. }
  2220. video::-webkit-media-controls-panel {
  2221. display: none !important;
  2222. }
  2223. video::-webkit-media-controls-play-button {
  2224. display: none !important;
  2225. }
  2226. video::-webkit-media-controls-timeline {
  2227. display: none !important;
  2228. }
  2229. video::-webkit-media-controls-current-time-display {
  2230. display: none !important;
  2231. }
  2232. video::-webkit-media-controls-time-remaining-display {
  2233. display: none !important;
  2234. }
  2235. video::-webkit-media-controls-mute-button {
  2236. display: none !important;
  2237. }
  2238. video::-webkit-media-controls-volume-slider {
  2239. display: none !important;
  2240. }
  2241. video::-webkit-media-controls-fullscreen-button {
  2242. display: none !important;
  2243. }
  2244. .subtitle-overlay {
  2245. position: absolute;
  2246. bottom: 50px;
  2247. left: 0;
  2248. width: 100%;
  2249. padding: 15px;
  2250. background-color: rgba(0, 0, 0, 0.7);
  2251. color: white;
  2252. text-align: center;
  2253. font-size: 16px;
  2254. line-height: 1.5;
  2255. z-index: 10;
  2256. border-radius: 4px;
  2257. max-width: 90%;
  2258. margin: 0 auto;
  2259. left: 5%;
  2260. right: 5%;
  2261. }
  2262. .control-panel {
  2263. padding: 15px;
  2264. display: flex;
  2265. justify-content: center;
  2266. }
  2267. .control-button {
  2268. padding: 10px 20px;
  2269. background-color: #4CAF50;
  2270. color: white;
  2271. border: none;
  2272. border-radius: 4px;
  2273. cursor: pointer;
  2274. }
  2275. .loading {
  2276. text-align: center;
  2277. margin: 20px 0;
  2278. font-size: 16px;
  2279. }
  2280. .response-container {
  2281. margin-top: 20px;
  2282. padding: 0 20px;
  2283. display: none; /* 默认隐藏调试信息 */
  2284. }
  2285. /* 当showDebugInfo为true时显示 */
  2286. .showDebugInfo .response-container {
  2287. display: block;
  2288. }
  2289. .response-item {
  2290. padding: 10px;
  2291. border: 1px solid #eee;
  2292. border-radius: 4px;
  2293. margin-bottom: 10px;
  2294. background-color: #f9f9f9;
  2295. }
  2296. .response-content {
  2297. display: flex;
  2298. flex-direction: column;
  2299. }
  2300. .answer-button-container {
  2301. position: absolute;
  2302. top: 75%;
  2303. left: 50%;
  2304. transform: translate(-50%, -50%);
  2305. z-index: 20;
  2306. }
  2307. .answer-button {
  2308. width: 120px;
  2309. height: 120px;
  2310. border-radius: 50%;
  2311. background-color: #6c5ce7; /* 绿色背景,与图片中的颜色类似 */
  2312. color: white;
  2313. font-size: 18px;
  2314. border: none;
  2315. box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  2316. display: flex;
  2317. justify-content: center;
  2318. align-items: center;
  2319. cursor: pointer;
  2320. animation: pulse 2s infinite;
  2321. }
  2322. @keyframes pulse {
  2323. 0% {
  2324. transform: scale(1);
  2325. box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  2326. }
  2327. 50% {
  2328. transform: scale(1.05);
  2329. box-shadow: 0 8px 15px rgba(0, 0, 0, 0.4);
  2330. }
  2331. 100% {
  2332. transform: scale(1);
  2333. box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  2334. }
  2335. }
  2336. .stop-recording-button-container {
  2337. position: absolute;
  2338. top: 75%;
  2339. left: 50%;
  2340. transform: translate(-50%, -50%);
  2341. z-index: 20;
  2342. }
  2343. .stop-recording-button {
  2344. width: 120px;
  2345. height: 120px;
  2346. border-radius: 50%;
  2347. background-color: #e74c3c; /* 红色背景 */
  2348. color: white;
  2349. font-size: 18px;
  2350. border: none;
  2351. box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  2352. display: flex;
  2353. justify-content: center;
  2354. align-items: center;
  2355. cursor: pointer;
  2356. animation: pulse 2s infinite;
  2357. }
  2358. @keyframes pulse {
  2359. 0% {
  2360. transform: scale(1);
  2361. box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  2362. }
  2363. 50% {
  2364. transform: scale(1.05);
  2365. box-shadow: 0 8px 15px rgba(0, 0, 0, 0.4);
  2366. }
  2367. 100% {
  2368. transform: scale(1);
  2369. box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  2370. }
  2371. }
  2372. /* 录制中的指示器 */
  2373. .recording-indicator {
  2374. position: absolute;
  2375. top: 20px;
  2376. left: 20px;
  2377. display: flex;
  2378. align-items: center;
  2379. background-color: rgba(0, 0, 0, 0.6);
  2380. padding: 5px 10px;
  2381. border-radius: 15px;
  2382. z-index: 20;
  2383. }
  2384. .recording-dot {
  2385. width: 12px;
  2386. height: 12px;
  2387. background-color: #e74c3c;
  2388. border-radius: 50%;
  2389. margin-right: 8px;
  2390. animation: blink 1s infinite;
  2391. }
  2392. .recording-text {
  2393. color: white;
  2394. font-size: 14px;
  2395. }
  2396. @keyframes blink {
  2397. 0% { opacity: 1; }
  2398. 50% { opacity: 0.3; }
  2399. 100% { opacity: 1; }
  2400. }
  2401. .start-recording-button-container {
  2402. position: absolute;
  2403. top: 75%;
  2404. left: 50%;
  2405. transform: translate(-50%, -50%);
  2406. z-index: 20;
  2407. }
  2408. .start-recording-button {
  2409. width: 120px;
  2410. height: 120px;
  2411. border-radius: 50%;
  2412. background-color: #6c5ce7; /* 与开始面试按钮颜色保持一致 */
  2413. color: white;
  2414. font-size: 18px;
  2415. border: none;
  2416. box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  2417. display: flex;
  2418. justify-content: center;
  2419. align-items: center;
  2420. cursor: pointer;
  2421. animation: pulse 2s infinite; /* 使用相同的动画 */
  2422. }
  2423. /* 可以删除pulse-green动画,直接使用与开始面试按钮相同的pulse动画 */
  2424. .retry-button-container {
  2425. position: absolute;
  2426. bottom: 50px;
  2427. left: 50%;
  2428. transform: translateX(-50%);
  2429. z-index: 20;
  2430. }
  2431. .retry-button {
  2432. padding: 10px 20px;
  2433. background-color: #3498db; /* 蓝色背景 */
  2434. color: white;
  2435. font-size: 16px;
  2436. border: none;
  2437. border-radius: 4px;
  2438. box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  2439. cursor: pointer;
  2440. }
  2441. .retry-button:hover {
  2442. background-color: #2980b9;
  2443. }
  2444. /* 录制时长显示 */
  2445. .recording-timer {
  2446. position: absolute;
  2447. top: 20px;
  2448. left: 130px; /* 放在录制指示器旁边 */
  2449. background-color: rgba(0, 0, 0, 0.6);
  2450. padding: 5px 10px;
  2451. border-radius: 15px;
  2452. z-index: 20;
  2453. display: flex;
  2454. flex-direction: column;
  2455. }
  2456. .timer-text {
  2457. color: white;
  2458. font-size: 14px;
  2459. font-family: monospace; /* 使用等宽字体,使时间显示更稳定 */
  2460. }
  2461. .remaining-time {
  2462. color: white;
  2463. font-size: 12px;
  2464. margin-top: 2px;
  2465. }
  2466. .remaining-time.warning {
  2467. color: #ff6b6b; /* 剩余时间少时显示红色 */
  2468. animation: blink 1s infinite; /* 使用闪烁动画提醒用户 */
  2469. }
  2470. /* 添加上传状态指示器 */
  2471. .upload-status-indicator {
  2472. position: absolute;
  2473. top: 20px;
  2474. left: 130px; /* 放在录制指示器旁边 */
  2475. background-color: rgba(0, 0, 0, 0.6);
  2476. padding: 5px 10px;
  2477. border-radius: 15px;
  2478. z-index: 20;
  2479. }
  2480. .upload-status-content {
  2481. display: flex;
  2482. align-items: center;
  2483. }
  2484. .upload-status-icon {
  2485. width: 12px;
  2486. height: 12px;
  2487. border-radius: 50%;
  2488. margin-right: 8px;
  2489. }
  2490. .upload-status-text {
  2491. color: white;
  2492. font-size: 14px;
  2493. }
  2494. .uploading {
  2495. background-color: #e74c3c;
  2496. }
  2497. </style>