identity-verify.vue 86 KB

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