identity-verify.vue 135 KB

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