identity-verify.vue 133 KB

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