identity-verify.vue 111 KB

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