identity-verify.vue 88 KB

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