interview-question.vue 166 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334
  1. <template>
  2. <div class="identity-verify-container">
  3. <div class="digital-human-container">
  4. <!-- AI数字人视频/图像显示区域 -->
  5. <div class="digital-human-video">
  6. <!-- 添加GIF图片显示区域 -->
  7. <!-- <img v-if="showGif && gifUrl" :src="gifUrl" class="gif-player" alt="面试官GIF" /> -->
  8. <!-- <video
  9. v-if="showGif && gifUrl"
  10. :src="gifUrl"
  11. id="mpVideo"
  12. autoplay
  13. class="video-player"
  14. :controls="false"
  15. loop
  16. muted
  17. object-fit="contain"
  18. ></video> v-if="!showGif" -->
  19. <!-- 视频播放区域,当showGif为false时显示 -->
  20. <video
  21. :src="videoUrl"
  22. id="myVideo"
  23. ref="videoPlayer"
  24. autoplay
  25. playsinline
  26. disablePictureInPicture
  27. controlsList="nodownload nofullscreen noremoteplayback"
  28. class="video-player"
  29. :controls="false"
  30. @error="handleVideoError"
  31. @ended="handleVideoEnded"
  32. @timeupdate="handleTimeUpdate">
  33. </video>
  34. <!-- 添加透明蒙层 -->
  35. <div class="video-overlay"></div>
  36. <div class="answer-button-container" v-if="showAnswerButton">
  37. <button class="answer-button" @click="handleAnswerButtonClick">
  38. 开始提问
  39. </button>
  40. </div>
  41. <!-- 添加字幕覆盖层 :data-time="formatTime(recordingTimerCount) || '03:30'"-->
  42. <div class="subtitle-overlay" v-if="currentSubtitle" >
  43. {{ currentSubtitle }}
  44. <!-- <button v-if="showNextButton" class="next-button" @click="handleNextButtonClick">我已阅读完成,继续</button> -->
  45. </div>
  46. <!-- 添加答题按钮 -->
  47. </div>
  48. <!-- 用户摄像头视频显示区域 -->
  49. <div class="user-camera-container">
  50. <!-- 在小程序环境中使用camera组件 -->
  51. <camera v-if="useMiniProgramCameraComponent"
  52. device-position="front"
  53. flash="off"
  54. class="user-camera-video"
  55. @error="handleCameraError"
  56. :record-audio="true"
  57. frame-size="small"
  58. resolution="low"
  59. :disable-zoom="true"
  60. :enable-camera="true"
  61. :enable-record="true"
  62. mode="normal">
  63. </camera>
  64. <!-- 在H5/App环境中使用video元素 -->
  65. <video v-else
  66. id="userCamera"
  67. ref="userCameraVideo"
  68. autoplay
  69. playsinline
  70. muted
  71. class="user-camera-video"
  72. :controls="false">
  73. </video>
  74. </div>
  75. <!-- 字幕/文本覆盖区域 -->
  76. <!-- <div class="subtitle-overlay" v-if="assistantResponse">
  77. {{ assistantResponse }}
  78. </div> -->
  79. </div>
  80. <!-- 加载状态 -->
  81. <div v-if="loading" class="loading">加载中...</div>
  82. <!-- 控制面板(可选,可以隐藏) -->
  83. <!-- 响应数据(可以设为隐藏,仅用于调试) -->
  84. <div v-if="showDebugInfo" class="response-container">
  85. <div v-if="assistantResponse" class="response-item">
  86. <div class="response-content">
  87. <span>助手回复: {{ assistantResponse }}</span>
  88. </div>
  89. </div>
  90. <div v-if="audioTranscript" class="response-item">
  91. <div class="response-content">
  92. <span>音频转写: {{ audioTranscript }}</span>
  93. </div>
  94. </div>
  95. <div v-for="(item, index) in processedResponses" :key="index" class="response-item">
  96. <div class="response-content">
  97. <span v-if="item.role">角色: {{ item.role }}</span>
  98. <span v-if="item.transcript">文本: {{ item.transcript }}</span>
  99. </div>
  100. </div>
  101. </div>
  102. <!-- 添加停止录制按钮 -->
  103. <div class="stop-recording-button-container" v-if="showStopRecordingButton">
  104. <button class="stop-recording-button" @click="stopRecordingAnswer">
  105. 完成提问
  106. </button>
  107. </div>
  108. <!-- 添加录制指示器 -->
  109. <div class="recording-indicator" v-if="isRecording">
  110. <div class="recording-dot"></div>
  111. <span class="recording-text">正在录制...</span>
  112. <span class="timer-text">{{ recordingTimeDisplay || '00:00 / 05:00' }}</span>
  113. </div>
  114. <!-- 添加开始回答按钮 -->
  115. <div class="start-recording-button-container" v-if="showStartRecordingButton">
  116. <button class="start-recording-button" @click="handleStartRecordingClick">
  117. 开始提问
  118. </button>
  119. </div>
  120. <!-- 添加重试上传按钮 -->
  121. <div class="retry-button-container" v-if="showRetryButton">
  122. <button class="retry-button" @click="retryVideoUpload">
  123. 重新上传
  124. </button>
  125. </div>
  126. <!-- 在模板部分添加录制时长显示 -->
  127. <!-- <div class="recording-timer" v-if="isRecording">
  128. <span class="timer-text">{{ recordingTimeDisplay || '00:00' }}</span>
  129. </div> -->
  130. <!-- 添加上传状态指示器 -->
  131. <!-- <div class="upload-status-indicator" v-if="showUploadStatus && uploadStatusText">
  132. <div class="upload-status-content">
  133. <div class="upload-status-icon" :class="{'uploading': isUploading}"></div>
  134. <span class="upload-status-text">{{ uploadStatusText }}</span>
  135. </div>
  136. </div> -->
  137. <!-- 修改录制时长显示 -->
  138. <!-- <div class="recording-timer" v-if="isRecording">
  139. <span class="timer-text">{{ recordingTimeDisplay || '00:00 / 05:00' }}</span>
  140. <span class="remaining-time" :class="{'warning': remainingTime <= 10}">
  141. 剩余: {{ formatTime(remainingTime) }}
  142. </span>
  143. </div> -->
  144. <!-- 在模板部分添加倒计时蒙层 -->
  145. <div class="countdown-overlay" v-if="showCountdown">
  146. <div class="countdown-content">
  147. <div class="countdown-number">{{ countdownValue }}</div>
  148. <div class="countdown-text">准备开始回答</div>
  149. </div>
  150. </div>
  151. <!-- 在template中添加蒙层 -->
  152. <div class="ai-voice-overlay" v-if="isPlayingAiVoice">
  153. <div class="ai-voice-content">
  154. <div class="ai-voice-icon"></div>
  155. <div class="ai-voice-text">面试官正在回复...</div>
  156. </div>
  157. </div>
  158. <!-- 在模板部分添加继续提问和结束面试按钮 -->
  159. <div class="continue-question-container" v-if="showContinueQuestionButton">
  160. <button class="continue-question-button" @click="handleContinueQuestionClick">
  161. 继续提问
  162. </button>
  163. </div>
  164. <!-- <div class="end-interview-container" v-if="showEndInterviewButton">
  165. <button class="end-interview-button" @click="handleEndInterviewClick">
  166. 结束提问
  167. </button>
  168. </div> -->
  169. <!-- 添加提问轮次显示 -->
  170. <!-- <div class="question-round-indicator" v-if="questionRound > 0">
  171. <span class="round-text">第 {{ questionRound }}/{{ maxQuestionRounds }} 轮提问</span>
  172. </div> -->
  173. </div>
  174. </template>
  175. <script>
  176. import { apiBaseUrl } from '@/common/config.js';
  177. export default {
  178. name: 'IdentityVerify',
  179. data() {
  180. return {
  181. loading: false,
  182. responses: [],
  183. processedResponses: [],
  184. assistantResponse: '',
  185. audioTranscript: '',
  186. videoPlaying: false,
  187. showDebugInfo: false, // 设置为true可以显示调试信息
  188. videoUrl: 'https://data.qicai321.com/minlong/1809457d-30c5-40bb-b6d8-a8c2e8e1e9e2.mp4', //'http://121.36.251.245:9000/minlong/tenant_1/general_uploads/abdaa6fda8494e3a8613304743ed0433.mp4', // 用于存储AI数字人视频URL
  189. showReplayButton: false,
  190. cameraStream: null, // 存储摄像头流
  191. cameraError: null, // 存储摄像头错误信息
  192. useMiniProgramCameraComponent: false, // 添加小程序相机组件标志
  193. cameraContext: null, // 添加相机上下文
  194. currentSubtitle: '',
  195. subtitles: [
  196. {
  197. startTime: 0, // 开始时间(秒)
  198. endTime: 6, // 结束时间(秒)
  199. text: '您已完成本次面试全部题目,请问您对于这个岗位还有什么想要了解的吗?'
  200. },
  201. ],
  202. // secondVideoSubtitles: [
  203. // {
  204. // startTime: 0,
  205. // endTime: 10,
  206. // text: '请结合您的基本信息与过往履历进行简单的自我介绍,并讲一讲您有哪些优势胜任本岗位:'
  207. // }
  208. // ],
  209. // thirdVideoSubtitles: [
  210. // {
  211. // startTime: 0,
  212. // endTime: 4,
  213. // text: '在工作中,你如何确保个人防护装备的正确使用?'
  214. // }
  215. // ],
  216. // fourthVideoSubtitles: [
  217. // {
  218. // startTime: 0,
  219. // endTime: 4,
  220. // text: '描述一次你与团队合作改善生产流程的经历。'
  221. // }
  222. // ],
  223. // fifthVideoSubtitles: [
  224. // {
  225. // startTime: 0,
  226. // endTime: 6,
  227. // text: '你在团队合作中曾遇到过哪些挑战?如何解决团队内部的分歧?'
  228. // }
  229. // ],
  230. // sixthVideoSubtitles: [
  231. // {
  232. // startTime: 0,
  233. // endTime: 5,
  234. // text: '您已完成本次面试全部题目,请问您对于这个岗位还有什么想要了解的吗?'
  235. // }
  236. // ],
  237. showAnswerButton: false, // 控制答题按钮显示
  238. currentVideoIndex: 0, // 当前播放的视频索引
  239. videoList: [
  240. 'https://data.qicai321.com/minlong/1809457d-30c5-40bb-b6d8-a8c2e8e1e9e2.mp4'//结束
  241. ],
  242. isRecording: false,
  243. recordingTimer: null,
  244. showStopRecordingButton: false,
  245. mediaRecorder: null,
  246. recordedChunks: [],
  247. recorder: null,
  248. lastUploadedVideoUrl: '',
  249. showStartRecordingButton: false,
  250. showRetryButton: false, // 控制重试按钮显示
  251. lastVideoToRetry: null, // 存储上次失败的视频URL,用于重试
  252. recordingStartTime: null, // 录制开始时间
  253. recordingTimerCount: 0, // 录制计时器计数
  254. recordingTimeDisplay: '00:00', // 格式化的录制时间显示
  255. // 添加上传队列相关数据
  256. uploadQueue: [], // 存储待上传的视频
  257. isUploading: false, // 标记是否正在上传
  258. uploadProgress: {}, // 存储每个视频的上传进度
  259. uploadStatus: {}, // 存储每个视频的上传状态
  260. showUploadStatus: false, // 是否显示上传状态指示器
  261. uploadStatusText: '', // 上传状态文本
  262. mediaRecorderTimeout: null, // 用于存储MediaRecorder的超时机制
  263. maxRecordingTime: 300, // 最大录制时间(秒)- 从60秒改为300秒(5分钟)
  264. remainingTime: 300, // 剩余录制时间(秒)- 从60秒改为300秒
  265. // 修改初始视频索引,添加参数控制
  266. startFromLastVideo: false, // 是否从最后一个视频开始播放
  267. countdownValue: 10, // 倒计时数值
  268. showCountdown: false, // 是否显示倒计时蒙层
  269. countdownTimer: null,
  270. showGif: false, // 控制是否显示GIF
  271. gifUrl: '', // GIF图片的URL
  272. // 添加AI语音交互相关属性
  273. aiVoiceUrl: '', // AI语音URL
  274. aiText: '', // AI回复文本
  275. transcribedText: '', // 转写文本
  276. isPlayingAiVoice: false, // 是否正在播放AI语音
  277. aiAudioPlayer: null, // AI语音播放器
  278. // 添加新的状态变量
  279. showContinueQuestionButton: false, // 控制"继续提问"按钮显示
  280. showEndInterviewButton: false, // 控制"结束面试"按钮显示
  281. questionRound: 0, // 当前提问轮次
  282. maxQuestionRounds: 1, // 最大提问轮次(可配置)
  283. conversationHistory: [], // 对话历史记录
  284. pendingAutoNavigation: false, // 标记是否有待处理的自动跳转
  285. hasTriedFallbackMethod: false, // 标记是否尝试过备选方法播放音频
  286. hasShownTextFallbackToast: false, // 标记是否已显示文本回退提示
  287. showNextButton: false, // 添加一个变量控制按钮显示
  288. }
  289. },
  290. onLoad(options) {
  291. // 检查是否有参数指定从最后一个视频开始
  292. if (options && options.startFromLast === 'true') {
  293. this.startFromLastVideo = true;
  294. // 设置为最后一个视频的索引
  295. this.currentVideoIndex = this.videoList.length - 1;
  296. }
  297. },
  298. mounted() {
  299. /* this.fetchData() */
  300. // 如果需要从最后一个视频开始,直接设置
  301. if (this.startFromLastVideo) {
  302. console.log('从最后一个视频开始播放');
  303. this.currentVideoIndex = this.videoList.length - 1;
  304. this.videoUrl = this.videoList[this.currentVideoIndex];
  305. }
  306. this.playDigitalHumanVideo();
  307. this.checkAudioPermission();
  308. this.initCamera();
  309. this.checkIOSCameraRecordPermission();
  310. // 添加防御性检查,避免渲染错误
  311. this.checkAndFixRenderingIssues();
  312. // 添加音频测试
  313. setTimeout(() => {
  314. if (this.cameraStream && !this.useMiniProgramCameraComponent) {
  315. this.testAudioInput();
  316. }
  317. }, 3000);
  318. uni.setKeepScreenOn({
  319. keepScreenOn: true
  320. });
  321. },
  322. beforeDestroy() {
  323. // 组件销毁前停止摄像头
  324. this.stopUserCamera();
  325. // 销毁AI音频播放器
  326. if (this.aiAudioPlayer) {
  327. try {
  328. this.aiAudioPlayer.destroy();
  329. } catch (e) {
  330. console.error('销毁音频播放器失败:', e);
  331. }
  332. this.aiAudioPlayer = null;
  333. }
  334. // 清除所有计时器
  335. if (this.recordingTimer) {
  336. clearInterval(this.recordingTimer);
  337. this.recordingTimer = null;
  338. }
  339. if (this.countdownTimer) {
  340. clearInterval(this.countdownTimer);
  341. this.countdownTimer = null;
  342. }
  343. if (this.mediaRecorderTimeout) {
  344. clearTimeout(this.mediaRecorderTimeout);
  345. this.mediaRecorderTimeout = null;
  346. }
  347. // 如果有正在进行的录制,停止录制
  348. if (this.mediaRecorder && this.mediaRecorder.state === 'recording') {
  349. try {
  350. this.mediaRecorder.stop();
  351. } catch (e) {
  352. console.error('停止MediaRecorder失败:', e);
  353. }
  354. }
  355. if (this.recorder) {
  356. try {
  357. this.cameraContext.stopRecord();
  358. } catch (e) {
  359. console.error('停止小程序录制失败:', e);
  360. }
  361. }
  362. // 关闭屏幕常亮
  363. uni.setKeepScreenOn({
  364. keepScreenOn: false
  365. });
  366. },
  367. methods: {
  368. // 初始化相机
  369. async initCamera() {
  370. // 检查平台
  371. const systemInfo = uni.getSystemInfoSync();
  372. // 判断是否在小程序环境中
  373. const isMiniProgram = systemInfo.uniPlatform === 'mp-weixin' ||
  374. systemInfo.uniPlatform === 'mp-alipay' ||
  375. systemInfo.uniPlatform === 'mp-baidu';
  376. if (isMiniProgram) {
  377. // 小程序环境使用小程序的相机API
  378. this.useMiniProgramCameraComponent = true;
  379. // 创建相机上下文
  380. this.cameraContext = uni.createCameraContext();
  381. // 确保已获取录音和相机权限
  382. uni.getSetting({
  383. success: (res) => {
  384. // 检查录音权限
  385. if (!res.authSetting['scope.record']) {
  386. uni.authorize({
  387. scope: 'scope.record',
  388. success: () => {
  389. console.log('录音权限已获取');
  390. },
  391. fail: (err) => {
  392. console.error('录音权限获取失败:', err);
  393. this.showPermissionDialog('录音');
  394. }
  395. });
  396. }
  397. // 检查相机权限
  398. if (!res.authSetting['scope.camera']) {
  399. uni.authorize({
  400. scope: 'scope.camera',
  401. success: () => {
  402. console.log('相机权限已获取');
  403. },
  404. fail: (err) => {
  405. console.error('相机权限获取失败:', err);
  406. this.showPermissionDialog('相机');
  407. }
  408. });
  409. }
  410. // 在iOS上,可能需要额外的权限检查
  411. const systemInfo = uni.getSystemInfoSync();
  412. if (systemInfo.platform === 'ios') {
  413. // 在iOS上,不要使用无效的权限范围
  414. // 移除以下代码块
  415. /*
  416. if (!res.authSetting['scope.camera.record']) {
  417. uni.authorize({
  418. scope: 'scope.camera.record',
  419. success: () => {
  420. console.log('相机录制权限已获取');
  421. },
  422. fail: (err) => {
  423. console.error('相机录制权限获取失败:', err);
  424. this.showPermissionDialog('相机录制');
  425. }
  426. });
  427. }
  428. */
  429. // 确保同时获取了相机和录音权限
  430. if (!res.authSetting['scope.camera'] || !res.authSetting['scope.record']) {
  431. console.log('iOS需要同时获取相机和录音权限');
  432. }
  433. }
  434. }
  435. });
  436. } else {
  437. // H5/App环境使用浏览器的API
  438. try {
  439. // 请求摄像头和麦克风权限并获取媒体流,添加更多约束
  440. const constraints = {
  441. audio: {
  442. echoCancellation: true,
  443. noiseSuppression: true,
  444. autoGainControl: true
  445. },
  446. video: {
  447. width: { ideal: 640, max: 1280 }, // 控制视频宽度
  448. height: { ideal: 480, max: 720 }, // 控制视频高度
  449. frameRate: { ideal: 15, max: 24 }, // 控制帧率
  450. facingMode: 'user'
  451. }
  452. };
  453. const stream = await navigator.mediaDevices.getUserMedia(constraints);
  454. // 保存流以便后续使用
  455. this.cameraStream = stream;
  456. // 检查音频轨道
  457. const audioTracks = stream.getAudioTracks();
  458. console.log('音频轨道数量:', audioTracks.length);
  459. if (audioTracks.length > 0) {
  460. console.log('音频轨道已获取:', audioTracks[0].label);
  461. // 确保音频轨道已启用
  462. audioTracks[0].enabled = true;
  463. } else {
  464. console.warn('未检测到音频轨道,尝试单独获取音频');
  465. this.tryGetAudioOnly();
  466. }
  467. // 将流设置到视频元素
  468. const videoElement = this.$refs.userCameraVideo;
  469. if (videoElement) {
  470. videoElement.srcObject = stream;
  471. videoElement.muted = true; // 避免回声,但仍然录制声音
  472. }
  473. } catch (error) {
  474. console.error('获取摄像头失败:', error);
  475. this.cameraError = error.message || '无法访问摄像头';
  476. // 显示错误提示
  477. uni.showToast({
  478. title: '无法访问摄像头,请检查权限设置',
  479. icon: 'none'
  480. });
  481. }
  482. }
  483. },
  484. // 停止用户摄像头
  485. stopUserCamera() {
  486. if (this.cameraStream) {
  487. // 停止所有轨道
  488. this.cameraStream.getTracks().forEach(track => {
  489. track.stop();
  490. });
  491. this.cameraStream = null;
  492. }
  493. },
  494. async fetchData() {
  495. this.loading = true
  496. this.assistantResponse = ''
  497. this.audioTranscript = ''
  498. this.processedResponses = []
  499. try {
  500. // 使用uni.request代替fetch
  501. const requestTask = uni.request({
  502. url: 'https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions',
  503. method: 'POST',
  504. header: {
  505. 'Content-Type': 'application/json',
  506. 'Authorization': 'Bearer sk-9e1ec73a7d97493b8613c63f06b6110c'
  507. },
  508. data: {
  509. "model": "qwen-omni-turbo",
  510. "messages": [
  511. {
  512. "role": "user",
  513. "content": [
  514. {
  515. "type": "input_audio",
  516. "input_audio": {
  517. "data": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250211/tixcef/cherry.wav",
  518. "format": "wav"
  519. }
  520. },
  521. {
  522. "type": "text",
  523. "text": "这段音频在说什么"
  524. }
  525. ]
  526. }
  527. ],
  528. "stream":true,
  529. "stream_options":{
  530. "include_usage":true
  531. },
  532. "modalities":["text","audio"],
  533. "audio":{"voice":"Cherry","format":"wav"}
  534. },
  535. success: (res) => {
  536. console.log('请求成功,响应数据:', res.data);
  537. // 检查响应数据是否包含多个JSON对象
  538. if (typeof res.data === 'string' && res.data.includes('data: {')) {
  539. // 处理包含多个JSON对象的情况
  540. const chunks = res.data.split('data: ').filter(chunk => chunk.trim() !== '');
  541. chunks.forEach(chunk => {
  542. this.handleStreamResponse(chunk);
  543. });
  544. } else {
  545. // 处理单个响应对象的情况
  546. this.handleStreamResponse(res.data);
  547. }
  548. // 模拟获取到数字人视频并播放
  549. this.playDigitalHumanVideo();
  550. },
  551. fail: (err) => {
  552. console.error('请求失败:', err);
  553. },
  554. complete: () => {
  555. this.loading = false;
  556. }
  557. });
  558. } catch (error) {
  559. console.error('获取数据失败:', error);
  560. this.loading = false;
  561. }
  562. },
  563. handleStreamResponse(data) {
  564. // 处理流式响应数据
  565. if (typeof data === 'string') {
  566. // 处理字符串格式的响应
  567. if (data === '[DONE]') return;
  568. try {
  569. // 移除可能存在的换行符和多余空格
  570. const cleanData = data.trim();
  571. // 检查是否是有效的JSON字符串
  572. if (cleanData.startsWith('{') && cleanData.endsWith('}')) {
  573. const jsonData = JSON.parse(cleanData);
  574. this.processStreamChunk(jsonData);
  575. }
  576. } catch (e) {
  577. console.error('解析JSON失败:', e, '原始数据:', data);
  578. }
  579. } else {
  580. // 处理对象格式的响应
  581. this.processStreamChunk(data);
  582. }
  583. },
  584. processStreamChunk(chunk) {
  585. if (chunk.choices && chunk.choices.length > 0) {
  586. const choice = chunk.choices[0];
  587. // 处理助手回复内容
  588. if (choice.delta && choice.delta.content) {
  589. this.assistantResponse += choice.delta.content;
  590. }
  591. // 处理音频转写内容
  592. if (choice.delta && choice.delta.audio && choice.delta.audio.transcript) {
  593. this.audioTranscript += choice.delta.audio.transcript;
  594. }
  595. // 处理角色和音频转写
  596. if (choice.delta) {
  597. const result = {};
  598. if (choice.delta.role) {
  599. result.role = choice.delta.role;
  600. }
  601. if (choice.delta.audio && choice.delta.audio.transcript) {
  602. result.transcript = choice.delta.audio.transcript;
  603. }
  604. if (Object.keys(result).length > 0) {
  605. this.processedResponses.push(result);
  606. }
  607. }
  608. }
  609. },
  610. processResponseData() {
  611. // 处理返回的数据
  612. this.processedResponses = this.responses.map(item => {
  613. const result = {}
  614. // 处理角色信息
  615. if (item.delta && item.delta.role) {
  616. result.role = item.delta.role
  617. }
  618. // 处理音频转写文本
  619. if (item.delta && item.delta.audio && item.delta.audio.transcript) {
  620. result.transcript = item.delta.audio.transcript
  621. }
  622. return result
  623. }).filter(item => Object.keys(item).length > 0)
  624. },
  625. // 播放数字人视频
  626. playDigitalHumanVideo() {
  627. // 设置当前视频
  628. if(JSON.parse(uni.getStorageSync('configData'))==null){
  629. this.videoUrl = this.videoList[this.currentVideoIndex];
  630. }else{
  631. this.videoUrl =JSON.parse(uni.getStorageSync('configData')).digital_human?.ending_video_url || this.videoList[this.currentVideoIndex];
  632. }
  633. this.videoPlaying = true;
  634. console.log(`播放视频 ${this.currentVideoIndex + 1}/${this.videoList.length}: ${this.videoUrl}`);
  635. // 使用 uni.createVideoContext 来控制视频
  636. this.$nextTick(() => {
  637. const videoContext = uni.createVideoContext('myVideo', this);
  638. if (videoContext) {
  639. videoContext.play();
  640. // 设置超时检查,确认视频是否真的在播放
  641. setTimeout(() => {
  642. if (this.videoPlaying && this.$refs.videoPlayer) {
  643. console.log('视频应该正在播放');
  644. } else {
  645. console.log('视频可能未成功播放,尝试替代方案');
  646. this.tryAlternativeVideoPath();
  647. }
  648. }, 1000);
  649. } else {
  650. console.error('无法创建视频上下文');
  651. this.tryAlternativeVideoPath();
  652. }
  653. });
  654. },
  655. // 修改 tryAlternativeVideoPath 方法
  656. tryAlternativeVideoPath() {
  657. console.log('尝试使用替代路径');
  658. // 尝试不同的路径格式
  659. const alternativePaths = [
  660. './static/demo.mp4',
  661. '../static/demo.mp4',
  662. 'static/demo.mp4',
  663. '/static/demo.mp4',
  664. // 添加绝对路径
  665. `${window.location.origin}/static/demo.mp4`
  666. ];
  667. // 获取当前路径索引
  668. const currentPathIndex = alternativePaths.indexOf(this.videoUrl);
  669. const nextPathIndex = (currentPathIndex + 1) % alternativePaths.length;
  670. // 设置下一个路径
  671. this.videoUrl = alternativePaths[nextPathIndex];
  672. console.log('尝试新路径:', this.videoUrl);
  673. this.$nextTick(() => {
  674. const videoContext = uni.createVideoContext('myVideo', this);
  675. if (videoContext) {
  676. videoContext.stop();
  677. videoContext.play();
  678. // 检查是否成功播放
  679. setTimeout(() => {
  680. if (nextPathIndex === alternativePaths.length - 1 && !this.videoPlaying) {
  681. console.log('所有路径均失败,尝试使用uni.getVideoInfo检查视频');
  682. this.checkVideoWithAPI();
  683. }
  684. }, 1000);
  685. }
  686. });
  687. },
  688. // 添加新方法:使用uni API检查视频
  689. checkVideoWithAPI() {
  690. // 尝试使用uni.getVideoInfo API检查视频是否可用
  691. uni.getVideoInfo({
  692. src: '/static/demo.mp4',
  693. success: (res) => {
  694. console.log('视频信息获取成功:', res);
  695. // 如果能获取到视频信息,再次尝试播放
  696. this.videoUrl = '/static/demo.mp4';
  697. this.$nextTick(() => {
  698. const videoContext = uni.createVideoContext('myVideo', this);
  699. if (videoContext) {
  700. videoContext.play();
  701. }
  702. });
  703. },
  704. fail: (err) => {
  705. console.error('视频信息获取失败:', err);
  706. // 最后尝试使用uni.chooseVideo API
  707. this.fallbackToLocalVideo();
  708. }
  709. });
  710. },
  711. // 添加新方法:回退到本地视频
  712. fallbackToLocalVideo() {
  713. console.log('尝试使用本地视频资源');
  714. // 检查平台
  715. const platform = uni.getSystemInfoSync().platform;
  716. if (platform === 'android' || platform === 'ios') {
  717. // 移动端可以尝试使用本地资源
  718. this.videoUrl = platform === 'android' ? 'android.resource://package_name/raw/demo' : 'file:///assets/demo.mp4';
  719. this.$nextTick(() => {
  720. const videoContext = uni.createVideoContext('myVideo', this);
  721. if (videoContext) {
  722. videoContext.play();
  723. }
  724. });
  725. } else {
  726. // 最终回退到静态图片
  727. this.videoPlaying = false;
  728. uni.showToast({
  729. title: '视频加载失败,显示静态图片',
  730. icon: 'none'
  731. });
  732. }
  733. },
  734. // 修改 handleVideoError 方法
  735. handleVideoError(e) {
  736. console.error('视频加载错误:', e);
  737. // 记录更详细的错误信息
  738. if (e && e.detail) {
  739. console.error('详细错误信息:', e.detail);
  740. }
  741. // 检查视频文件是否存在
  742. uni.getFileInfo({
  743. filePath: this.videoUrl.startsWith('/') ? this.videoUrl.substring(1) : this.videoUrl,
  744. success: (res) => {
  745. console.log('文件存在,大小:', res.size);
  746. // 文件存在但播放失败,可能是格式问题
  747. this.tryDifferentFormat();
  748. },
  749. fail: (err) => {
  750. console.error('文件不存在或无法访问:', err);
  751. // 尝试不同路径
  752. this.tryAlternativeVideoPath();
  753. }
  754. });
  755. // 如果多次尝试后仍然失败,显示错误信息
  756. uni.showToast({
  757. title: '视频加载失败,请检查文件是否存在',
  758. icon: 'none',
  759. duration: 2000
  760. });
  761. },
  762. // 添加新方法:尝试不同格式
  763. tryDifferentFormat() {
  764. console.log('尝试不同的视频格式');
  765. // 尝试不同的视频格式
  766. const formats = [
  767. { ext: 'mp4', mime: 'video/mp4' },
  768. { ext: 'webm', mime: 'video/webm' },
  769. { ext: 'ogg', mime: 'video/ogg' },
  770. { ext: 'mov', mime: 'video/quicktime' }
  771. ];
  772. // 获取当前文件名(不含扩展名)
  773. const currentPath = this.videoUrl;
  774. const basePath = currentPath.substring(0, currentPath.lastIndexOf('.')) || '/static/demo';
  775. // 尝试下一个格式
  776. let nextFormat = formats.find(f => !currentPath.endsWith(f.ext));
  777. if (nextFormat) {
  778. this.videoUrl = `${basePath}.${nextFormat.ext}`;
  779. console.log('尝试新格式:', this.videoUrl);
  780. this.$nextTick(() => {
  781. const videoContext = uni.createVideoContext('myVideo', this);
  782. if (videoContext) {
  783. videoContext.stop();
  784. videoContext.play();
  785. }
  786. });
  787. } else {
  788. // 所有格式都尝试过了,使用内置资源
  789. this.useBuiltInResource();
  790. }
  791. },
  792. // 添加新方法:使用内置资源
  793. useBuiltInResource() {
  794. console.log('尝试使用内置资源');
  795. // 检查平台
  796. const platform = uni.getSystemInfoSync().platform;
  797. // 根据平台选择合适的视频源
  798. if (platform === 'windows') {
  799. // Windows平台特定处理
  800. // 尝试使用相对于应用根目录的路径
  801. const appRoot = process.env.UNI_INPUT_DIR || '';
  802. this.videoUrl = `./static/demo.mp4`;
  803. // 或者尝试使用file://协议
  804. // this.videoUrl = `file:///${appRoot.replace(/\\/g, '/')}/static/demo.mp4`;
  805. console.log('Windows平台尝试路径:', this.videoUrl);
  806. } else if (platform === 'android' || platform === 'ios') {
  807. // 移动端
  808. this.useNativeVideo();
  809. } else {
  810. // Web平台
  811. // 尝试使用完整URL
  812. const baseUrl = window.location.origin;
  813. this.videoUrl = `${baseUrl}/static/demo.mp4`;
  814. console.log('Web平台尝试URL:', this.videoUrl);
  815. }
  816. this.$nextTick(() => {
  817. const videoContext = uni.createVideoContext('myVideo', this);
  818. if (videoContext) {
  819. videoContext.play();
  820. }
  821. });
  822. },
  823. // 添加新方法:使用原生视频能力
  824. useNativeVideo() {
  825. console.log('尝试使用原生视频能力');
  826. // 在移动端,可以尝试使用原生视频播放器
  827. uni.chooseVideo({
  828. sourceType: ['album'],
  829. success: (res) => {
  830. this.videoUrl = res.tempFilePath;
  831. this.$nextTick(() => {
  832. const videoContext = uni.createVideoContext('myVideo', this);
  833. if (videoContext) {
  834. videoContext.play();
  835. }
  836. });
  837. },
  838. fail: () => {
  839. // 如果用户取消选择,回退到静态图片
  840. this.videoPlaying = false;
  841. uni.showToast({
  842. title: '无法加载视频,显示静态图片',
  843. icon: 'none'
  844. });
  845. }
  846. });
  847. },
  848. // 处理视频结束事件
  849. handleVideoEnded() {
  850. console.log('视频播放结束,当前视频索引:', this.currentVideoIndex);
  851. this.videoPlaying = false;
  852. /* // 设置对应问题的GIF图片URL
  853. // if (this.currentVideoIndex === 0) {
  854. this.gifUrl = 'http://121.36.251.245:9000/minlong/cae2da8f92ce4af278d3929ab8c5973f.mp4';
  855. // } else if (this.currentVideoIndex === 1) {
  856. // this.gifUrl = 'http://121.36.251.245:9000/minlong/tenant_1/general_uploads/5273282d971441249aeadf35a7574f01.gif';
  857. // } else if (this.currentVideoIndex === 2) {
  858. // this.gifUrl = 'http://121.36.251.245:9000/minlong/tenant_1/general_uploads/5273282d971441249aeadf35a7574f01.gif';
  859. // } else if (this.currentVideoIndex === 3) {
  860. // this.gifUrl = 'http://121.36.251.245:9000/minlong/tenant_1/general_uploads/5273282d971441249aeadf35a7574f01.gif';
  861. // } else if (this.currentVideoIndex === 4) {
  862. // this.gifUrl = 'http://121.36.251.245:9000/minlong/tenant_1/general_uploads/5273282d971441249aeadf35a7574f01.gif';
  863. // } else if (this.currentVideoIndex === 5) {
  864. // this.gifUrl = 'http://121.36.251.245:9000/minlong/tenant_1/general_uploads/5273282d971441249aeadf35a7574f01.gif';
  865. // }
  866. // 显示GIF图片
  867. this.showGif = true; */
  868. // 视频结束后直接显示"开始作答"按钮
  869. this.showStartRecordingButton = true;
  870. this.startCountdown();
  871. this.showAnswerButton = false;
  872. },
  873. // 添加新方法:开始倒计时
  874. startCountdown() {
  875. // 显示倒计时蒙层
  876. this.showCountdown = true;
  877. this.countdownValue = 10;
  878. // 开始倒计时
  879. this.countdownTimer = setInterval(() => {
  880. this.countdownValue--;
  881. if (this.countdownValue <= 0) {
  882. // 倒计时结束,清除定时器
  883. this.clearCountdown();
  884. // 隐藏"开始回答"按钮
  885. this.showStartRecordingButton = false;
  886. // 开始录制
  887. this.startRecordingAnswer();
  888. }
  889. }, 1000);
  890. },
  891. // 添加新方法:清除倒计时
  892. clearCountdown() {
  893. if (this.countdownTimer) {
  894. clearInterval(this.countdownTimer);
  895. this.countdownTimer = null;
  896. }
  897. this.showCountdown = false;
  898. },
  899. // 修改 handleStartRecordingClick 方法,使其可以终止倒计时
  900. handleStartRecordingClick() {
  901. // 隐藏"开始回答"按钮
  902. this.showStartRecordingButton = false;
  903. // 如果倒计时正在进行,清除倒计时
  904. this.clearCountdown();
  905. // 直接开始录制
  906. this.startRecordingAnswer();
  907. },
  908. // 修复 stopRecordingAnswer 方法,确保录制正确停止并上传
  909. stopRecordingAnswer() {
  910. // 如果倒计时正在进行,先清除倒计时
  911. this.clearCountdown();
  912. // 检查录制时长
  913. const recordingDuration = this.getRecordingDuration();
  914. const minimumDuration = 5; // 最小录制时长(秒)
  915. if (recordingDuration < minimumDuration) {
  916. // 录制时间过短,显示提示
  917. uni.showToast({
  918. title: '录制时间过短,请至少录制5秒',
  919. icon: 'none',
  920. duration: 2000
  921. });
  922. // 不执行停止录制逻辑,继续录制
  923. return;
  924. }
  925. // 隐藏停止录制按钮
  926. this.showStopRecordingButton = false;
  927. // 停止录制计时器
  928. if (this.recordingTimer) {
  929. clearInterval(this.recordingTimer);
  930. this.recordingTimer = null;
  931. }
  932. // 根据平台选择不同的停止录制方法
  933. const systemInfo = uni.getSystemInfoSync();
  934. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith('mp-');
  935. if (isMiniProgram) {
  936. // 小程序环境使用小程序的停止录制API
  937. this.stopMiniProgramRecording();
  938. } else {
  939. // H5/App环境使用MediaRecorder API
  940. this.stopBrowserRecording();
  941. }
  942. // 标记录制已停止
  943. this.isRecording = false;
  944. },
  945. // 添加新方法:开始录制用户回答
  946. startRecordingAnswer() {
  947. console.log('开始录制用户回答');
  948. this.isRecording = true;
  949. // 记录录制开始时间
  950. this.recordingStartTime = Date.now();
  951. this.recordingTimerCount = 0;
  952. this.remainingTime = this.maxRecordingTime;
  953. // 启动计时器,每秒更新计时
  954. this.recordingTimer = setInterval(() => {
  955. this.recordingTimerCount++;
  956. this.remainingTime = Math.max(0, this.maxRecordingTime - this.recordingTimerCount);
  957. // 更新UI显示录制时长和剩余时间
  958. this.recordingTimeDisplay = this.formatTime(this.recordingTimerCount) +
  959. ' / ' + this.formatTime(this.maxRecordingTime);
  960. // 检查是否达到最大录制时间
  961. if (this.recordingTimerCount >= this.maxRecordingTime) {
  962. console.log('已达到最大录制时间(60秒),自动停止录制');
  963. this.stopRecordingAnswer();
  964. }
  965. }, 1000);
  966. // 显示录制中的提示
  967. // uni.showLoading({
  968. // title: '正在录制...',
  969. // mask: true
  970. // });
  971. // 根据平台选择不同的录制方法
  972. const systemInfo = uni.getSystemInfoSync();
  973. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith('mp-');
  974. if (isMiniProgram) {
  975. // 小程序环境使用小程序的录制API
  976. this.startMiniProgramRecording();
  977. } else {
  978. // H5/App环境使用MediaRecorder API
  979. this.startBrowserRecording();
  980. }
  981. // 显示停止录制按钮
  982. this.showStopRecordingButton = true;
  983. },
  984. // 添加一个新方法:重置相机组件
  985. resetCamera() {
  986. console.log('重置相机组件');
  987. // 先完全移除相机组件
  988. this.useMiniProgramCameraComponent = false;
  989. // 释放相机上下文
  990. if (this.cameraContext) {
  991. this.cameraContext = null;
  992. }
  993. // 延迟后重新创建相机组件
  994. setTimeout(() => {
  995. this.useMiniProgramCameraComponent = true;
  996. // 再次延迟创建相机上下文,确保组件已完全渲染
  997. setTimeout(() => {
  998. this.cameraContext = uni.createCameraContext();
  999. console.log('相机组件已重置');
  1000. }, 500);
  1001. }, 500);
  1002. },
  1003. // 修改 startMiniProgramRecording 方法
  1004. startMiniProgramRecording() {
  1005. console.log('开始小程序录制方法');
  1006. // 获取平台信息
  1007. const systemInfo = uni.getSystemInfoSync();
  1008. const isIOS = systemInfo.platform === 'ios';
  1009. // 在iOS上,先重置相机
  1010. if (isIOS) {
  1011. // 先重置相机组件
  1012. this.resetCamera();
  1013. // 延迟执行录制,给相机组件足够的初始化时间
  1014. setTimeout(() => {
  1015. this.actualStartRecording(isIOS);
  1016. }, 1000);
  1017. } else {
  1018. // Android直接开始
  1019. this.actualStartRecording(isIOS);
  1020. }
  1021. },
  1022. // 添加新方法:实际开始录制
  1023. actualStartRecording(isIOS) {
  1024. if (!this.cameraContext) {
  1025. this.cameraContext = uni.createCameraContext();
  1026. console.log('创建新的相机上下文');
  1027. }
  1028. // 确保有录音权限
  1029. uni.getSetting({
  1030. success: (res) => {
  1031. const hasRecordAuth = res.authSetting['scope.record'];
  1032. const hasCameraAuth = res.authSetting['scope.camera'];
  1033. if (!hasRecordAuth || !hasCameraAuth) {
  1034. console.warn('缺少必要权限,请求权限');
  1035. this.requestMiniProgramPermissions();
  1036. return;
  1037. }
  1038. // 在iOS上,先检查相机状态
  1039. if (isIOS) {
  1040. console.log('iOS: 检查相机状态');
  1041. // 使用最简单的选项,设置最大录制时间为5分钟
  1042. const options = {
  1043. timeout: 300000, // 300秒超时 (5分钟)
  1044. quality: 'low', // 降低质量
  1045. compressed: true,
  1046. success: () => {
  1047. console.log('iOS录制开始成功');
  1048. },
  1049. fail: (err) => {
  1050. console.error('iOS录制失败:', err);
  1051. // 如果失败,尝试使用不同的方法
  1052. this.useAlternativeRecordingMethod();
  1053. }
  1054. };
  1055. try {
  1056. console.log('尝试开始录制');
  1057. this.recorder = this.cameraContext.startRecord(options);
  1058. } catch (e) {
  1059. console.error('开始录制异常:', e);
  1060. this.useAlternativeRecordingMethod();
  1061. }
  1062. } else {
  1063. // Android使用标准选项,设置最大录制时间为5分钟
  1064. const options = {
  1065. timeout: 300000, // 300秒超时 (5分钟)
  1066. quality: 'medium',
  1067. compressed: true,
  1068. success: () => {
  1069. console.log('Android录制开始成功');
  1070. },
  1071. fail: (err) => {
  1072. console.error('Android录制失败:', err);
  1073. uni.showToast({
  1074. title: '录制失败,请检查相机权限',
  1075. icon: 'none'
  1076. });
  1077. this.proceedToNextQuestion();
  1078. }
  1079. };
  1080. this.recorder = this.cameraContext.startRecord(options);
  1081. }
  1082. }
  1083. });
  1084. },
  1085. // 添加新方法:使用替代录制方法
  1086. useAlternativeRecordingMethod() {
  1087. console.log('使用替代录制方法');
  1088. // 在iOS上,可以尝试使用chooseVideo API作为备选
  1089. uni.showActionSheet({
  1090. itemList: ['使用相册中的视频', '跳过此问题'],
  1091. success: (res) => {
  1092. if (res.tapIndex === 0) {
  1093. // 选择相册中的视频
  1094. uni.chooseVideo({
  1095. sourceType: ['album'],
  1096. maxDuration: 300, // 从60秒改为300秒
  1097. camera: 'front',
  1098. success: (res) => {
  1099. console.log('选择视频成功:', res.tempFilePath);
  1100. // 停止录制状态
  1101. this.isRecording = false;
  1102. this.showStopRecordingButton = false;
  1103. // 上传选择的视频
  1104. this.uploadRecordedVideo(res.tempFilePath);
  1105. },
  1106. fail: () => {
  1107. console.log('用户取消选择视频');
  1108. this.proceedToNextQuestion();
  1109. }
  1110. });
  1111. } else {
  1112. // 跳过此问题
  1113. console.log('用户选择跳过问题');
  1114. this.proceedToNextQuestion();
  1115. }
  1116. },
  1117. fail: () => {
  1118. console.log('操作取消');
  1119. this.proceedToNextQuestion();
  1120. }
  1121. });
  1122. },
  1123. // 添加新方法:请求小程序权限
  1124. requestMiniProgramPermissions() {
  1125. // 请求录音权限
  1126. uni.authorize({
  1127. scope: 'scope.record',
  1128. success: () => {
  1129. console.log('录音权限已获取');
  1130. // 请求相机权限
  1131. uni.authorize({
  1132. scope: 'scope.camera',
  1133. success: () => {
  1134. console.log('相机权限已获取');
  1135. // 权限都获取到后,开始录制
  1136. this.startMiniProgramRecording();
  1137. },
  1138. fail: (err) => {
  1139. console.error('相机权限获取失败:', err);
  1140. this.showPermissionDialog('相机');
  1141. }
  1142. });
  1143. },
  1144. fail: (err) => {
  1145. console.error('录音权限获取失败:', err);
  1146. this.showPermissionDialog('录音');
  1147. }
  1148. });
  1149. },
  1150. // 修改浏览器环境下的录制方法
  1151. startBrowserRecording() {
  1152. if (!this.cameraStream) {
  1153. console.error('没有可用的摄像头流');
  1154. uni.showToast({
  1155. title: '录制失败,摄像头未就绪',
  1156. icon: 'none'
  1157. });
  1158. this.proceedToNextQuestion();
  1159. return;
  1160. }
  1161. try {
  1162. // 检查流中是否包含音频轨道
  1163. const hasAudio = this.cameraStream.getAudioTracks().length > 0;
  1164. if (!hasAudio) {
  1165. console.warn('警告:媒体流中没有音频轨道,尝试重新获取带音频的媒体流');
  1166. // 尝试重新获取带音频的媒体流
  1167. navigator.mediaDevices.getUserMedia({
  1168. audio: {
  1169. echoCancellation: true,
  1170. noiseSuppression: true,
  1171. autoGainControl: true
  1172. },
  1173. video: true
  1174. })
  1175. .then(newStream => {
  1176. // 检查新流是否包含音频轨道
  1177. const audioTracks = newStream.getAudioTracks();
  1178. if (audioTracks.length > 0) {
  1179. console.log('成功获取音频轨道:', audioTracks[0].label);
  1180. // 合并视频和音频轨道
  1181. const videoTrack = this.cameraStream.getVideoTracks()[0];
  1182. const audioTrack = newStream.getAudioTracks()[0];
  1183. // 创建新的媒体流,包含视频和音频轨道
  1184. const combinedStream = new MediaStream();
  1185. if (videoTrack) combinedStream.addTrack(videoTrack);
  1186. if (audioTrack) combinedStream.addTrack(audioTrack);
  1187. this.cameraStream = combinedStream;
  1188. // 更新视频元素的源
  1189. const videoElement = this.$refs.userCameraVideo;
  1190. if (videoElement) {
  1191. videoElement.srcObject = combinedStream;
  1192. videoElement.muted = true; // 避免回声,但仍然录制声音
  1193. }
  1194. // 继续录制过程
  1195. this.setupMediaRecorder(combinedStream);
  1196. } else {
  1197. console.warn('仍然无法获取音频轨道');
  1198. // 使用现有流继续
  1199. this.setupMediaRecorder(this.cameraStream);
  1200. }
  1201. })
  1202. .catch(err => {
  1203. console.error('获取音频失败:', err);
  1204. // 使用现有流继续
  1205. this.setupMediaRecorder(this.cameraStream);
  1206. });
  1207. } else {
  1208. console.log('检测到音频轨道,直接使用');
  1209. // 已有音频轨道,直接使用
  1210. this.setupMediaRecorder(this.cameraStream);
  1211. }
  1212. } catch (error) {
  1213. console.error('浏览器录制失败:', error);
  1214. uni.showToast({
  1215. title: '录制失败,浏览器可能不支持此功能',
  1216. icon: 'none'
  1217. });
  1218. this.proceedToNextQuestion();
  1219. }
  1220. },
  1221. // 修改 setupMediaRecorder 方法
  1222. setupMediaRecorder(stream) {
  1223. // 检查流中的轨道
  1224. const videoTracks = stream.getVideoTracks();
  1225. const audioTracks = stream.getAudioTracks();
  1226. console.log('设置MediaRecorder - 视频轨道:', videoTracks.length, '音频轨道:', audioTracks.length);
  1227. // 尝试使用支持度更广的编码格式
  1228. let mimeType = '';
  1229. const supportedTypes = [
  1230. 'video/webm;codecs=vp9,opus',
  1231. 'video/webm;codecs=vp8,opus',
  1232. 'video/webm;codecs=h264,opus',
  1233. 'video/mp4;codecs=h264,aac',
  1234. 'video/webm',
  1235. 'video/mp4'
  1236. ];
  1237. for (const type of supportedTypes) {
  1238. if (MediaRecorder.isTypeSupported(type)) {
  1239. mimeType = type;
  1240. console.log('使用支持的MIME类型:', mimeType);
  1241. break;
  1242. }
  1243. }
  1244. // 创建MediaRecorder实例,设置较低的比特率以减小文件大小
  1245. const options = {
  1246. mimeType: mimeType || '',
  1247. audioBitsPerSecond: 64000, // 降低音频比特率
  1248. videoBitsPerSecond: 1000000, // 降低视频比特率到1Mbps
  1249. };
  1250. try {
  1251. this.mediaRecorder = new MediaRecorder(stream, options);
  1252. console.log('MediaRecorder创建成功,使用选项:', options);
  1253. } catch (e) {
  1254. console.warn('使用指定选项创建MediaRecorder失败,尝试使用默认选项');
  1255. this.mediaRecorder = new MediaRecorder(stream);
  1256. }
  1257. // 存储录制的数据块
  1258. this.recordedChunks = [];
  1259. // 监听数据可用事件
  1260. this.mediaRecorder.ondataavailable = (event) => {
  1261. if (event.data && event.data.size > 0) {
  1262. this.recordedChunks.push(event.data);
  1263. console.log(`收到数据块: ${event.data.size} 字节`);
  1264. }
  1265. };
  1266. // 监听录制停止事件
  1267. this.mediaRecorder.onstop = async () => {
  1268. console.log('MediaRecorder停止,数据块数量:', this.recordedChunks.length);
  1269. if (this.recordedChunks.length === 0) {
  1270. console.error('没有录制到数据');
  1271. uni.showToast({
  1272. title: '录制失败,未捕获到数据',
  1273. icon: 'none'
  1274. });
  1275. this.proceedToNextQuestion();
  1276. return;
  1277. }
  1278. // 创建Blob对象
  1279. const mimeType = this.mediaRecorder.mimeType || 'video/webm';
  1280. const blob = new Blob(this.recordedChunks, { type: mimeType });
  1281. console.log('创建Blob,原始大小:', blob.size, '类型:', mimeType);
  1282. // 显示压缩中提示
  1283. uni.showLoading({
  1284. title: '正在处理视频...',
  1285. mask: true
  1286. });
  1287. try {
  1288. // 压缩视频
  1289. const compressedBlob = await this.compressVideo(blob);
  1290. // 将Blob转换为File对象
  1291. const fileName = `answer_${this.currentVideoIndex}_${Date.now()}.webm`;
  1292. const file = new File([compressedBlob], fileName, { type: mimeType });
  1293. // 隐藏压缩提示
  1294. uni.hideLoading();
  1295. // 上传文件
  1296. this.uploadRecordedVideo(file);
  1297. } catch (error) {
  1298. console.error('视频处理失败:', error);
  1299. uni.hideLoading();
  1300. // 如果压缩失败,使用原始视频
  1301. const fileName = `answer_${this.currentVideoIndex}_${Date.now()}.webm`;
  1302. const file = new File([blob], fileName, { type: mimeType });
  1303. this.uploadRecordedVideo(file);
  1304. }
  1305. };
  1306. // 监听错误
  1307. this.mediaRecorder.onerror = (event) => {
  1308. console.error('MediaRecorder错误:', event.error);
  1309. };
  1310. // 开始录制
  1311. try {
  1312. this.mediaRecorder.start(1000); // 每秒触发一次dataavailable事件
  1313. console.log('MediaRecorder开始录制');
  1314. // 设置最大录制时间为60秒
  1315. // 注意:我们已经在startRecordingAnswer方法中设置了全局计时器
  1316. // 这里作为备份机制,确保即使全局计时器失效,也能停止录制
  1317. this.mediaRecorderTimeout = setTimeout(() => {
  1318. if (this.mediaRecorder && this.mediaRecorder.state === 'recording') {
  1319. console.log('MediaRecorder备份超时机制触发,停止录制');
  1320. this.mediaRecorder.stop();
  1321. }
  1322. }, 300000); // 300秒 (5分钟)
  1323. } catch (e) {
  1324. console.error('开始录制失败:', e);
  1325. }
  1326. },
  1327. // 添加新方法:停止录制用户回答
  1328. stopRecordingAnswer() {
  1329. console.log('停止录制用户回答');
  1330. if (this.countdownTimer) {
  1331. clearInterval(this.countdownTimer);
  1332. this.countdownTimer = null;
  1333. this.showCountdown = false;
  1334. }
  1335. // 检查录制时长
  1336. const recordingDuration = this.getRecordingDuration();
  1337. const minimumDuration = 5; // 最小录制时长(秒),从3秒改为5秒
  1338. if (recordingDuration < minimumDuration) {
  1339. // 录制时间过短,显示提示
  1340. uni.showToast({
  1341. title: '录制时间过短,请至少录制5秒',
  1342. icon: 'none',
  1343. duration: 2000
  1344. });
  1345. // 不执行停止录制逻辑,继续录制
  1346. return;
  1347. }
  1348. // 隐藏停止录制按钮
  1349. this.showStopRecordingButton = false;
  1350. // 停止录制计时器
  1351. if (this.recordingTimer) {
  1352. clearInterval(this.recordingTimer);
  1353. this.recordingTimer = null;
  1354. }
  1355. // 根据平台选择不同的停止录制方法
  1356. const systemInfo = uni.getSystemInfoSync();
  1357. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith('mp-');
  1358. if (isMiniProgram) {
  1359. // 小程序环境使用小程序的停止录制API
  1360. this.stopMiniProgramRecording();
  1361. } else {
  1362. // H5/App环境使用MediaRecorder API
  1363. this.stopBrowserRecording();
  1364. }
  1365. // 标记录制已停止
  1366. this.isRecording = false;
  1367. },
  1368. // 添加新方法:获取录制时长
  1369. getRecordingDuration() {
  1370. // 如果有明确的录制开始时间,计算实际录制时长
  1371. if (this.recordingStartTime) {
  1372. return (Date.now() - this.recordingStartTime) / 1000;
  1373. }
  1374. // 如果没有明确记录开始时间,尝试从视频元素获取
  1375. if (this.mediaRecorder && this.$refs.userCameraVideo) {
  1376. return this.$refs.userCameraVideo.currentTime || 0;
  1377. }
  1378. // 如果无法获取准确时长,返回估计值(如果有计时器)
  1379. if (this.recordingTimerCount) {
  1380. return this.recordingTimerCount;
  1381. }
  1382. // 默认返回0
  1383. return 0;
  1384. },
  1385. // 添加新方法:重置录制
  1386. resetRecording() {
  1387. // 保持录制状态,但重置计时器
  1388. if (this.recordingTimer) {
  1389. clearTimeout(this.recordingTimer);
  1390. }
  1391. // 重置录制开始时间
  1392. this.recordingStartTime = Date.now();
  1393. this.recordingTimerCount = 0;
  1394. // 如果是浏览器环境,需要重置MediaRecorder
  1395. if (this.mediaRecorder && this.mediaRecorder.state !== 'inactive') {
  1396. // 停止当前录制
  1397. this.mediaRecorder.stop();
  1398. // 清空已录制的数据块
  1399. this.recordedChunks = [];
  1400. // 短暂延迟后重新开始录制
  1401. setTimeout(() => {
  1402. this.startBrowserRecording();
  1403. }, 500);
  1404. }
  1405. // 如果是小程序环境,需要重置相机录制
  1406. else if (this.cameraContext) {
  1407. // 停止当前录制
  1408. this.cameraContext.stopRecord({
  1409. success: () => {
  1410. console.log('重置录制:停止当前录制成功');
  1411. // 短暂延迟后重新开始录制
  1412. setTimeout(() => {
  1413. this.startMiniProgramRecording();
  1414. }, 500);
  1415. },
  1416. fail: (err) => {
  1417. console.error('重置录制:停止当前录制失败', err);
  1418. // 尝试直接重新开始录制
  1419. this.startMiniProgramRecording();
  1420. }
  1421. });
  1422. }
  1423. // 显示提示
  1424. uni.showToast({
  1425. title: '请重新开始回答',
  1426. icon: 'none',
  1427. duration: 2000
  1428. });
  1429. },
  1430. // 修复 completeRecordingStop 方法,确保视频正确上传和处理
  1431. completeRecordingStop() {
  1432. console.log('完成录制停止');
  1433. // 隐藏停止录制按钮
  1434. this.showStopRecordingButton = false;
  1435. // 停止录制计时器
  1436. if (this.recordingTimer) {
  1437. clearInterval(this.recordingTimer);
  1438. this.recordingTimer = null;
  1439. }
  1440. // 标记录制已停止
  1441. this.isRecording = false;
  1442. // 显示上传中状态
  1443. this.showUploadStatus = true;
  1444. this.uploadStatusText = '正在处理视频...';
  1445. this.isUploading = true;
  1446. // 根据平台选择不同的停止录制方法
  1447. const systemInfo = uni.getSystemInfoSync();
  1448. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith('mp-');
  1449. if (isMiniProgram) {
  1450. // 小程序环境使用小程序的停止录制API
  1451. this.stopMiniProgramRecording();
  1452. } else {
  1453. // H5/App环境使用MediaRecorder API
  1454. this.stopBrowserRecording();
  1455. }
  1456. },
  1457. // 修复 stopMiniProgramRecording 方法,确保小程序环境下正确停止录制
  1458. stopMiniProgramRecording() {
  1459. console.log('停止小程序录制');
  1460. if (!this.cameraContext) {
  1461. console.error('相机上下文不存在');
  1462. this.handleRecordingError(new Error('相机上下文不存在'));
  1463. return;
  1464. }
  1465. try {
  1466. // 显示加载提示
  1467. uni.showLoading({
  1468. title: '正在处理视频...',
  1469. mask: true
  1470. });
  1471. // 停止录制
  1472. this.cameraContext.stopRecord({
  1473. success: (res) => {
  1474. console.log('停止录制成功:', res);
  1475. // 隐藏加载提示
  1476. uni.hideLoading();
  1477. // 获取视频临时路径
  1478. const tempVideoPath = res.tempVideoPath || res.tempFilePath;
  1479. if (tempVideoPath) {
  1480. console.log('获取到视频临时路径:', tempVideoPath);
  1481. // 上传视频
  1482. this.uploadRecordedVideo(tempVideoPath);
  1483. } else {
  1484. console.error('未获取到视频临时路径');
  1485. this.handleRecordingError(new Error('未获取到视频临时路径'));
  1486. }
  1487. },
  1488. fail: (err) => {
  1489. console.error('停止录制失败:', err);
  1490. uni.hideLoading();
  1491. this.handleRecordingError(err);
  1492. }
  1493. });
  1494. } catch (e) {
  1495. console.error('停止录制异常:', e);
  1496. uni.hideLoading();
  1497. this.handleRecordingError(e);
  1498. }
  1499. },
  1500. // 添加新方法:停止浏览器录制
  1501. stopBrowserRecording() {
  1502. if (this.mediaRecorder && this.mediaRecorder.state !== 'inactive') {
  1503. this.mediaRecorder.stop();
  1504. console.log('浏览器录制停止成功');
  1505. } else {
  1506. console.error('MediaRecorder不存在或已经停止');
  1507. this.proceedToNextQuestion();
  1508. }
  1509. },
  1510. // 修复 uploadRecordedVideo 方法,确保视频正确上传到服务器
  1511. uploadRecordedVideo(videoPath) {
  1512. console.log('开始上传录制的视频:', videoPath);
  1513. // 保存最后上传的视频路径,用于可能的重试
  1514. this.lastVideoToRetry = videoPath;
  1515. // 显示上传状态
  1516. this.showUploadStatus = true;
  1517. this.uploadStatusText = '正在上传视频...';
  1518. this.isUploading = true;
  1519. // 保存上传状态到本地存储
  1520. this.saveUploadStatus();
  1521. // 获取用户信息和租户ID
  1522. const tenant_id = uni.getStorageSync('tenant_id') || '1';
  1523. const openid = uni.getStorageSync('userInfo') ? JSON.parse(uni.getStorageSync('userInfo')).openid : '';
  1524. const application_id = uni.getStorageSync('appId') || '';
  1525. // 使用uni.uploadFile上传视频
  1526. const uploadTask = uni.uploadFile({
  1527. url: `${apiBaseUrl}/api/upload/`,
  1528. filePath: videoPath,
  1529. name: 'file',
  1530. formData: {
  1531. tenant_id: tenant_id,
  1532. openid: openid,
  1533. application_id: application_id,
  1534. biz_type: 'interview_video',
  1535. video_duration: this.recordingTimerCount || 0,
  1536. has_audio: 'true' // 明确标记包含音频
  1537. },
  1538. success: (uploadRes) => {
  1539. console.log('视频上传成功:', uploadRes);
  1540. try {
  1541. // 解析响应数据
  1542. const result = typeof uploadRes.data === 'string' ? JSON.parse(uploadRes.data) : uploadRes.data;
  1543. if ((result.success || result.code === 2000) && (result.data?.url || result.data?.permanent_link)) {
  1544. // 上传成功,获取视频URL
  1545. const videoUrl = result.data.url || result.data.permanent_link || '';
  1546. console.log('视频URL:', videoUrl);
  1547. // 更新上传状态
  1548. this.uploadStatusText = '视频处理完成,正在分析...';
  1549. // 保存上传状态
  1550. this.saveUploadStatus();
  1551. // 提交视频到AI语音交互接口
  1552. this.submitToAiVoiceInteraction(videoUrl);
  1553. } else {
  1554. console.error('上传响应格式错误:', result);
  1555. const errorMsg = result.msg || result.message || '上传响应格式错误';
  1556. this.handleUploadError(new Error(errorMsg));
  1557. }
  1558. } catch (e) {
  1559. console.error('解析上传响应失败:', e);
  1560. this.handleUploadError(e);
  1561. }
  1562. },
  1563. fail: (err) => {
  1564. console.error('视频上传失败:', err);
  1565. // 提供更友好的错误信息
  1566. let errorMessage = '网络错误,请检查网络连接';
  1567. if (err.errMsg) {
  1568. if (err.errMsg.includes('timeout')) {
  1569. errorMessage = '上传超时,请检查网络连接';
  1570. } else if (err.errMsg.includes('fail')) {
  1571. errorMessage = '上传失败: ' + err.errMsg;
  1572. }
  1573. }
  1574. this.handleUploadError(new Error(errorMessage));
  1575. },
  1576. complete: () => {
  1577. // 隐藏上传状态
  1578. this.showUploadStatus = false;
  1579. this.isUploading = false;
  1580. // 更新上传状态
  1581. this.saveUploadStatus();
  1582. }
  1583. });
  1584. // 监听上传进度
  1585. uploadTask.onProgressUpdate((res) => {
  1586. console.log('上传进度:', res.progress);
  1587. this.uploadStatusText = `正在上传视频... ${res.progress}%`;
  1588. // 如果上传速度过慢,提供提示
  1589. if (res.progress < 10 && res.totalTimeMs > 10000) {
  1590. this.uploadStatusText = `上传速度较慢,请耐心等待... ${res.progress}%`;
  1591. }
  1592. });
  1593. },
  1594. // 修改 processUploadQueue 方法,添加后台上传支持
  1595. processUploadQueue() {
  1596. // 如果队列为空,结束处理
  1597. if (this.uploadQueue.length === 0) {
  1598. this.isUploading = false;
  1599. this.showUploadStatus = false;
  1600. // 清除上传状态
  1601. try {
  1602. uni.removeStorageSync('videoUploadStatus');
  1603. } catch (e) {
  1604. console.error('清除上传状态失败:', e);
  1605. }
  1606. // 发送上传完成通知
  1607. this.notifyUploadComplete();
  1608. return;
  1609. }
  1610. // 标记为正在上传
  1611. this.isUploading = true;
  1612. this.showUploadStatus = true;
  1613. // 获取队列中的第一个任务
  1614. const task = this.uploadQueue[0];
  1615. // 更新任务状态
  1616. this.uploadStatus[task.id] = 'uploading';
  1617. this.updateUploadStatusText();
  1618. // 增加尝试次数
  1619. task.attempts++;
  1620. // 根据文件类型选择上传方法
  1621. if (typeof task.file !== 'string') {
  1622. // 浏览器环境,使用XMLHttpRequest上传
  1623. this.uploadFileWithXHR(task);
  1624. } else {
  1625. // 小程序环境,使用uni.uploadFile上传
  1626. this.uploadFileWithUni(task);
  1627. }
  1628. // 更新上传状态到本地存储
  1629. this.saveUploadStatus();
  1630. },
  1631. // 添加新方法:发送上传完成通知
  1632. notifyUploadComplete() {
  1633. // 使用uni.postMessage在页面间通信(小程序环境)
  1634. try {
  1635. uni.$emit('videoUploadComplete', {
  1636. timestamp: Date.now()
  1637. });
  1638. console.log('发送上传完成通知');
  1639. } catch (e) {
  1640. console.error('发送上传完成通知失败:', e);
  1641. }
  1642. // 如果在App环境,可以使用本地通知
  1643. const systemInfo = uni.getSystemInfoSync();
  1644. if (systemInfo.platform === 'android' || systemInfo.platform === 'ios') {
  1645. // 检查是否支持本地通知
  1646. if (plus && plus.push) {
  1647. plus.push.createMessage('视频上传完成', '您的面试视频已成功上传', {});
  1648. }
  1649. }
  1650. },
  1651. // 添加新方法:使用XMLHttpRequest上传文件
  1652. uploadFileWithXHR(task) {
  1653. // 获取用户信息
  1654. const userInfo = uni.getStorageSync('userInfo');
  1655. const openid = userInfo ? (JSON.parse(userInfo).openid || '') : '';
  1656. const tenant_id = uni.getStorageSync('tenant_id') || '1';
  1657. // 创建FormData
  1658. const formData = new FormData();
  1659. formData.append('file', task.file);
  1660. formData.append('openid', openid);
  1661. formData.append('tenant_id', tenant_id);
  1662. formData.append('application_id', uni.getStorageSync('appId'));
  1663. formData.append('question_id', task.questionId);
  1664. formData.append('video_duration', this.recordingTimerCount || 0);
  1665. formData.append('has_audio', 'true'); // 明确标记包含音频
  1666. // 创建XMLHttpRequest
  1667. const xhr = new XMLHttpRequest();
  1668. xhr.open('POST', `${apiBaseUrl}/api/upload/`, true);
  1669. xhr.timeout = 120000; // 2分钟超时
  1670. // 监听上传进度
  1671. xhr.upload.onprogress = (event) => {
  1672. if (event.lengthComputable) {
  1673. const percentComplete = Math.round((event.loaded / event.total) * 100);
  1674. this.uploadProgress[task.id] = percentComplete;
  1675. this.updateUploadStatusText();
  1676. }
  1677. };
  1678. // 监听请求完成
  1679. xhr.onload = () => {
  1680. if (xhr.status === 200) {
  1681. try {
  1682. const res = JSON.parse(xhr.responseText);
  1683. console.log('上传响应:', res);
  1684. if (res.code === 2000) {
  1685. // 获取上传后的视频URL
  1686. const videoUrl = res.data.url || res.data.photoUrl || '';
  1687. if (videoUrl) {
  1688. // 上传成功,更新状态
  1689. this.uploadStatus[task.id] = 'success';
  1690. this.updateUploadStatusText();
  1691. // 提交到面试接口
  1692. this.submitVideoToInterview(videoUrl, task);
  1693. } else {
  1694. this.handleUploadFailure(task, '视频URL获取失败');
  1695. }
  1696. } else {
  1697. this.handleUploadFailure(task, res.msg || '上传失败');
  1698. }
  1699. } catch (e) {
  1700. this.handleUploadFailure(task, '解析响应失败');
  1701. }
  1702. } else {
  1703. this.handleUploadFailure(task, 'HTTP状态: ' + xhr.status);
  1704. }
  1705. };
  1706. // 监听错误
  1707. xhr.onerror = () => {
  1708. this.handleUploadFailure(task, '网络错误');
  1709. };
  1710. // 监听超时
  1711. xhr.ontimeout = () => {
  1712. this.handleUploadFailure(task, '上传超时');
  1713. };
  1714. // 发送请求
  1715. xhr.send(formData);
  1716. },
  1717. // 添加新方法:使用uni.uploadFile上传文件
  1718. uploadFileWithUni(task) {
  1719. // 获取用户信息
  1720. const userInfo = uni.getStorageSync('userInfo');
  1721. const openid = userInfo ? (JSON.parse(userInfo).openid || '') : '';
  1722. const tenant_id = uni.getStorageSync('tenant_id') || '1';
  1723. // 创建上传任务
  1724. const uploadTask = uni.uploadFile({
  1725. url: `${apiBaseUrl}/api/upload/`,
  1726. filePath: task.file,
  1727. name: 'file',
  1728. formData: {
  1729. openid: openid,
  1730. tenant_id: tenant_id,
  1731. application_id: uni.getStorageSync('appId'),
  1732. question_id: task.questionId,
  1733. video_duration: this.recordingTimerCount || 0,
  1734. has_audio: 'true' // 明确标记包含音频
  1735. },
  1736. success: (uploadRes) => {
  1737. try {
  1738. const res = JSON.parse(uploadRes.data);
  1739. console.log('上传响应:', res);
  1740. if (res.code === 2000) {
  1741. // 获取上传后的视频URL
  1742. const videoUrl = res.data.permanent_link || res.data.url || '';
  1743. if (videoUrl) {
  1744. // 上传成功,更新状态
  1745. this.uploadStatus[task.id] = 'success';
  1746. this.updateUploadStatusText();
  1747. // 提交到面试接口
  1748. this.submitVideoToInterview(videoUrl, task);
  1749. } else {
  1750. this.handleUploadFailure(task, '视频URL获取失败');
  1751. }
  1752. } else {
  1753. this.handleUploadFailure(task, res.msg || '上传失败');
  1754. }
  1755. } catch (e) {
  1756. this.handleUploadFailure(task, '解析响应失败');
  1757. }
  1758. },
  1759. fail: (err) => {
  1760. this.handleUploadFailure(task, err.errMsg || '上传失败');
  1761. }
  1762. });
  1763. // 监听上传进度
  1764. uploadTask.onProgressUpdate((res) => {
  1765. this.uploadProgress[task.id] = res.progress;
  1766. this.updateUploadStatusText();
  1767. });
  1768. },
  1769. // 添加新方法:处理上传失败
  1770. handleUploadFailure(task, errorMsg) {
  1771. console.error('上传失败:', errorMsg);
  1772. // 更新任务状态
  1773. this.uploadStatus[task.id] = 'failed';
  1774. this.updateUploadStatusText();
  1775. // 检查是否还有重试机会
  1776. if (task.attempts < task.maxAttempts) {
  1777. console.log(`将在5秒后重试上传,当前尝试次数: ${task.attempts}/${task.maxAttempts}`);
  1778. // 5秒后重试
  1779. setTimeout(() => {
  1780. // 重置进度
  1781. this.uploadProgress[task.id] = 0;
  1782. // 重新开始上传
  1783. if (typeof task.file !== 'string') {
  1784. this.uploadFileWithXHR(task);
  1785. } else {
  1786. this.uploadFileWithUni(task);
  1787. }
  1788. }, 5000);
  1789. } else {
  1790. // 超过最大重试次数,移除任务并继续处理队列
  1791. console.log('超过最大重试次数,放弃上传');
  1792. // 显示错误提示
  1793. uni.showToast({
  1794. title: '视频上传失败,请稍后重试',
  1795. icon: 'none',
  1796. duration: 2000
  1797. });
  1798. // 从队列中移除当前任务
  1799. this.uploadQueue.shift();
  1800. // 继续处理队列中的下一个任务
  1801. this.processUploadQueue();
  1802. }
  1803. },
  1804. // 修改 submitVideoToInterview 方法
  1805. submitVideoToInterview(videoUrl, task = null) {
  1806. console.log('提交视频URL到面试接口:', videoUrl);
  1807. // 确定问题ID
  1808. let questionId;
  1809. if (task) {
  1810. questionId = task.questionId;
  1811. } else {
  1812. // 根据当前视频索引映射到正确的问题ID(兼容旧代码)
  1813. switch(this.currentVideoIndex) {
  1814. case 1:
  1815. questionId = 36;
  1816. break;
  1817. case 2:
  1818. questionId = 11;
  1819. break;
  1820. case 3:
  1821. questionId = 12;
  1822. break;
  1823. case 4:
  1824. questionId = 13;
  1825. break;
  1826. default:
  1827. questionId = 10;
  1828. }
  1829. }
  1830. // 准备请求参数
  1831. const requestData = {
  1832. application_id: uni.getStorageSync('appId'),
  1833. question_id: questionId,
  1834. video_url: videoUrl,
  1835. tenant_id: uni.getStorageSync('tenant_id') || '1',
  1836. has_audio: true // 明确标记包含音频
  1837. };
  1838. // 首先提交到面试接口
  1839. /* uni.request({
  1840. url: `${apiBaseUrl}/api/job/upload_video`,
  1841. method: 'POST',
  1842. data: requestData,
  1843. header: {
  1844. 'content-type': 'application/x-www-form-urlencoded'
  1845. },
  1846. success: (res) => {
  1847. console.log('面试接口提交成功:', res);
  1848. if (res.data.code === 0 || res.data.code === 2000) {
  1849. // 提交成功
  1850. if (task) {
  1851. // 从队列中移除当前任务
  1852. this.uploadQueue.shift();
  1853. // 继续处理队列中的下一个任务
  1854. this.processUploadQueue();
  1855. } else {
  1856. // 兼容旧代码的处理逻辑
  1857. uni.showToast({
  1858. title: '回答已提交',
  1859. icon: 'success'
  1860. });
  1861. // 保存最后上传的视频URL
  1862. this.lastUploadedVideoUrl = videoUrl;
  1863. // 隐藏重试按钮(如果之前显示了)
  1864. this.showRetryButton = false;
  1865. this.lastVideoToRetry = null;
  1866. }
  1867. // 提交到AI语音交互接口
  1868. } else {
  1869. // 提交失败
  1870. if (task) {
  1871. this.handleSubmitFailure(task, res.data.msg || '提交失败');
  1872. } else {
  1873. // 兼容旧代码的处理逻辑
  1874. uni.showToast({
  1875. title: res.data.msg || '提交失败,请重试',
  1876. icon: 'none'
  1877. });
  1878. // 保存失败的视频URL,用于重试
  1879. this.lastVideoToRetry = videoUrl;
  1880. // 显示重试按钮
  1881. this.showRetryButton = true;
  1882. }
  1883. }
  1884. },
  1885. fail: (err) => {
  1886. console.error('面试接口提交失败:', err);
  1887. if (task) {
  1888. this.handleSubmitFailure(task, err.errMsg || '网络错误');
  1889. } else {
  1890. // 兼容旧代码的处理逻辑
  1891. uni.hideLoading();
  1892. uni.showToast({
  1893. title: '网络错误,请重试',
  1894. icon: 'none'
  1895. });
  1896. // 保存失败的视频URL,用于重试
  1897. this.lastVideoToRetry = videoUrl;
  1898. // 显示重试按钮
  1899. this.showRetryButton = true;
  1900. }
  1901. }
  1902. }); */
  1903. this.submitToAiVoiceInteraction(videoUrl);
  1904. },
  1905. // 添加新方法:处理提交失败
  1906. handleSubmitFailure(task, errorMsg) {
  1907. console.error('提交失败:', errorMsg);
  1908. // 更新任务状态
  1909. this.uploadStatus[task.id] = 'failed';
  1910. this.updateUploadStatusText();
  1911. // 检查是否还有重试机会
  1912. if (task.attempts < task.maxAttempts) {
  1913. console.log(`将在5秒后重试提交,当前尝试次数: ${task.attempts}/${task.maxAttempts}`);
  1914. // 5秒后重试
  1915. setTimeout(() => {
  1916. // 重新提交
  1917. this.submitVideoToInterview(task.videoUrl, task);
  1918. }, 5000);
  1919. } else {
  1920. // 超过最大重试次数,移除任务并继续处理队列
  1921. console.log('超过最大重试次数,放弃提交');
  1922. // 显示错误提示
  1923. uni.showToast({
  1924. title: '视频提交失败,请稍后重试',
  1925. icon: 'none',
  1926. duration: 2000
  1927. });
  1928. // 从队列中移除当前任务
  1929. this.uploadQueue.shift();
  1930. // 继续处理队列中的下一个任务
  1931. this.processUploadQueue();
  1932. }
  1933. },
  1934. // 添加新方法:更新上传状态文本
  1935. updateUploadStatusText() {
  1936. if (this.uploadQueue.length === 0) {
  1937. this.uploadStatusText = '';
  1938. return;
  1939. }
  1940. const currentTask = this.uploadQueue[0];
  1941. const progress = this.uploadProgress[currentTask.id] || 0;
  1942. const status = this.uploadStatus[currentTask.id] || 'pending';
  1943. let statusText = '';
  1944. switch (status) {
  1945. case 'pending':
  1946. statusText = '等待上传';
  1947. break;
  1948. case 'uploading':
  1949. statusText = `上传中 ${progress}%`;
  1950. break;
  1951. case 'success':
  1952. statusText = '上传成功,提交中...';
  1953. break;
  1954. case 'failed':
  1955. statusText = `上传失败,${currentTask.attempts < currentTask.maxAttempts ? '即将重试' : '已放弃'}`;
  1956. break;
  1957. }
  1958. this.uploadStatusText = `问题${currentTask.questionId - 9}:${statusText}`;
  1959. // 如果队列中有多个任务,显示总数
  1960. if (this.uploadQueue.length > 1) {
  1961. this.uploadStatusText += ` (${this.uploadQueue.length}个视频待处理)`;
  1962. }
  1963. },
  1964. // 修改 proceedToNextQuestion 方法
  1965. proceedToNextQuestion() {
  1966. console.log('准备跳转到下一页面');
  1967. // 如果正在播放AI语音,不立即跳转
  1968. if (this.isPlayingAiVoice) {
  1969. console.log('AI语音正在播放,等待播放完成后再跳转');
  1970. return;
  1971. }
  1972. // 不再等待上传队列完成,直接跳转
  1973. // this.navigateToNextPage();
  1974. // 如果有未完成的上传任务,在后台继续处理
  1975. if (this.uploadQueue.length > 0) {
  1976. console.log('上传队列将在后台继续处理...');
  1977. // 保存上传状态到本地存储,以便在其他页面可以查看
  1978. this.saveUploadStatus();
  1979. }
  1980. },
  1981. // 修改 navigateToNextPage 方法
  1982. navigateToNextPage() {
  1983. console.log('执行页面跳转');
  1984. // 确保清理音频相关状态
  1985. this.isPlayingAiVoice = false;
  1986. this.currentSubtitle = '';
  1987. // 添加延迟确保状态已更新
  1988. setTimeout(() => {
  1989. uni.navigateTo({
  1990. url: '/pages/success/success',
  1991. success: () => {
  1992. console.log('页面跳转成功');
  1993. },
  1994. fail: (err) => {
  1995. console.error('页面跳转失败:', err);
  1996. uni.showToast({
  1997. title: '页面跳转失败',
  1998. icon: 'none',
  1999. duration: 2000
  2000. });
  2001. }
  2002. });
  2003. }, 100);
  2004. },
  2005. // 添加处理导航失败的方法
  2006. handleNavigationFailure() {
  2007. // 尝试跳转到其他页面
  2008. uni.navigateTo({
  2009. url: '/pages/success/success',//'/pages/posture-guide/posture-guide',
  2010. fail: (err2) => {
  2011. console.error('备用跳转也失败:', err2);
  2012. // 最后尝试返回上一页
  2013. uni.navigateBack({
  2014. delta: 1
  2015. });
  2016. }
  2017. });
  2018. },
  2019. // 修改 handleAnswerButtonClick 方法
  2020. handleAnswerButtonClick() {
  2021. // 隐藏答题按钮
  2022. this.showAnswerButton = false;
  2023. // 显示简短提示
  2024. uni.showToast({
  2025. title: '面试完成',
  2026. icon: 'success',
  2027. duration: 500 // 只显示0.5秒
  2028. });
  2029. // 如果有最后上传的视频URL,提交到AI语音交互接口
  2030. if (this.lastUploadedVideoUrl) {
  2031. this.submitToAiVoiceInteraction(this.lastUploadedVideoUrl);
  2032. } else {
  2033. // 没有视频URL,直接跳转
  2034. this.navigateToNextPage();
  2035. }
  2036. },
  2037. // 处理相机错误
  2038. handleCameraError(e) {
  2039. console.error('相机错误:', e);
  2040. // 获取平台信息
  2041. const systemInfo = uni.getSystemInfoSync();
  2042. const isIOS = systemInfo.platform === 'ios';
  2043. if (isIOS) {
  2044. console.log('iOS相机错误,尝试重新初始化');
  2045. // 显示提示
  2046. uni.showToast({
  2047. title: '相机初始化中...',
  2048. icon: 'loading',
  2049. duration: 2000
  2050. });
  2051. // 重置相机
  2052. this.resetCamera();
  2053. // 如果正在录制,停止录制
  2054. if (this.isRecording) {
  2055. this.isRecording = false;
  2056. this.showStopRecordingButton = false;
  2057. // 提供替代选项
  2058. setTimeout(() => {
  2059. this.useAlternativeRecordingMethod();
  2060. }, 1000);
  2061. }
  2062. } else {
  2063. // 显示错误提示
  2064. uni.showToast({
  2065. title: '相机初始化失败,请检查权限设置',
  2066. icon: 'none'
  2067. });
  2068. // 尝试备用选项
  2069. this.tryFallbackOptions();
  2070. }
  2071. },
  2072. // 添加新方法:尝试备用选项
  2073. tryFallbackOptions() {
  2074. // 检查环境
  2075. const systemInfo = uni.getSystemInfoSync();
  2076. // 在小程序环境中使用小程序API
  2077. if (systemInfo.uniPlatform === 'mp-weixin' || systemInfo.uniPlatform === 'mp-alipay') {
  2078. this.useMiniProgramCamera();
  2079. }
  2080. // 在H5环境中显示静态图像
  2081. else {
  2082. this.showStaticCameraPlaceholder();
  2083. }
  2084. },
  2085. // 添加新方法:使用小程序相机API
  2086. useMiniProgramCamera() {
  2087. console.log('尝试使用小程序相机组件');
  2088. // 这里需要在模板中添加小程序相机组件
  2089. // 并设置一个标志来控制显示
  2090. this.useMiniProgramCameraComponent = true;
  2091. },
  2092. // 添加新方法:显示静态图像
  2093. showStaticCameraPlaceholder() {
  2094. console.log('显示静态摄像头占位图');
  2095. // 创建一个图像元素
  2096. const img = document.createElement('img');
  2097. img.src = '/static/images/camera-placeholder.png'; // 确保有这个图片资源
  2098. img.className = 'static-camera-image';
  2099. img.style.width = '100%';
  2100. img.style.height = '100%';
  2101. img.style.objectFit = 'cover';
  2102. // 获取容器并添加图像
  2103. const container = this.$refs.userCameraVideo.parentNode;
  2104. container.appendChild(img);
  2105. },
  2106. // 处理视频时间更新事件
  2107. handleTimeUpdate(e) {
  2108. // 获取当前视频播放时间
  2109. const currentTime = e.target.currentTime;
  2110. // 如果正在录制,更新录制时间显示
  2111. if (this.isRecording && this.recordingTimerCount) {
  2112. this.recordingTimeDisplay = this.formatTime(this.recordingTimerCount);
  2113. }
  2114. // 根据当前播放的视频索引选择对应的字幕数组
  2115. let currentSubtitles;
  2116. if (this.currentVideoIndex === 0) {
  2117. currentSubtitles = this.subtitles;
  2118. } else if (this.currentVideoIndex === 1) {
  2119. currentSubtitles = this.secondVideoSubtitles;
  2120. } else if (this.currentVideoIndex === 2) {
  2121. currentSubtitles = this.thirdVideoSubtitles;
  2122. } else if (this.currentVideoIndex === 3) {
  2123. currentSubtitles = this.fourthVideoSubtitles;
  2124. } else if (this.currentVideoIndex === 4) {
  2125. currentSubtitles = this.fifthVideoSubtitles;
  2126. } else if (this.currentVideoIndex === 5) {
  2127. currentSubtitles = this.sixthVideoSubtitles;
  2128. } else {
  2129. // 如果有更多视频,可以继续添加条件
  2130. currentSubtitles = [];
  2131. }
  2132. // 查找当前时间应该显示的字幕
  2133. const subtitle = currentSubtitles.find(
  2134. sub => currentTime >= sub.startTime && currentTime < sub.endTime
  2135. );
  2136. // 更新当前字幕
  2137. this.currentSubtitle = subtitle ? subtitle.text : '';
  2138. },
  2139. // Add a new method to handle the "Start Recording" button click
  2140. handleStartRecordingClick() {
  2141. // 隐藏"开始回答"按钮
  2142. this.showStartRecordingButton = false;
  2143. // 如果倒计时正在进行,清除倒计时
  2144. this.clearCountdown();
  2145. // 开始录制
  2146. this.startRecordingAnswer();
  2147. },
  2148. // 修改 checkAudioPermission 方法,确保在录制前获取音频权限
  2149. checkAudioPermission() {
  2150. // 在小程序环境中
  2151. const systemInfo = uni.getSystemInfoSync();
  2152. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith('mp-');
  2153. if (isMiniProgram) {
  2154. // 小程序环境下的权限请求
  2155. uni.getSetting({
  2156. success: (res) => {
  2157. if (!res.authSetting['scope.record']) {
  2158. uni.authorize({
  2159. scope: 'scope.record',
  2160. success: () => {
  2161. console.log('录音权限已获取');
  2162. },
  2163. fail: (err) => {
  2164. console.error('录音权限获取失败:', err);
  2165. this.showPermissionDialog('录音');
  2166. }
  2167. });
  2168. }
  2169. if (!res.authSetting['scope.camera']) {
  2170. uni.authorize({
  2171. scope: 'scope.camera',
  2172. success: () => {
  2173. console.log('相机权限已获取');
  2174. },
  2175. fail: (err) => {
  2176. console.error('相机权限获取失败:', err);
  2177. this.showPermissionDialog('相机');
  2178. }
  2179. });
  2180. }
  2181. }
  2182. });
  2183. } else {
  2184. // 浏览器环境下的权限请求
  2185. // ... 保持原有代码不变
  2186. }
  2187. },
  2188. // 添加新方法:测试音频输入
  2189. testAudioInput() {
  2190. if (!this.cameraStream) {
  2191. console.warn('没有可用的媒体流,无法测试音频');
  2192. return;
  2193. }
  2194. const audioTracks = this.cameraStream.getAudioTracks();
  2195. if (audioTracks.length === 0) {
  2196. console.warn('没有检测到音频轨道,尝试重新获取');
  2197. this.tryGetAudioOnly();
  2198. return;
  2199. }
  2200. console.log('音频轨道信息:', audioTracks[0].getSettings());
  2201. // 创建音频上下文和分析器
  2202. try {
  2203. const AudioContext = window.AudioContext || window.webkitAudioContext;
  2204. if (!AudioContext) {
  2205. console.warn('浏览器不支持AudioContext');
  2206. return;
  2207. }
  2208. const audioContext = new AudioContext();
  2209. const analyser = audioContext.createAnalyser();
  2210. const microphone = audioContext.createMediaStreamSource(this.cameraStream);
  2211. microphone.connect(analyser);
  2212. // 设置分析器
  2213. analyser.fftSize = 256;
  2214. const bufferLength = analyser.frequencyBinCount;
  2215. const dataArray = new Uint8Array(bufferLength);
  2216. // 检测音频输入
  2217. let silenceCounter = 0;
  2218. const checkAudio = () => {
  2219. if (this.isRecording) return; // 如果正在录制,停止检测
  2220. analyser.getByteFrequencyData(dataArray);
  2221. // 计算平均音量
  2222. let sum = 0;
  2223. for (let i = 0; i < bufferLength; i++) {
  2224. sum += dataArray[i];
  2225. }
  2226. const average = sum / bufferLength;
  2227. if (average > 10) {
  2228. console.log('检测到音频输入,音量:', average);
  2229. silenceCounter = 0;
  2230. } else {
  2231. silenceCounter++;
  2232. if (silenceCounter > 10) {
  2233. console.warn('持续检测不到音频输入,可能麦克风未正常工作');
  2234. silenceCounter = 0;
  2235. }
  2236. }
  2237. // 继续检测
  2238. requestAnimationFrame(checkAudio);
  2239. };
  2240. // 开始检测
  2241. checkAudio();
  2242. } catch (e) {
  2243. console.error('音频测试失败:', e);
  2244. }
  2245. },
  2246. // 添加新方法:尝试单独获取音频
  2247. tryGetAudioOnly() {
  2248. navigator.mediaDevices.getUserMedia({ audio: true })
  2249. .then(audioStream => {
  2250. // 如果已有视频流,合并音频和视频轨道
  2251. if (this.cameraStream) {
  2252. const videoTrack = this.cameraStream.getVideoTracks()[0];
  2253. const audioTrack = audioStream.getAudioTracks()[0];
  2254. // 创建新的媒体流,包含视频和音频轨道
  2255. const combinedStream = new MediaStream();
  2256. if (videoTrack) combinedStream.addTrack(videoTrack);
  2257. if (audioTrack) combinedStream.addTrack(audioTrack);
  2258. // 更新摄像头流
  2259. this.cameraStream = combinedStream;
  2260. // 更新视频元素的源
  2261. const videoElement = this.$refs.userCameraVideo;
  2262. if (videoElement) {
  2263. videoElement.srcObject = combinedStream;
  2264. videoElement.muted = true; // 避免回声,但仍然录制声音
  2265. }
  2266. console.log('成功合并音频和视频轨道');
  2267. } else {
  2268. console.warn('没有视频流可合并');
  2269. }
  2270. })
  2271. .catch(err => {
  2272. console.error('单独获取音频失败:', err);
  2273. });
  2274. },
  2275. // 添加新方法:显示权限对话框
  2276. showPermissionDialog(permissionType) {
  2277. uni.showModal({
  2278. title: '需要权限',
  2279. content: `请允许使用${permissionType}权限,否则可能影响面试功能`,
  2280. confirmText: '去设置',
  2281. success: (res) => {
  2282. if (res.confirm) {
  2283. uni.openSetting({
  2284. success: (settingRes) => {
  2285. console.log('设置页面打开成功', settingRes);
  2286. }
  2287. });
  2288. }
  2289. }
  2290. });
  2291. },
  2292. // 添加重试上传方法
  2293. retryVideoUpload() {
  2294. if (this.lastVideoToRetry) {
  2295. // 隐藏重试按钮
  2296. this.showRetryButton = false;
  2297. // 显示加载提示
  2298. uni.showLoading({
  2299. title: '正在重新提交...',
  2300. mask: true
  2301. });
  2302. // 重新提交视频
  2303. this.submitVideoToInterview(this.lastVideoToRetry);
  2304. } else {
  2305. uni.showToast({
  2306. title: '没有可重试的视频',
  2307. icon: 'none'
  2308. });
  2309. }
  2310. },
  2311. // 添加一个新方法用于压缩视频
  2312. async compressVideo(videoBlob) {
  2313. // 如果视频大小小于某个阈值,直接返回原视频
  2314. if (videoBlob.size < 5 * 1024 * 1024) { // 小于5MB
  2315. return videoBlob;
  2316. }
  2317. console.log('开始压缩视频,原始大小:', videoBlob.size);
  2318. // 创建一个视频元素来加载视频
  2319. const videoElement = document.createElement('video');
  2320. videoElement.muted = true;
  2321. videoElement.autoplay = false;
  2322. // 创建一个canvas元素用于绘制视频帧
  2323. const canvas = document.createElement('canvas');
  2324. const ctx = canvas.getContext('2d');
  2325. // 设置视频源
  2326. videoElement.src = URL.createObjectURL(videoBlob);
  2327. return new Promise((resolve) => {
  2328. videoElement.onloadedmetadata = () => {
  2329. // 设置canvas尺寸为视频的一半
  2330. const width = Math.floor(videoElement.videoWidth / 2);
  2331. const height = Math.floor(videoElement.videoHeight / 2);
  2332. canvas.width = width;
  2333. canvas.height = height;
  2334. // 创建MediaRecorder来录制canvas
  2335. const stream = canvas.captureStream(15); // 15fps
  2336. // 如果原视频有音轨,添加到新流中
  2337. if (videoElement.captureStream) {
  2338. const originalStream = videoElement.captureStream();
  2339. const audioTracks = originalStream.getAudioTracks();
  2340. if (audioTracks.length > 0) {
  2341. stream.addTrack(audioTracks[0]);
  2342. }
  2343. }
  2344. // 设置较低的比特率
  2345. const options = {
  2346. mimeType: 'video/webm;codecs=vp8,opus',
  2347. audioBitsPerSecond: 64000,
  2348. videoBitsPerSecond: 800000 // 800kbps
  2349. };
  2350. const mediaRecorder = new MediaRecorder(stream, options);
  2351. const chunks = [];
  2352. mediaRecorder.ondataavailable = (e) => {
  2353. if (e.data.size > 0) {
  2354. chunks.push(e.data);
  2355. }
  2356. };
  2357. mediaRecorder.onstop = () => {
  2358. const compressedBlob = new Blob(chunks, { type: 'video/webm' });
  2359. console.log('视频压缩完成,压缩后大小:', compressedBlob.size);
  2360. resolve(compressedBlob);
  2361. };
  2362. // 开始播放视频并录制
  2363. videoElement.onplay = () => {
  2364. mediaRecorder.start(100);
  2365. // 绘制视频帧到canvas
  2366. const drawFrame = () => {
  2367. if (videoElement.paused || videoElement.ended) {
  2368. mediaRecorder.stop();
  2369. return;
  2370. }
  2371. ctx.drawImage(videoElement, 0, 0, width, height);
  2372. requestAnimationFrame(drawFrame);
  2373. };
  2374. drawFrame();
  2375. };
  2376. videoElement.play();
  2377. };
  2378. });
  2379. },
  2380. // 修改 checkIOSCameraRecordPermission 方法
  2381. checkIOSCameraRecordPermission() {
  2382. const systemInfo = uni.getSystemInfoSync();
  2383. if (systemInfo.platform !== 'ios') return;
  2384. // 在iOS上,需要同时请求相机和录音权限
  2385. uni.getSetting({
  2386. success: (res) => {
  2387. // 检查相机权限
  2388. if (!res.authSetting['scope.camera']) {
  2389. uni.authorize({
  2390. scope: 'scope.camera',
  2391. success: () => {
  2392. console.log('iOS相机权限已获取');
  2393. },
  2394. fail: (err) => {
  2395. console.error('iOS相机权限获取失败:', err);
  2396. this.showPermissionDialog('相机');
  2397. }
  2398. });
  2399. }
  2400. // 检查录音权限
  2401. if (!res.authSetting['scope.record']) {
  2402. uni.authorize({
  2403. scope: 'scope.record',
  2404. success: () => {
  2405. console.log('iOS录音权限已获取');
  2406. },
  2407. fail: (err) => {
  2408. console.error('iOS录音权限获取失败:', err);
  2409. this.showPermissionDialog('录音');
  2410. }
  2411. });
  2412. }
  2413. }
  2414. });
  2415. },
  2416. // 添加新方法:检查并修复渲染问题
  2417. checkAndFixRenderingIssues() {
  2418. // 检查全局对象,防止渲染错误
  2419. try {
  2420. // 检查是否有全局变量u
  2421. if (typeof u !== 'undefined' && u) {
  2422. // 检查currentQuestion属性
  2423. if (!u.currentQuestion) {
  2424. console.log('修复: 创建缺失的currentQuestion对象');
  2425. u.currentQuestion = {};
  2426. }
  2427. // 确保isImportant属性存在
  2428. if (u.currentQuestion && typeof u.currentQuestion.isImportant === 'undefined') {
  2429. console.log('修复: 设置缺失的isImportant属性');
  2430. u.currentQuestion.isImportant = false;
  2431. }
  2432. }
  2433. } catch (e) {
  2434. console.log('防御性检查异常:', e);
  2435. }
  2436. },
  2437. // 添加格式化时间的辅助方法
  2438. formatTime(seconds) {
  2439. if (!seconds && seconds !== 0) return '03:30'; // 默认显示03:30
  2440. const minutes = Math.floor(seconds / 60);
  2441. const remainingSeconds = seconds % 60;
  2442. return `${minutes.toString().padStart(2, '0')}:${remainingSeconds.toString().padStart(2, '0')}`;
  2443. },
  2444. // 添加新方法:保存上传状态到本地存储
  2445. saveUploadStatus() {
  2446. const uploadStatus = {
  2447. isUploading: this.isUploading,
  2448. uploadQueue: this.uploadQueue.length,
  2449. timestamp: Date.now()
  2450. };
  2451. try {
  2452. uni.setStorageSync('videoUploadStatus', JSON.stringify(uploadStatus));
  2453. } catch (e) {
  2454. console.error('保存上传状态失败:', e);
  2455. }
  2456. },
  2457. // 修改 submitToAiVoiceInteraction 方法
  2458. submitToAiVoiceInteraction(videoUrl) {
  2459. console.log('提交视频到AI语音交互接口:', videoUrl);
  2460. // 显示加载提示
  2461. uni.showLoading({
  2462. title: '面试官正在思考...',
  2463. mask: true
  2464. });
  2465. // 获取用户信息和租户ID
  2466. const tenant_id = uni.getStorageSync('tenant_id') || '1';
  2467. const application_id = uni.getStorageSync('appId') || '98'; // 默认为98(报告)
  2468. let positionConfigId = 1;
  2469. if(JSON.parse(uni.getStorageSync('configData'))){
  2470. positionConfigId = JSON.parse(uni.getStorageSync('configData')).id;
  2471. }
  2472. // 准备请求数据
  2473. const requestData = {
  2474. voice_url: videoUrl,
  2475. tenant_id: tenant_id,
  2476. application_id: application_id,
  2477. scene_type: 'interview', // 场景类型:面试
  2478. // voice_type: 'longxiaoxia', // 角色:龙小侠
  2479. position_config_id: positionConfigId,
  2480. conversation_history: this.conversationHistory // 添加对话历史
  2481. };
  2482. // 检查环境
  2483. const systemInfo = uni.getSystemInfoSync();
  2484. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith('mp-');
  2485. if (isMiniProgram) {
  2486. // 小程序环境使用 uni.request
  2487. uni.request({
  2488. url: `${apiBaseUrl}/api/system/voice/mcp/interaction`, // 使用新的接口地址
  2489. method: 'POST',
  2490. data: requestData,
  2491. header: {
  2492. 'content-type': 'application/json' // 修改为JSON格式
  2493. },
  2494. success: (res) => {
  2495. if (res.statusCode === 200) {
  2496. this.handleAiInteractionResponse(res.data);
  2497. } else {
  2498. this.handleAiInteractionError(res.data);
  2499. }
  2500. },
  2501. fail: (err) => {
  2502. this.handleAiInteractionError(err);
  2503. }
  2504. });
  2505. } else {
  2506. // H5/App环境使用 XMLHttpRequest
  2507. const xhr = new XMLHttpRequest();
  2508. xhr.open('POST', `${apiBaseUrl}/api/system/voice/mcp/interaction`, true);
  2509. xhr.timeout = 60000; // 60秒超时
  2510. xhr.setRequestHeader('Content-Type', 'application/json');
  2511. xhr.onload = () => {
  2512. if (xhr.status === 200) {
  2513. try {
  2514. const response = JSON.parse(xhr.responseText);
  2515. this.handleAiInteractionResponse(response);
  2516. } catch (e) {
  2517. console.error('解析AI响应失败:', e);
  2518. this.handleAiInteractionError({ errMsg: '解析响应失败' });
  2519. }
  2520. } else {
  2521. this.handleAiInteractionError({ errMsg: 'HTTP状态: ' + xhr.status });
  2522. }
  2523. };
  2524. xhr.onerror = () => {
  2525. this.handleAiInteractionError({ errMsg: '网络错误' });
  2526. };
  2527. xhr.ontimeout = () => {
  2528. this.handleAiInteractionError({ errMsg: '请求超时' });
  2529. };
  2530. // 发送JSON格式的数据
  2531. xhr.send(JSON.stringify(requestData));
  2532. }
  2533. },
  2534. // 添加处理AI交互响应的方法
  2535. handleAiInteractionResponse(data) {
  2536. console.log('AI语音交互接口响应:', data);
  2537. // 获取系统信息
  2538. const systemInfo = uni.getSystemInfoSync();
  2539. const isIOS = systemInfo.platform === 'ios';
  2540. // 标记正在播放AI语音
  2541. this.isPlayingAiVoice = true;
  2542. // 隐藏加载提示
  2543. uni.hideLoading();
  2544. // 重置备选方法尝试标志
  2545. this.hasTriedFallbackMethod = false;
  2546. if (data && data.success) {
  2547. // 保存AI回复数据
  2548. this.aiText = data.ai_text || '';
  2549. this.transcribedText = data.transcribed_text ? data.transcribed_text.text : '';
  2550. // 记录对话历史
  2551. this.conversationHistory.push({
  2552. role: 'user',
  2553. content: this.transcribedText
  2554. });
  2555. this.conversationHistory.push({
  2556. role: 'assistant',
  2557. content: this.aiText
  2558. });
  2559. // 获取AI语音URL
  2560. const aiVoiceUrl = data.ai_voice_url || '';
  2561. if (aiVoiceUrl) {
  2562. // 构建完整的URL
  2563. this.aiVoiceUrl = aiVoiceUrl.startsWith('http')
  2564. ? aiVoiceUrl
  2565. : `${apiBaseUrl}${aiVoiceUrl}`;
  2566. console.log('AI语音URL:', this.aiVoiceUrl);
  2567. // 显示AI回复文本作为字幕
  2568. this.currentSubtitle = this.aiText;
  2569. // 检查平台
  2570. const systemInfo = uni.getSystemInfoSync();
  2571. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith('mp-');
  2572. // 检查音频URL是否包含不支持的格式
  2573. const isUnsupportedFormat = this.checkUnsupportedAudioFormat(this.aiVoiceUrl);
  2574. if (isUnsupportedFormat && isMiniProgram) {
  2575. console.warn('检测到小程序不支持的音频格式,直接使用文本显示');
  2576. this.displayTextResponse();
  2577. return;
  2578. }
  2579. // 根据平台选择不同的播放方法
  2580. if (isMiniProgram) {
  2581. // 小程序环境使用原生API
  2582. if (isIOS) {
  2583. this.playIOSMiniProgramAudio();
  2584. } else {
  2585. this.playMiniProgramAudio();
  2586. }
  2587. /* this.playMiniProgramAudio(); */
  2588. } else {
  2589. // H5/App环境使用通用方法
  2590. this.playAiVoice();
  2591. }
  2592. // 重要:确保在AI语音播放期间不显示继续提问按钮
  2593. this.showContinueQuestionButton = false;
  2594. this.showEndInterviewButton = false;
  2595. } else {
  2596. console.warn('未获取到AI语音URL,使用文本显示');
  2597. // 如果没有语音URL,显示文本回复
  2598. this.displayTextResponse();
  2599. }
  2600. } else {
  2601. console.error('AI语音交互失败:', data);
  2602. // AI交互失败,显示继续提问按钮
  2603. this.showContinueQuestionOptions();
  2604. // 检查是否需要自动跳转
  2605. this.checkPendingNavigation();
  2606. }
  2607. },
  2608. // 修改 handleAiInteractionError 方法,不要直接跳转,而是显示继续提问选项
  2609. handleAiInteractionError(err) {
  2610. console.error('AI语音交互请求失败:', err);
  2611. uni.hideLoading();
  2612. // 显示错误提示
  2613. uni.showToast({
  2614. title: 'AI处理失败,请重试',
  2615. icon: 'none',
  2616. duration: 2000
  2617. });
  2618. // 请求失败,显示继续提问选项,而不是直接跳转
  2619. this.showContinueQuestionOptions();
  2620. },
  2621. // 添加新方法:播放AI语音
  2622. async playAiVoice() {
  2623. console.log('开始播放AI语音:', this.aiVoiceUrl);
  2624. // 重置错误提示标记
  2625. this.hasShownTextFallbackToast = false;
  2626. // 标记正在播放AI语音
  2627. this.isPlayingAiVoice = true;
  2628. // 隐藏所有按钮
  2629. this.showContinueQuestionButton = false;
  2630. this.showEndInterviewButton = false;
  2631. // 显示AI回复文本作为字幕
  2632. this.currentSubtitle = this.aiText;
  2633. // 检查音频URL是否有效
  2634. if (!this.aiVoiceUrl || this.aiVoiceUrl.trim() === '') {
  2635. console.error('无效的音频URL,直接显示文本');
  2636. this.useTextFallbackAndNavigate();
  2637. return;
  2638. }
  2639. try {
  2640. // 获取系统信息
  2641. const systemInfo = uni.getSystemInfoSync();
  2642. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith('mp-');
  2643. const isIOS = systemInfo.platform === 'ios';
  2644. // 根据平台选择播放方式并等待播放完成
  2645. if (isMiniProgram) {
  2646. if (isIOS) {
  2647. await this.playIOSMiniProgramAudio();
  2648. } else {
  2649. await this.playMiniProgramAudio();
  2650. }
  2651. } else if (isIOS) {
  2652. await this.playAiVoiceForIOS();
  2653. } else {
  2654. await this.playAiVoiceForAndroid();
  2655. }
  2656. // 音频播放完成后再跳转
  2657. this.navigateToNextPage();
  2658. } catch (error) {
  2659. console.error('音频播放失败:', error);
  2660. this.useTextFallbackAndNavigate();
  2661. }
  2662. },
  2663. // 新增方法:文本回退并导航
  2664. useTextFallbackAndNavigate() {
  2665. console.log('使用文本回退并准备导航');
  2666. // 标记播放结束
  2667. this.isPlayingAiVoice = false;
  2668. // 显示友好提示
  2669. if (!this.hasShownTextFallbackToast) {
  2670. this.hasShownTextFallbackToast = true;
  2671. uni.showToast({
  2672. title: '为您显示文字回复',
  2673. icon: 'none',
  2674. duration: 2000
  2675. });
  2676. }
  2677. // 显示完整文本
  2678. this.currentSubtitle = this.aiText || '抱歉,AI回复内容加载失败';
  2679. // 给用户一定时间阅读文本后自动跳转
  2680. setTimeout(() => {
  2681. this.navigateToNextPage();
  2682. }, 5000); // 5秒后跳转
  2683. },
  2684. // 修改 handleIOSAudioPlaybackComplete 方法
  2685. handleIOSAudioPlaybackComplete() {
  2686. // 标记播放结束
  2687. this.isPlayingAiVoice = false;
  2688. // 延迟清空字幕
  2689. setTimeout(() => {
  2690. this.currentSubtitle = '';
  2691. }, 1000);
  2692. // 销毁音频播放器
  2693. if (this.aiAudioPlayer) {
  2694. try {
  2695. this.aiAudioPlayer.destroy();
  2696. } catch (e) {
  2697. console.error('销毁iOS音频播放器失败:', e);
  2698. }
  2699. this.aiAudioPlayer = null;
  2700. }
  2701. // 直接导航到下一页
  2702. this.navigateToNextPage();
  2703. },
  2704. // 修改 playMiniProgramAudio 方法
  2705. playMiniProgramAudio() {
  2706. return new Promise(async (resolve, reject) => {
  2707. try {
  2708. // 显示加载提示
  2709. uni.showLoading({
  2710. title: '音频加载中...',
  2711. mask: true
  2712. });
  2713. // 先下载音频文件
  2714. const localAudioPath = await this.preloadAudio(this.aiVoiceUrl);
  2715. // 隐藏加载提示
  2716. uni.hideLoading();
  2717. const audioContext = wx.createInnerAudioContext();
  2718. audioContext.src = localAudioPath; // 使用本地文件路径
  2719. audioContext.autoplay = true;
  2720. // 设置音频缓冲大小
  2721. audioContext.bufferSize = 4096;
  2722. let hasStarted = false;
  2723. let hasError = false;
  2724. audioContext.onPlay(() => {
  2725. console.log('AI语音开始播放');
  2726. hasStarted = true;
  2727. this.currentSubtitle = this.aiText;
  2728. });
  2729. audioContext.onEnded(() => {
  2730. console.log('AI语音播放结束');
  2731. this.isPlayingAiVoice = false;
  2732. this.currentSubtitle = '';
  2733. audioContext.destroy();
  2734. // 确保在播放完成后立即解析Promise并跳转
  2735. if (!hasError) {
  2736. console.log('准备跳转到下一页');
  2737. this.navigateToNextPage(); // 添加这行
  2738. resolve();
  2739. }
  2740. });
  2741. audioContext.onStop(() => {
  2742. console.log('AI语音播放停止');
  2743. this.isPlayingAiVoice = false;
  2744. this.currentSubtitle = '';
  2745. audioContext.destroy();
  2746. // 如果是正常停止(非错误导致),也要触发跳转
  2747. if (!hasError) {
  2748. console.log('播放停止,准备跳转到下一页');
  2749. this.navigateToNextPage(); // 添加这行
  2750. resolve();
  2751. }
  2752. });
  2753. audioContext.onError((err) => {
  2754. hasError = true;
  2755. console.error('AI语音播放错误:', err);
  2756. audioContext.destroy();
  2757. // 显示错误提示
  2758. uni.showToast({
  2759. title: '音频播放异常,将显示文字',
  2760. icon: 'none',
  2761. duration: 2000
  2762. });
  2763. // 尝试使用备选音频格式
  2764. if (this.aiVoiceUrl.endsWith('.mp3')) {
  2765. const wavUrl = this.aiVoiceUrl.replace('.mp3', '.wav');
  2766. console.log('尝试使用WAV格式:', wavUrl);
  2767. this.aiVoiceUrl = wavUrl;
  2768. this.playMiniProgramAudio()
  2769. .then(resolve)
  2770. .catch(reject);
  2771. } else {
  2772. reject(err);
  2773. }
  2774. });
  2775. // 设置超时检测
  2776. setTimeout(() => {
  2777. if (!hasStarted && !hasError) {
  2778. console.error('音频播放启动超时');
  2779. audioContext.destroy();
  2780. reject(new Error('音频播放启动超时'));
  2781. }
  2782. }, 5000);
  2783. } catch (error) {
  2784. uni.hideLoading();
  2785. console.error('音频播放初始化失败:', error);
  2786. reject(error);
  2787. }
  2788. });
  2789. },
  2790. // 新增方法:导航到下一页
  2791. navigateToNextPage() {
  2792. console.log('执行页面跳转');
  2793. // 确保清理音频相关状态
  2794. this.isPlayingAiVoice = false;
  2795. this.currentSubtitle = '';
  2796. // 添加延迟确保状态已更新
  2797. setTimeout(() => {
  2798. uni.navigateTo({
  2799. url: '/pages/success/success',
  2800. success: () => {
  2801. console.log('页面跳转成功');
  2802. },
  2803. fail: (err) => {
  2804. console.error('页面跳转失败:', err);
  2805. uni.showToast({
  2806. title: '页面跳转失败',
  2807. icon: 'none',
  2808. duration: 2000
  2809. });
  2810. }
  2811. });
  2812. }, 100);
  2813. },
  2814. // 新增方法:专门处理iOS小程序音频播放
  2815. playIOSMiniProgramAudio() {
  2816. return new Promise((resolve, reject) => {
  2817. try {
  2818. const audioContext = wx.createInnerAudioContext();
  2819. audioContext.src = this.aiVoiceUrl;
  2820. audioContext.autoplay = true;
  2821. audioContext.onPlay(() => {
  2822. console.log('iOS小程序音频开始播放');
  2823. });
  2824. audioContext.onEnded(() => {
  2825. console.log('iOS小程序音频播放完成');
  2826. audioContext.destroy();
  2827. resolve();
  2828. });
  2829. audioContext.onError((err) => {
  2830. console.error('iOS小程序音频播放错误:', err);
  2831. audioContext.destroy();
  2832. reject(err);
  2833. });
  2834. } catch (error) {
  2835. reject(error);
  2836. }
  2837. });
  2838. },
  2839. playAiVoiceForIOS() {
  2840. return new Promise((resolve, reject) => {
  2841. try {
  2842. const audioContext = new Audio();
  2843. audioContext.src = this.aiVoiceUrl;
  2844. audioContext.autoplay = true;
  2845. audioContext.addEventListener('play', () => {
  2846. console.log('iOS音频开始播放');
  2847. });
  2848. audioContext.addEventListener('ended', () => {
  2849. console.log('iOS音频播放完成');
  2850. resolve();
  2851. });
  2852. audioContext.addEventListener('error', (err) => {
  2853. console.error('iOS音频播放错误:', err);
  2854. reject(err);
  2855. });
  2856. } catch (error) {
  2857. reject(error);
  2858. }
  2859. });
  2860. },
  2861. playAiVoiceForAndroid() {
  2862. return new Promise((resolve, reject) => {
  2863. try {
  2864. const audioContext = new Audio();
  2865. audioContext.src = this.aiVoiceUrl;
  2866. audioContext.autoplay = true;
  2867. audioContext.addEventListener('play', () => {
  2868. console.log('Android音频开始播放');
  2869. });
  2870. audioContext.addEventListener('ended', () => {
  2871. console.log('Android音频播放完成');
  2872. resolve();
  2873. });
  2874. audioContext.addEventListener('error', (err) => {
  2875. console.error('Android音频播放错误:', err);
  2876. reject(err);
  2877. });
  2878. } catch (error) {
  2879. reject(error);
  2880. }
  2881. });
  2882. },
  2883. // 新增方法:iOS小程序音频预下载
  2884. preloadIOSMiniProgramAudio(audioUrl) {
  2885. return new Promise((resolve, reject) => {
  2886. console.log('开始预下载iOS小程序音频:', audioUrl);
  2887. uni.downloadFile({
  2888. url: audioUrl,
  2889. timeout: 15000, // 15秒超时
  2890. success: (res) => {
  2891. if (res.statusCode === 200) {
  2892. console.log('iOS小程序音频下载成功:', res.tempFilePath);
  2893. resolve(res.tempFilePath);
  2894. } else {
  2895. console.error('iOS小程序音频下载失败,状态码:', res.statusCode);
  2896. reject(new Error(`下载失败,状态码: ${res.statusCode}`));
  2897. }
  2898. },
  2899. fail: (err) => {
  2900. console.error('iOS小程序音频下载请求失败:', err);
  2901. reject(err);
  2902. }
  2903. });
  2904. });
  2905. },
  2906. // 新增方法:iOS小程序错误处理
  2907. handleIOSMiniProgramError(audioContext, error) {
  2908. console.error('处理iOS小程序音频错误:', error);
  2909. // 销毁音频播放器
  2910. if (audioContext) {
  2911. try {
  2912. audioContext.destroy();
  2913. } catch (e) {
  2914. console.error('销毁音频播放器失败:', e);
  2915. }
  2916. }
  2917. // 根据错误类型显示不同的提示信息
  2918. let errorMessage = '音频播放异常,显示文字';
  2919. if (error.errMsg && error.errMsg.includes('-11850')) {
  2920. console.log('iOS小程序检测到系统音频错误(-11850)');
  2921. errorMessage = '系统音频服务暂停,显示文字';
  2922. } else if (error.errCode === 10002) {
  2923. console.log('iOS小程序检测到errCode:10002,网络或资源问题');
  2924. errorMessage = '音频加载中断,显示文字';
  2925. } else if (error.errCode === 10001) {
  2926. console.log('iOS小程序检测到errCode:10001,系统错误');
  2927. errorMessage = '系统音频错误,显示文字';
  2928. } else if (error.errCode === 10003) {
  2929. console.log('iOS小程序检测到errCode:10003,文件错误');
  2930. errorMessage = '音频文件错误,显示文字';
  2931. } else if (error.errCode === 10004) {
  2932. console.log('iOS小程序检测到errCode:10004,格式不支持');
  2933. errorMessage = '音频格式不支持,显示文字';
  2934. }
  2935. // 显示用户友好的错误提示
  2936. uni.showToast({
  2937. title: errorMessage,
  2938. icon: 'none',
  2939. duration: 2000
  2940. });
  2941. // 使用文本回退
  2942. this.useIOSTextFallback();
  2943. },
  2944. // 新增方法:iOS小程序播放超时处理
  2945. handleIOSPlaybackTimeout(audioContext) {
  2946. console.log('iOS小程序音频播放超时处理');
  2947. // 销毁音频播放器
  2948. if (audioContext) {
  2949. try {
  2950. audioContext.destroy();
  2951. } catch (e) {
  2952. console.error('销毁超时音频播放器失败:', e);
  2953. }
  2954. }
  2955. // 显示超时提示
  2956. /* uni.showToast({
  2957. title: '音频加载超时,显示文字',
  2958. icon: 'none',
  2959. duration: 2000
  2960. }); */
  2961. // 使用文本回退
  2962. this.useIOSTextFallback();
  2963. },
  2964. // 新增方法:iOS小程序备选播放方法
  2965. fallbackIOSMiniProgramPlay(audioContext) {
  2966. console.log('iOS小程序使用备选播放方法');
  2967. try {
  2968. // 直接设置原始URL
  2969. audioContext.src = this.aiVoiceUrl;
  2970. // 设置较短的超时时间
  2971. const fallbackTimeout = setTimeout(() => {
  2972. if (this.isPlayingAiVoice) {
  2973. console.log('iOS小程序备选方法也超时');
  2974. clearTimeout(fallbackTimeout);
  2975. this.handleIOSPlaybackTimeout(audioContext);
  2976. }
  2977. }, 3000);
  2978. // 尝试播放
  2979. audioContext.play();
  2980. } catch (e) {
  2981. console.error('iOS小程序备选播放方法失败:', e);
  2982. this.handleIOSPlaybackTimeout(audioContext);
  2983. }
  2984. },
  2985. // 新增方法:统一的iOS音频完成处理
  2986. handleIOSAudioComplete(audioContext) {
  2987. console.log('iOS音频播放完成');
  2988. // 标记播放结束
  2989. this.isPlayingAiVoice = false;
  2990. // 延迟清空字幕,让用户有时间阅读
  2991. setTimeout(() => {
  2992. this.currentSubtitle = '';
  2993. }, 2000);
  2994. // 销毁音频播放器
  2995. if (audioContext) {
  2996. try {
  2997. audioContext.destroy();
  2998. } catch (e) {
  2999. console.error('销毁iOS音频播放器失败:', e);
  3000. }
  3001. }
  3002. // 显示继续提问选项
  3003. this.showContinueQuestionOptions();
  3004. // 检查是否需要自动跳转
  3005. this.checkPendingNavigation();
  3006. },
  3007. // 移除原来的 playMiniProgramAudioForIOS 方法,因为已经被新的 playIOSMiniProgramAudio 替代
  3008. // playMiniProgramAudioForIOS() 方法可以删除或注释掉
  3009. // 保留原有的 useIOSTextFallback 方法,但确保它能正确处理所有iOS场景
  3010. useIOSTextFallback() {
  3011. console.log('iOS使用文本回退方案');
  3012. // 确保播放状态正确
  3013. this.isPlayingAiVoice = false;
  3014. // 显示友好提示(如果还没有显示过)
  3015. if (!this.hasShownTextFallbackToast) {
  3016. this.hasShownTextFallbackToast = true;
  3017. }
  3018. // 显示完整文本和继续按钮
  3019. this.currentSubtitle = this.aiText || '抱歉,AI回复内容加载失败';
  3020. this.showNextButton = true; // 添加一个变量控制按钮显示
  3021. },
  3022. // 添加处理继续按钮点击的方法
  3023. handleNextButtonClick() {
  3024. this.showNextButton = false;
  3025. this.handleIOSAudioComplete(null);
  3026. },
  3027. // 添加新方法:iOS音频播放完成处理
  3028. handleIOSAudioPlaybackComplete() {
  3029. // 标记播放结束
  3030. this.isPlayingAiVoice = false;
  3031. // 延迟清空字幕,让用户有时间阅读
  3032. setTimeout(() => {
  3033. this.currentSubtitle = '';
  3034. }, 2000);
  3035. // 销毁音频播放器
  3036. if (this.aiAudioPlayer) {
  3037. try {
  3038. this.aiAudioPlayer.destroy();
  3039. } catch (e) {
  3040. console.error('销毁iOS音频播放器失败:', e);
  3041. }
  3042. this.aiAudioPlayer = null;
  3043. }
  3044. // 显示继续提问选项
  3045. this.showContinueQuestionOptions();
  3046. // 检查是否需要自动跳转
  3047. this.checkPendingNavigation();
  3048. },
  3049. // 添加新方法:iOS音频错误处理
  3050. handleIOSAudioError(error) {
  3051. console.error('iOS音频播放错误:', error);
  3052. // 根据错误码进行不同处理
  3053. switch (error.errCode) {
  3054. case 10001:
  3055. console.log('iOS音频系统错误,尝试重新播放');
  3056. this.retryIOSAudioPlay();
  3057. break;
  3058. case 10002:
  3059. console.log('iOS音频网络错误,使用备选方案');
  3060. this.handleIOS10002Error();
  3061. break;
  3062. case 10003:
  3063. console.log('iOS音频文件错误,使用文本回退');
  3064. this.useIOSTextFallback();
  3065. break;
  3066. case 10004:
  3067. console.log('iOS音频格式不支持,使用文本回退');
  3068. this.useIOSTextFallback();
  3069. break;
  3070. default:
  3071. console.log('iOS音频未知错误,使用文本回退');
  3072. this.useIOSTextFallback();
  3073. break;
  3074. }
  3075. },
  3076. // 添加新方法:重试iOS音频播放
  3077. retryIOSAudioPlay() {
  3078. console.log('重试iOS音频播放');
  3079. // 销毁当前播放器
  3080. if (this.aiAudioPlayer) {
  3081. try {
  3082. this.aiAudioPlayer.destroy();
  3083. } catch (e) {
  3084. console.error('销毁播放器失败:', e);
  3085. }
  3086. this.aiAudioPlayer = null;
  3087. }
  3088. // 延迟后重试
  3089. setTimeout(() => {
  3090. this.fallbackIOSAudioPlay();
  3091. }, 1000);
  3092. },
  3093. // 添加新方法:iOS备选音频播放
  3094. fallbackIOSAudioPlay() {
  3095. console.log('iOS备选音频播放方案');
  3096. try {
  3097. // 创建新的音频播放器
  3098. this.aiAudioPlayer = uni.createInnerAudioContext();
  3099. // 使用更保守的设置
  3100. this.aiAudioPlayer.autoplay = true;
  3101. this.aiAudioPlayer.obeyMuteSwitch = true; // 遵循静音开关
  3102. this.aiAudioPlayer.volume = 0.8;
  3103. // 直接使用原URL
  3104. this.aiAudioPlayer.src = this.aiVoiceUrl;
  3105. // 设置简化的事件监听
  3106. this.aiAudioPlayer.onPlay(() => {
  3107. console.log('iOS备选方案:音频开始播放');
  3108. this.currentSubtitle = this.aiText;
  3109. });
  3110. this.aiAudioPlayer.onEnded(() => {
  3111. console.log('iOS备选方案:音频播放结束');
  3112. this.handleIOSAudioPlaybackComplete();
  3113. });
  3114. this.aiAudioPlayer.onError((err) => {
  3115. console.error('iOS备选方案:音频播放错误:', err);
  3116. this.useIOSTextFallback();
  3117. });
  3118. // 设置超时,如果5秒内没有开始播放,使用文本回退
  3119. setTimeout(() => {
  3120. if (this.isPlayingAiVoice && this.aiAudioPlayer) {
  3121. console.log('iOS音频播放超时,使用文本回退');
  3122. this.useIOSTextFallback();
  3123. }
  3124. }, 5000);
  3125. } catch (e) {
  3126. console.error('iOS备选音频播放失败:', e);
  3127. this.useIOSTextFallback();
  3128. }
  3129. },
  3130. // 修改 playMiniProgramAudio 方法,添加iOS特殊处理
  3131. /* playMiniProgramAudio() {
  3132. console.log('使用小程序原生音频API播放:', this.aiVoiceUrl);
  3133. // 标记正在播放AI语音
  3134. this.isPlayingAiVoice = true;
  3135. // 确保在播放期间不显示继续提问按钮
  3136. this.showContinueQuestionButton = false;
  3137. this.showEndInterviewButton = false;
  3138. // 检查音频URL是否有效
  3139. if (!this.aiVoiceUrl || this.aiVoiceUrl.trim() === '') {
  3140. console.error('无效的音频URL');
  3141. this.handleAudioPlaybackFailure();
  3142. return;
  3143. }
  3144. // 检查平台
  3145. const systemInfo = uni.getSystemInfoSync();
  3146. const isIOS = systemInfo.platform === 'ios';
  3147. // iOS小程序特殊处理
  3148. if (isIOS) {
  3149. this.playMiniProgramAudioForIOS();
  3150. return;
  3151. }
  3152. // 非iOS平台的原有逻辑
  3153. try {
  3154. // 使用wx.createInnerAudioContext API (微信小程序)
  3155. const audioContext = wx.createInnerAudioContext();
  3156. // 设置音频属性
  3157. audioContext.autoplay = false;
  3158. audioContext.obeyMuteSwitch = false; // 忽略静音开关
  3159. // 监听播放开始事件
  3160. audioContext.onPlay(() => {
  3161. console.log('AI语音开始播放');
  3162. // 显示正在播放提示
  3163. });
  3164. // 监听播放结束事件
  3165. audioContext.onEnded(() => {
  3166. console.log('AI语音播放结束');
  3167. // 标记播放结束
  3168. this.isPlayingAiVoice = false;
  3169. // 清空字幕
  3170. this.currentSubtitle = '';
  3171. // 销毁音频播放器
  3172. audioContext.destroy();
  3173. // 播放结束后显示继续提问选项,而不是直接跳转
  3174. this.showContinueQuestionOptions();
  3175. });
  3176. // 监听播放错误事件
  3177. audioContext.onError((err) => {
  3178. console.error('AI语音播放错误:', err);
  3179. // 标记播放结束
  3180. this.isPlayingAiVoice = false;
  3181. // 清空字幕
  3182. this.currentSubtitle = '';
  3183. // 销毁音频播放器
  3184. audioContext.destroy();
  3185. // 播放错误时也显示继续提问选项
  3186. this.showContinueQuestionOptions();
  3187. });
  3188. // 设置音频源
  3189. audioContext.src = this.aiVoiceUrl;
  3190. // 添加超时处理,如果5秒内没有开始播放,则认为出错
  3191. const playTimeout = setTimeout(() => {
  3192. if (this.isPlayingAiVoice) {
  3193. console.warn('小程序音频播放超时,尝试备选方法');
  3194. this.tryMiniProgramFallbackAudioPlay();
  3195. }
  3196. }, 5000);
  3197. // 延迟一小段时间再播放,确保src已经设置完成
  3198. setTimeout(() => {
  3199. audioContext.play();
  3200. // 播放开始后清除超时
  3201. clearTimeout(playTimeout);
  3202. }, 300);
  3203. } catch (e) {
  3204. console.error('小程序播放AI语音时发生错误:', e);
  3205. // 标记播放结束
  3206. this.isPlayingAiVoice = false;
  3207. // 显示错误提示
  3208. // 使用文本显示方式作为备选方案
  3209. this.handleAudioPlaybackFailure();
  3210. }
  3211. }, */
  3212. // 添加新方法:iOS小程序音频播放
  3213. playMiniProgramAudioForIOS() {
  3214. console.log('iOS小程序环境:开始播放AI语音');
  3215. // 重置错误标记
  3216. this.hasShownTextFallbackToast = false;
  3217. try {
  3218. // 创建音频上下文
  3219. const audioContext = wx.createInnerAudioContext();
  3220. // iOS小程序特殊配置
  3221. audioContext.autoplay = false;
  3222. audioContext.obeyMuteSwitch = true; // iOS上遵循静音开关
  3223. audioContext.volume = 1.0;
  3224. // 设置错误处理
  3225. audioContext.onError((err) => {
  3226. console.error('iOS小程序音频播放错误:', err);
  3227. // 检查具体错误类型
  3228. if (err.errMsg && err.errMsg.includes('-11850')) {
  3229. console.log('iOS小程序检测到系统音频错误(-11850)');
  3230. /* uni.showToast({
  3231. title: '系统音频暂停,显示文字',
  3232. icon: 'none',
  3233. duration: 2000
  3234. }); */
  3235. } else if (err.errCode === 10002) {
  3236. console.log('iOS小程序检测到errCode:10002,网络或资源问题');
  3237. /* uni.showToast({
  3238. title: '音频加载中断,显示文字',
  3239. icon: 'none',
  3240. duration: 2000
  3241. }); */
  3242. } else {
  3243. console.log('iOS小程序其他音频错误:', err.errCode);
  3244. /* uni.showToast({
  3245. title: '音频播放异常,显示文字',
  3246. icon: 'none',
  3247. duration: 2000
  3248. }); */
  3249. }
  3250. this.useIOSMiniProgramTextFallback(audioContext);
  3251. });
  3252. // 先尝试直接播放,如果失败再下载
  3253. audioContext.src = this.aiVoiceUrl;
  3254. // 设置成功事件监听
  3255. audioContext.onPlay(() => {
  3256. console.log('iOS小程序音频开始播放');
  3257. this.currentSubtitle = this.aiText;
  3258. /* uni.showToast({
  3259. title: '正在播放AI回复',
  3260. icon: 'none',
  3261. duration: 1500
  3262. }); */
  3263. });
  3264. audioContext.onEnded(() => {
  3265. console.log('iOS小程序音频播放结束');
  3266. this.handleIOSMiniProgramAudioComplete(audioContext);
  3267. });
  3268. // 设置较短的播放超时时间
  3269. const playTimeout = setTimeout(() => {
  3270. if (this.isPlayingAiVoice) {
  3271. console.log('iOS小程序音频播放超时,切换到文本显示');
  3272. clearTimeout(playTimeout);
  3273. this.useIOSMiniProgramTextFallback(audioContext);
  3274. }
  3275. }, 3000); // 缩短到3秒
  3276. // 尝试播放
  3277. audioContext.play();
  3278. } catch (e) {
  3279. console.error('iOS小程序音频播放初始化失败:', e);
  3280. this.handleAudioPlaybackFailure();
  3281. }
  3282. },
  3283. // 添加新方法:iOS小程序音频播放完成
  3284. handleIOSMiniProgramAudioComplete(audioContext) {
  3285. this.isPlayingAiVoice = false;
  3286. setTimeout(() => {
  3287. this.currentSubtitle = '';
  3288. }, 2000);
  3289. if (audioContext) {
  3290. try {
  3291. audioContext.destroy();
  3292. } catch (e) {
  3293. console.error('销毁iOS小程序音频播放器失败:', e);
  3294. }
  3295. }
  3296. this.showContinueQuestionOptions();
  3297. this.checkPendingNavigation();
  3298. },
  3299. // 添加新方法:iOS小程序音频错误处理
  3300. handleIOSMiniProgramAudioError(audioContext, error) {
  3301. console.error('iOS小程序音频错误:', error);
  3302. // 根据错误码处理
  3303. if (error.errCode === 10002) {
  3304. this.useIOSMiniProgramTextFallback(audioContext);
  3305. } else {
  3306. // 其他错误也使用文本回退
  3307. this.useIOSMiniProgramTextFallback(audioContext);
  3308. }
  3309. },
  3310. // 添加新方法:iOS小程序文本回退
  3311. useIOSMiniProgramTextFallback(audioContext) {
  3312. console.log('iOS小程序使用文本回退方案');
  3313. // 销毁音频播放器
  3314. if (audioContext) {
  3315. try {
  3316. audioContext.destroy();
  3317. } catch (e) {
  3318. console.error('销毁音频播放器失败:', e);
  3319. }
  3320. }
  3321. // 确保播放状态正确
  3322. this.isPlayingAiVoice = false;
  3323. // 显示完整文本
  3324. this.currentSubtitle = this.aiText || '抱歉,AI回复内容加载失败';
  3325. // 根据文本长度计算阅读时间
  3326. const textLength = this.aiText ? this.aiText.length : 20;
  3327. const readingTime = Math.max(6000, Math.min(textLength * 120, 18000)); // 最少6秒,最多18秒
  3328. setTimeout(() => {
  3329. this.handleIOSMiniProgramAudioComplete(null);
  3330. }, readingTime);
  3331. },
  3332. // 添加新方法:处理音频播放错误
  3333. handleAudioPlaybackError(error) {
  3334. console.error('音频播放错误:', error);
  3335. // 尝试使用备选方法
  3336. if (!this.hasTriedFallbackMethod) {
  3337. this.hasTriedFallbackMethod = true;
  3338. this.tryFallbackAudioPlay();
  3339. return;
  3340. }
  3341. // 如果备选方法也失败,回退到文本显示
  3342. this.handleAudioPlaybackFailure();
  3343. },
  3344. // 添加新方法:尝试备选音频播放方法
  3345. tryFallbackAudioPlay() {
  3346. console.log('使用备选方法播放音频:', this.aiVoiceUrl);
  3347. // 如果当前播放器存在,先销毁
  3348. if (this.aiAudioPlayer) {
  3349. try {
  3350. this.aiAudioPlayer.destroy();
  3351. } catch (e) {
  3352. console.error('销毁音频播放器失败:', e);
  3353. }
  3354. this.aiAudioPlayer = null;
  3355. }
  3356. // 使用uni.downloadFile先下载音频文件
  3357. uni.downloadFile({
  3358. url: this.aiVoiceUrl,
  3359. success: (res) => {
  3360. if (res.statusCode === 200) {
  3361. console.log('音频文件下载成功:', res.tempFilePath);
  3362. // 使用新的音频上下文播放本地文件
  3363. const newAudioPlayer = uni.createInnerAudioContext();
  3364. this.aiAudioPlayer = newAudioPlayer;
  3365. newAudioPlayer.autoplay = true;
  3366. newAudioPlayer.src = res.tempFilePath;
  3367. // 设置事件监听
  3368. newAudioPlayer.onPlay(() => {
  3369. console.log('备选方法:音频开始播放');
  3370. });
  3371. newAudioPlayer.onEnded(() => {
  3372. console.log('备选方法:音频播放结束');
  3373. this.isPlayingAiVoice = false;
  3374. this.currentSubtitle = '';
  3375. newAudioPlayer.destroy();
  3376. this.aiAudioPlayer = null;
  3377. this.showContinueQuestionOptions();
  3378. this.checkPendingNavigation();
  3379. });
  3380. newAudioPlayer.onError((err) => {
  3381. console.error('备选方法:音频播放错误:', err);
  3382. this.isPlayingAiVoice = false;
  3383. this.currentSubtitle = '';
  3384. newAudioPlayer.destroy();
  3385. this.aiAudioPlayer = null;
  3386. // 显示错误提示
  3387. /* uni.showToast({
  3388. title: '无法播放音频,请查看文字回复',
  3389. icon: 'none',
  3390. duration: 2000
  3391. }); */
  3392. this.showContinueQuestionOptions();
  3393. this.checkPendingNavigation();
  3394. });
  3395. } else {
  3396. console.error('音频文件下载失败:', res);
  3397. this.handleAudioPlaybackFailure();
  3398. }
  3399. },
  3400. fail: (err) => {
  3401. console.error('音频文件下载请求失败:', err);
  3402. this.handleAudioPlaybackFailure();
  3403. }
  3404. });
  3405. },
  3406. // 添加新方法:处理音频播放失败的情况
  3407. handleAudioPlaybackFailure() {
  3408. // 标记播放结束
  3409. this.isPlayingAiVoice = false;
  3410. // 显示错误提示
  3411. /* uni.showToast({
  3412. title: '无法播放音频,将直接显示文字回复',
  3413. icon: 'none',
  3414. duration: 2000
  3415. }); */
  3416. // 确保字幕显示足够长的时间(10秒)让用户阅读
  3417. this.currentSubtitle = this.aiText;
  3418. // 设置定时器,10秒后清除字幕并显示继续提问选项
  3419. setTimeout(() => {
  3420. this.currentSubtitle = '';
  3421. this.showContinueQuestionOptions();
  3422. this.checkPendingNavigation();
  3423. }, 10000);
  3424. },
  3425. // 添加新方法:从视频中提取音频
  3426. async extractAudioFromVideo(videoBlob) {
  3427. console.log('开始从视频中提取音频');
  3428. return new Promise((resolve, reject) => {
  3429. try {
  3430. // 创建一个视频元素来加载视频
  3431. const videoElement = document.createElement('video');
  3432. videoElement.muted = false;
  3433. videoElement.autoplay = false;
  3434. // 创建音频上下文
  3435. const audioContext = new (window.AudioContext || window.webkitAudioContext)();
  3436. let audioDestination = null;
  3437. let mediaRecorder = null;
  3438. const audioChunks = [];
  3439. // 设置视频源
  3440. videoElement.src = URL.createObjectURL(videoBlob);
  3441. videoElement.onloadedmetadata = () => {
  3442. console.log('视频元数据已加载,视频时长:', videoElement.duration);
  3443. // 创建媒体源和目标节点
  3444. const source = audioContext.createMediaElementSource(videoElement);
  3445. audioDestination = audioContext.createMediaStreamDestination();
  3446. source.connect(audioDestination);
  3447. // 创建MediaRecorder来录制音频
  3448. mediaRecorder = new MediaRecorder(audioDestination.stream);
  3449. mediaRecorder.ondataavailable = (event) => {
  3450. if (event.data.size > 0) {
  3451. audioChunks.push(event.data);
  3452. }
  3453. };
  3454. mediaRecorder.onstop = () => {
  3455. const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
  3456. console.log('音频提取完成,大小:', audioBlob.size);
  3457. resolve(audioBlob);
  3458. };
  3459. // 开始播放视频并录制音频
  3460. videoElement.onplay = () => {
  3461. mediaRecorder.start(100);
  3462. };
  3463. videoElement.onended = () => {
  3464. mediaRecorder.stop();
  3465. audioContext.close();
  3466. };
  3467. // 开始播放
  3468. videoElement.play();
  3469. };
  3470. videoElement.onerror = (err) => {
  3471. console.error('视频加载失败:', err);
  3472. reject(new Error('视频加载失败'));
  3473. };
  3474. } catch (err) {
  3475. console.error('提取音频失败:', err);
  3476. reject(err);
  3477. }
  3478. });
  3479. },
  3480. // 添加新方法:上传音频文件
  3481. async uploadAudioFile(audioBlob, videoUrl) {
  3482. console.log('准备上传音频文件');
  3483. // 创建FormData
  3484. const formData = new FormData();
  3485. // 将Blob转换为File对象
  3486. const fileName = `audio_${Date.now()}.wav`;
  3487. const audioFile = new File([audioBlob], fileName, { type: 'audio/wav' });
  3488. // 添加文件和其他参数
  3489. formData.append('audio_file', audioFile);
  3490. formData.append('video_url', videoUrl);
  3491. formData.append('tenant_id', uni.getStorageSync('tenant_id') || '1');
  3492. formData.append('openid', uni.getStorageSync('userInfo') ? JSON.parse(uni.getStorageSync('userInfo')).openid : '');
  3493. formData.append('application_id', uni.getStorageSync('appId') || '');
  3494. return new Promise((resolve, reject) => {
  3495. // 创建XMLHttpRequest
  3496. const xhr = new XMLHttpRequest();
  3497. xhr.open('POST', `${apiBaseUrl}/api/voice_ai_interaction`, true);
  3498. xhr.timeout = 60000; // 60秒超时
  3499. xhr.onload = () => {
  3500. if (xhr.status === 200) {
  3501. try {
  3502. const response = JSON.parse(xhr.responseText);
  3503. resolve(response);
  3504. } catch (e) {
  3505. reject(new Error('解析响应失败'));
  3506. }
  3507. } else {
  3508. reject(new Error('HTTP状态: ' + xhr.status));
  3509. }
  3510. };
  3511. xhr.onerror = () => {
  3512. reject(new Error('网络错误'));
  3513. };
  3514. xhr.ontimeout = () => {
  3515. reject(new Error('请求超时'));
  3516. };
  3517. xhr.send(formData);
  3518. });
  3519. },
  3520. // 添加一个新方法:使用小程序原生音频API
  3521. /* playMiniProgramAudio() {
  3522. console.log('使用小程序原生音频API播放:', this.aiVoiceUrl);
  3523. // 标记正在播放AI语音
  3524. this.isPlayingAiVoice = true;
  3525. // 确保在播放期间不显示继续提问按钮
  3526. this.showContinueQuestionButton = false;
  3527. this.showEndInterviewButton = false;
  3528. // 检查音频URL是否有效
  3529. if (!this.aiVoiceUrl || this.aiVoiceUrl.trim() === '') {
  3530. console.error('无效的音频URL');
  3531. // 显示错误提示
  3532. // 标记播放结束
  3533. this.isPlayingAiVoice = false;
  3534. // 显示继续提问选项
  3535. this.showContinueQuestionOptions();
  3536. return;
  3537. }
  3538. try {
  3539. // 使用wx.createInnerAudioContext API (微信小程序)
  3540. const audioContext = wx.createInnerAudioContext();
  3541. // 设置音频属性
  3542. audioContext.autoplay = false;
  3543. audioContext.obeyMuteSwitch = false; // 忽略静音开关
  3544. // 监听播放开始事件
  3545. audioContext.onPlay(() => {
  3546. console.log('AI语音开始播放');
  3547. // 显示正在播放提
  3548. });
  3549. // 监听播放结束事件
  3550. audioContext.onEnded(() => {
  3551. console.log('AI语音播放结束');
  3552. // 标记播放结束
  3553. this.isPlayingAiVoice = false;
  3554. // 清空字幕
  3555. this.currentSubtitle = '';
  3556. // 销毁音频播放器
  3557. audioContext.destroy();
  3558. // 播放结束后显示继续提问选项,而不是直接跳转
  3559. this.showContinueQuestionOptions();
  3560. });
  3561. // 监听播放错误事件
  3562. audioContext.onError((err) => {
  3563. console.error('AI语音播放错误:', err);
  3564. // 标记播放结束
  3565. this.isPlayingAiVoice = false;
  3566. // 清空字幕
  3567. this.currentSubtitle = '';
  3568. // 销毁音频播放器
  3569. audioContext.destroy();
  3570. // 播放错误时也显示继续提问选项
  3571. this.showContinueQuestionOptions();
  3572. });
  3573. // 设置音频源
  3574. audioContext.src = this.aiVoiceUrl;
  3575. // 添加超时处理,如果5秒内没有开始播放,则认为出错
  3576. const playTimeout = setTimeout(() => {
  3577. if (this.isPlayingAiVoice) {
  3578. console.warn('小程序音频播放超时,尝试备选方法');
  3579. this.tryMiniProgramFallbackAudioPlay();
  3580. }
  3581. }, 5000);
  3582. // 延迟一小段时间再播放,确保src已经设置完成
  3583. setTimeout(() => {
  3584. audioContext.play();
  3585. // 播放开始后清除超时
  3586. clearTimeout(playTimeout);
  3587. }, 300);
  3588. } catch (e) {
  3589. console.error('小程序播放AI语音时发生错误:', e);
  3590. // 标记播放结束
  3591. this.isPlayingAiVoice = false;
  3592. // 显示错误提示
  3593. // 使用文本显示方式作为备选方案
  3594. this.handleAudioPlaybackFailure();
  3595. }
  3596. }, */
  3597. // 添加新方法:小程序环境的备选音频播放方法
  3598. tryMiniProgramFallbackAudioPlay() {
  3599. console.log('使用小程序备选方法播放音频:', this.aiVoiceUrl);
  3600. // 先下载音频文件到本地
  3601. uni.downloadFile({
  3602. url: this.aiVoiceUrl,
  3603. success: (res) => {
  3604. if (res.statusCode === 200) {
  3605. console.log('小程序音频文件下载成功:', res.tempFilePath);
  3606. // 使用新的音频上下文播放本地文件
  3607. const newAudioContext = wx.createInnerAudioContext();
  3608. newAudioContext.autoplay = true;
  3609. newAudioContext.src = res.tempFilePath;
  3610. // 设置事件监听
  3611. newAudioContext.onPlay(() => {
  3612. console.log('小程序备选方法:音频开始播放');
  3613. });
  3614. newAudioContext.onEnded(() => {
  3615. console.log('小程序备选方法:音频播放结束');
  3616. this.isPlayingAiVoice = false;
  3617. this.currentSubtitle = '';
  3618. newAudioContext.destroy();
  3619. this.showContinueQuestionOptions();
  3620. this.checkPendingNavigation();
  3621. });
  3622. newAudioContext.onError((err) => {
  3623. console.error('小程序备选方法:音频播放错误:', err);
  3624. this.isPlayingAiVoice = false;
  3625. this.currentSubtitle = '';
  3626. newAudioContext.destroy();
  3627. // 尝试使用系统播放器作为最后的备选方案
  3628. this.trySystemAudioPlayer();
  3629. });
  3630. } else {
  3631. console.error('小程序音频文件下载失败:', res);
  3632. this.handleAudioPlaybackFailure();
  3633. }
  3634. },
  3635. fail: (err) => {
  3636. console.error('小程序音频文件下载请求失败:', err);
  3637. this.handleAudioPlaybackFailure();
  3638. }
  3639. });
  3640. },
  3641. // 添加新方法:尝试使用系统播放器
  3642. trySystemAudioPlayer() {
  3643. console.log('尝试使用系统播放器播放音频');
  3644. // 检查平台
  3645. const systemInfo = uni.getSystemInfoSync();
  3646. if (systemInfo.platform === 'android' || systemInfo.platform === 'ios') {
  3647. // 在移动端尝试使用系统播放器
  3648. /* uni.showToast({
  3649. title: '正在使用系统播放器',
  3650. icon: 'none',
  3651. duration: 2000
  3652. }); */
  3653. // 使用uni.playVoice API (如果可用)
  3654. if (typeof uni.playVoice === 'function') {
  3655. uni.playVoice({
  3656. filePath: this.aiVoiceUrl,
  3657. success: () => {
  3658. console.log('系统播放器播放成功');
  3659. setTimeout(() => {
  3660. this.isPlayingAiVoice = false;
  3661. this.currentSubtitle = '';
  3662. this.showContinueQuestionOptions();
  3663. }, 5000); // 假设音频长度约为5秒
  3664. },
  3665. fail: (err) => {
  3666. console.error('系统播放器播放失败:', err);
  3667. this.handleAudioPlaybackFailure();
  3668. }
  3669. });
  3670. } else {
  3671. // 如果uni.playVoice不可用,尝试使用uni.openDocument
  3672. uni.openDocument({
  3673. filePath: this.aiVoiceUrl,
  3674. fileType: 'audio',
  3675. success: () => {
  3676. console.log('使用系统应用打开音频文件');
  3677. // 由于控制权交给了系统,我们需要手动处理后续流程
  3678. setTimeout(() => {
  3679. this.isPlayingAiVoice = false;
  3680. this.currentSubtitle = '';
  3681. this.showContinueQuestionOptions();
  3682. }, 8000); // 给用户足够的时间听完音频
  3683. },
  3684. fail: (err) => {
  3685. console.error('无法使用系统应用打开音频:', err);
  3686. this.handleAudioPlaybackFailure();
  3687. }
  3688. });
  3689. }
  3690. } else {
  3691. // 在其他平台上直接使用文本显示
  3692. this.handleAudioPlaybackFailure();
  3693. }
  3694. },
  3695. // 修改 showContinueQuestionOptions 方法,确保状态正确设置
  3696. showContinueQuestionOptions() {
  3697. // 如果正在播放AI语音,不执行此方法
  3698. if (this.isPlayingAiVoice) {
  3699. console.log('AI语音正在播放,暂不显示继续提问选项');
  3700. return;
  3701. }
  3702. // 增加提问轮次计数
  3703. this.questionRound++;
  3704. // 清空字幕
  3705. this.currentSubtitle = '';
  3706. // 直接跳转到下一页,不再显示继续提问按钮
  3707. console.log('准备跳转到下一页面');
  3708. // 延迟3秒后跳转,给用户一些时间查看状态
  3709. setTimeout(() => {
  3710. this.navigateToNextPage();
  3711. }, 3000);
  3712. // 确保所有录制状态被重置
  3713. this.isRecording = false;
  3714. if (this.recordingTimer) {
  3715. clearInterval(this.recordingTimer);
  3716. this.recordingTimer = null;
  3717. }
  3718. // 重置录制相关数据
  3719. this.recordedChunks = [];
  3720. this.recordingTimerCount = 0;
  3721. this.remainingTime = this.maxRecordingTime;
  3722. },
  3723. // 修复 handleContinueQuestionClick 方法,确保状态正确重置
  3724. handleContinueQuestionClick() {
  3725. // 如果AI语音仍在播放,不允许继续提问
  3726. if (this.isPlayingAiVoice) {
  3727. /* uni.showToast({
  3728. title: '请等待面试官回复完成',
  3729. icon: 'none',
  3730. duration: 2000
  3731. }); */
  3732. return;
  3733. }
  3734. // 隐藏继续提问和结束面试按钮
  3735. this.showContinueQuestionButton = false;
  3736. this.showEndInterviewButton = false;
  3737. // 重置录制相关状态
  3738. this.isRecording = false;
  3739. this.recordingTimerCount = 0;
  3740. this.remainingTime = this.maxRecordingTime;
  3741. this.recordingTimeDisplay = '00:00 / ' + this.formatTime(this.maxRecordingTime);
  3742. // 清空已录制的数据
  3743. this.recordedChunks = [];
  3744. // 如果有正在进行的录制,先停止
  3745. if (this.mediaRecorder && this.mediaRecorder.state === 'recording') {
  3746. this.mediaRecorder.stop();
  3747. }
  3748. if (this.recorder) {
  3749. try {
  3750. this.cameraContext.stopRecord();
  3751. } catch (e) {
  3752. console.error('停止录制失败:', e);
  3753. }
  3754. this.recorder = null;
  3755. }
  3756. // 延迟一小段时间再开始新的录制,确保之前的录制已完全停止
  3757. setTimeout(() => {
  3758. // 开始新一轮录制
  3759. this.startRecordingAnswer();
  3760. }, 500);
  3761. },
  3762. // 添加新方法:处理结束面试按钮点击
  3763. handleEndInterviewClick() {
  3764. // 隐藏继续提问和结束面试按钮
  3765. this.showContinueQuestionButton = false;
  3766. this.showEndInterviewButton = false;
  3767. // 显示结束提示
  3768. /* uni.showToast({
  3769. title: '面试已结束',
  3770. icon: 'success',
  3771. duration: 1500
  3772. }); */
  3773. // 执行现有的跳转逻辑
  3774. this.navigateToNextPage();
  3775. },
  3776. // 添加新方法:处理录制错误
  3777. handleRecordingError(error) {
  3778. console.error('录制错误:', error);
  3779. // 显示错误提示
  3780. /* uni.showToast({
  3781. title: '录制失败,请重试',
  3782. icon: 'none',
  3783. duration: 2000
  3784. }); */
  3785. // 重置录制状态
  3786. this.isRecording = false;
  3787. this.showStopRecordingButton = false;
  3788. // 显示重试按钮
  3789. this.showStartRecordingButton = true;
  3790. },
  3791. // 添加新方法:处理上传错误
  3792. handleUploadError(error) {
  3793. console.error('上传错误:', error);
  3794. // 显示错误提示
  3795. /* uni.showToast({
  3796. title: '上传失败,请重试',
  3797. icon: 'none',
  3798. duration: 2000
  3799. }); */
  3800. // 显示重试按钮
  3801. this.showRetryButton = true;
  3802. // 隐藏上传状态
  3803. this.showUploadStatus = false;
  3804. this.isUploading = false;
  3805. },
  3806. // 添加新方法:检查是否有待处理的自动跳转
  3807. checkPendingNavigation() {
  3808. // 确保所有处理都已完成
  3809. if (this.pendingAutoNavigation &&
  3810. !this.isPlayingAiVoice &&
  3811. !this.isUploading &&
  3812. !this.currentSubtitle) { // 确保字幕也已经清空
  3813. console.log('所有处理已完成,准备跳转');
  3814. // 重置标志
  3815. this.pendingAutoNavigation = false;
  3816. // 延迟跳转,给用户一点时间看到最终状态
  3817. setTimeout(() => {
  3818. this.navigateToNextPage();
  3819. }, 1000);
  3820. }
  3821. },
  3822. // 添加新方法:显示文本回复
  3823. displayTextResponse() {
  3824. // 标记为正在"播放"
  3825. this.isPlayingAiVoice = true;
  3826. // 显示AI回复文本
  3827. this.currentSubtitle = '';
  3828. // 计算每个字的显示时间(假设每个字需要200毫秒)
  3829. const charDisplayTime = 200;
  3830. let currentIndex = 0;
  3831. // 使用定时器逐字显示文本
  3832. const textInterval = setInterval(() => {
  3833. if (currentIndex <= this.aiText.length) {
  3834. this.currentSubtitle = this.aiText.substring(0, currentIndex);
  3835. currentIndex++;
  3836. } else {
  3837. // 文本显示完成
  3838. clearInterval(textInterval);
  3839. // 等待用户阅读完整文本
  3840. setTimeout(() => {
  3841. // 标记播放结束
  3842. this.isPlayingAiVoice = false;
  3843. // 清空字幕
  3844. this.currentSubtitle = '';
  3845. // 显示继续提问选项
  3846. this.showContinueQuestionOptions();
  3847. // 检查是否需要自动跳转
  3848. this.checkPendingNavigation();
  3849. }, 3000); // 给用户3秒时间阅读完整文本
  3850. }
  3851. }, charDisplayTime);
  3852. },
  3853. // 添加新方法:检查不支持的音频格式
  3854. checkUnsupportedAudioFormat(url) {
  3855. if (!url) return false;
  3856. // 获取URL的文件扩展名
  3857. const extension = url.split('.').pop().toLowerCase();
  3858. // 检查平台
  3859. const systemInfo = uni.getSystemInfoSync();
  3860. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith('mp-');
  3861. if (isMiniProgram) {
  3862. // 微信小程序支持的音频格式有限,主要是mp3和wav
  3863. // 检查是否是不支持的格式
  3864. const unsupportedFormats = ['ogg', 'flac', 'aac', 'm4a', 'opus'];
  3865. return unsupportedFormats.includes(extension);
  3866. }
  3867. return false;
  3868. },
  3869. // 修改文本回退方法
  3870. useIOSTextFallback() {
  3871. console.log('切换到文本显示模式');
  3872. this.isPlayingAiVoice = false;
  3873. if (!this.hasShownTextFallbackToast) {
  3874. this.hasShownTextFallbackToast = true;
  3875. }
  3876. // 显示AI回复文本
  3877. this.currentSubtitle = this.aiText || '抱歉,无法获取AI回复内容';
  3878. // 根据文本长度计算阅读时间
  3879. const textLength = this.aiText ? this.aiText.length : 20;
  3880. const readingTime = Math.max(8000, Math.min(textLength * 150, 20000)); // 最少8秒,最多20秒
  3881. console.log(`文本长度: ${textLength}字,预计阅读时间: ${readingTime/1000}秒`);
  3882. // 等待用户阅读完成后再跳转
  3883. setTimeout(() => {
  3884. this.navigateToNextPage();
  3885. }, readingTime);
  3886. },
  3887. // 添加音频预加载方法
  3888. preloadAudio(audioUrl) {
  3889. return new Promise((resolve, reject) => {
  3890. console.log('开始预加载音频:', audioUrl);
  3891. // 使用wx.downloadFile下载音频文件
  3892. const downloadTask = wx.downloadFile({
  3893. url: audioUrl,
  3894. success: (res) => {
  3895. if (res.statusCode === 200) {
  3896. console.log('音频文件下载成功,临时路径:', res.tempFilePath);
  3897. resolve(res.tempFilePath);
  3898. } else {
  3899. console.error('音频文件下载失败,状态码:', res.statusCode);
  3900. reject(new Error(`下载失败,状态码: ${res.statusCode}`));
  3901. }
  3902. },
  3903. fail: (error) => {
  3904. console.error('音频文件下载失败:', error);
  3905. reject(error);
  3906. }
  3907. });
  3908. // 监听下载进度
  3909. downloadTask.onProgressUpdate((res) => {
  3910. console.log('音频下载进度:', res.progress);
  3911. });
  3912. });
  3913. },
  3914. // 修改音频播放方法
  3915. playMiniProgramAudio() {
  3916. return new Promise(async (resolve, reject) => {
  3917. try {
  3918. // 显示加载提示
  3919. uni.showLoading({
  3920. title: '音频加载中...',
  3921. mask: true
  3922. });
  3923. // 先下载音频文件
  3924. const localAudioPath = await this.preloadAudio(this.aiVoiceUrl);
  3925. // 隐藏加载提示
  3926. uni.hideLoading();
  3927. const audioContext = wx.createInnerAudioContext();
  3928. audioContext.src = localAudioPath; // 使用本地文件路径
  3929. audioContext.autoplay = true;
  3930. // 设置音频缓冲大小
  3931. audioContext.bufferSize = 4096;
  3932. let hasStarted = false;
  3933. let hasError = false;
  3934. audioContext.onPlay(() => {
  3935. console.log('AI语音开始播放');
  3936. hasStarted = true;
  3937. this.currentSubtitle = this.aiText;
  3938. });
  3939. audioContext.onEnded(() => {
  3940. console.log('AI语音播放结束');
  3941. this.isPlayingAiVoice = false;
  3942. this.currentSubtitle = '';
  3943. audioContext.destroy();
  3944. // 确保在播放完成后立即解析Promise并跳转
  3945. if (!hasError) {
  3946. console.log('准备跳转到下一页');
  3947. this.navigateToNextPage(); // 添加这行
  3948. resolve();
  3949. }
  3950. });
  3951. audioContext.onStop(() => {
  3952. console.log('AI语音播放停止');
  3953. this.isPlayingAiVoice = false;
  3954. this.currentSubtitle = '';
  3955. audioContext.destroy();
  3956. // 如果是正常停止(非错误导致),也要触发跳转
  3957. if (!hasError) {
  3958. console.log('播放停止,准备跳转到下一页');
  3959. this.navigateToNextPage(); // 添加这行
  3960. resolve();
  3961. }
  3962. });
  3963. audioContext.onError((err) => {
  3964. hasError = true;
  3965. console.error('AI语音播放错误:', err);
  3966. audioContext.destroy();
  3967. // 显示错误提示
  3968. uni.showToast({
  3969. title: '音频播放异常,将显示文字',
  3970. icon: 'none',
  3971. duration: 2000
  3972. });
  3973. // 尝试使用备选音频格式
  3974. if (this.aiVoiceUrl.endsWith('.mp3')) {
  3975. const wavUrl = this.aiVoiceUrl.replace('.mp3', '.wav');
  3976. console.log('尝试使用WAV格式:', wavUrl);
  3977. this.aiVoiceUrl = wavUrl;
  3978. this.playMiniProgramAudio()
  3979. .then(resolve)
  3980. .catch(reject);
  3981. } else {
  3982. reject(err);
  3983. }
  3984. });
  3985. // 设置超时检测
  3986. setTimeout(() => {
  3987. if (!hasStarted && !hasError) {
  3988. console.error('音频播放启动超时');
  3989. audioContext.destroy();
  3990. reject(new Error('音频播放启动超时'));
  3991. }
  3992. }, 5000);
  3993. } catch (error) {
  3994. uni.hideLoading();
  3995. console.error('音频播放初始化失败:', error);
  3996. reject(error);
  3997. }
  3998. });
  3999. },
  4000. // 添加备选的音频播放方法
  4001. async playFallbackAudio() {
  4002. return new Promise((resolve, reject) => {
  4003. try {
  4004. const audio = wx.createInnerAudioContext();
  4005. // 尝试使用较低质量的音频设置
  4006. audio.volume = 1.0;
  4007. audio.playbackRate = 1.0;
  4008. audio.src = this.aiVoiceUrl;
  4009. audio.autoplay = true;
  4010. audio.onPlay(() => {
  4011. console.log('备选音频开始播放');
  4012. });
  4013. audio.onEnded(() => {
  4014. console.log('备选音频播放完成');
  4015. audio.destroy();
  4016. resolve();
  4017. });
  4018. audio.onError((err) => {
  4019. console.error('备选音频播放失败:', err);
  4020. audio.destroy();
  4021. reject(err);
  4022. });
  4023. } catch (error) {
  4024. reject(error);
  4025. }
  4026. });
  4027. },
  4028. // 修改主音频播放方法
  4029. async playAiVoice() {
  4030. console.log('开始播放AI语音:', this.aiVoiceUrl);
  4031. this.isPlayingAiVoice = true;
  4032. this.currentSubtitle = this.aiText;
  4033. try {
  4034. // 首先尝试主要播放方法
  4035. await this.playMiniProgramAudio();
  4036. console.log('音频播放完成,准备跳转');
  4037. // 确保在音频播放完成后立即跳转
  4038. this.navigateToNextPage();
  4039. } catch (error) {
  4040. console.error('主要播放方法失败,尝试备选方法:', error);
  4041. try {
  4042. // 尝试备选播放方法
  4043. await this.playFallbackAudio();
  4044. console.log('备选音频播放完成,准备跳转');
  4045. this.navigateToNextPage();
  4046. } catch (fallbackError) {
  4047. console.error('备选播放方法也失败:', fallbackError);
  4048. // 如果所有播放方法都失败,回退到文本显示
  4049. this.useTextFallbackAndNavigate();
  4050. }
  4051. }
  4052. },
  4053. }
  4054. }
  4055. </script>
  4056. <style scoped>
  4057. .identity-verify-container {
  4058. padding: 0;
  4059. max-width: 100%;
  4060. margin: 0 auto;
  4061. height: 100vh;
  4062. display: flex;
  4063. flex-direction: column;
  4064. background-color: #f5f5f5;
  4065. }
  4066. .digital-human-container {
  4067. position: relative;
  4068. width: 100%;
  4069. height: 100vh;
  4070. overflow: hidden;
  4071. background-color: #f0f0f0;
  4072. }
  4073. .digital-human-video {
  4074. width: 100%;
  4075. height: 100%;
  4076. display: flex;
  4077. justify-content: center;
  4078. align-items: center;
  4079. }
  4080. /* 添加视频蒙层样式 */
  4081. .video-overlay {
  4082. position: absolute;
  4083. top: 0;
  4084. left: 0;
  4085. width: 100%;
  4086. height: 100%;
  4087. background-color: transparent; /* 完全透明 */
  4088. z-index: 6; /* 确保在视频之上,但在按钮和字幕之下 */
  4089. pointer-events: auto; /* 允许捕获点击事件 */
  4090. }
  4091. /* 用户摄像头容器样式 */
  4092. .user-camera-container {
  4093. position: absolute;
  4094. top: 50px;
  4095. right: 5px;
  4096. width: 110px; /* 稍微增加宽度 */
  4097. height: 160px; /* 稍微增加高度 */
  4098. border-radius: 4px; /* 减小圆角 */
  4099. overflow: hidden;
  4100. box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  4101. z-index: 20;
  4102. }
  4103. /* 用户摄像头视频样式 */
  4104. .user-camera-video {
  4105. width: 100%;
  4106. height: 100%;
  4107. object-fit: cover;
  4108. background-color: #333;
  4109. }
  4110. .video-player {
  4111. width: 100%;
  4112. height: 100%;
  4113. object-fit: cover;
  4114. outline: none; /* 移除视频获得焦点时的轮廓 */
  4115. -webkit-tap-highlight-color: transparent; /* 移除移动设备上的点击高亮 */
  4116. }
  4117. /* 隐藏视频控制条 */
  4118. video::-webkit-media-controls {
  4119. display: none !important;
  4120. }
  4121. video::-webkit-media-controls-enclosure {
  4122. display: none !important;
  4123. }
  4124. video::-webkit-media-controls-panel {
  4125. display: none !important;
  4126. }
  4127. video::-webkit-media-controls-play-button {
  4128. display: none !important;
  4129. }
  4130. video::-webkit-media-controls-timeline {
  4131. display: none !important;
  4132. }
  4133. video::-webkit-media-controls-current-time-display {
  4134. display: none !important;
  4135. }
  4136. video::-webkit-media-controls-time-remaining-display {
  4137. display: none !important;
  4138. }
  4139. video::-webkit-media-controls-mute-button {
  4140. display: none !important;
  4141. }
  4142. video::-webkit-media-controls-volume-slider {
  4143. display: none !important;
  4144. }
  4145. video::-webkit-media-controls-fullscreen-button {
  4146. display: none !important;
  4147. }
  4148. /* 修改字幕覆盖层样式,使其与图片中的样式一致 */
  4149. .subtitle-overlay {
  4150. position: absolute;
  4151. bottom: 100px; /* 调整位置,使其更靠近底部 */
  4152. left: 5%; /* 从左侧留出5%的空间 */
  4153. width: 80%; /* 宽度设为90%,两侧各留5%实现居中 */
  4154. padding: 15px 20px; /* 增加左右内边距 */
  4155. border-radius: 15px;
  4156. background-color: rgba(255, 255, 255, 0.9); /* 白色半透明背景 */
  4157. color: #333; /* 文字颜色为深色 */
  4158. text-align: left; /* 文字左对齐 */
  4159. font-size: 16px;
  4160. line-height: 1.5;
  4161. z-index: 10;
  4162. margin: 0 auto; /* 添加自动边距实现居中 */
  4163. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); /* 添加轻微阴影 */
  4164. display: flex;
  4165. flex-direction: column;
  4166. align-items: center;
  4167. gap: 10px;
  4168. }
  4169. /* 继续按钮样式 */
  4170. .next-button {
  4171. background-color: #0039b3;
  4172. color: white;
  4173. border: none;
  4174. padding: 8px 20px;
  4175. border-radius: 20px;
  4176. cursor: pointer;
  4177. font-size: 14px;
  4178. margin-top: 10px;
  4179. transition: all 0.3s;
  4180. width: 140px;
  4181. height: 36px;
  4182. display: flex;
  4183. justify-content: center;
  4184. align-items: center;
  4185. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  4186. }
  4187. .next-button:hover {
  4188. background-color: #002b8f;
  4189. transform: translateY(-1px);
  4190. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  4191. }
  4192. .next-button:active {
  4193. background-color: #001d66;
  4194. transform: translateY(1px);
  4195. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  4196. }
  4197. /* 添加计时器样式,右侧显示橙色圆点和时间 */
  4198. .subtitle-overlay::after {
  4199. content: attr(data-time);
  4200. position: absolute;
  4201. right: 20px;
  4202. bottom: 15px;
  4203. color: #333;
  4204. font-size: 14px;
  4205. }
  4206. .control-panel {
  4207. padding: 15px;
  4208. display: flex;
  4209. justify-content: center;
  4210. }
  4211. .control-button {
  4212. padding: 10px 20px;
  4213. background-color: #4CAF50;
  4214. color: white;
  4215. border: none;
  4216. border-radius: 4px;
  4217. cursor: pointer;
  4218. }
  4219. .loading {
  4220. text-align: center;
  4221. margin: 20px 0;
  4222. font-size: 16px;
  4223. }
  4224. .response-container {
  4225. margin-top: 20px;
  4226. padding: 0 20px;
  4227. display: none; /* 默认隐藏调试信息 */
  4228. }
  4229. /* 当showDebugInfo为true时显示 */
  4230. .showDebugInfo .response-container {
  4231. display: block;
  4232. }
  4233. .response-item {
  4234. padding: 10px;
  4235. border: 1px solid #eee;
  4236. border-radius: 4px;
  4237. margin-bottom: 10px;
  4238. background-color: #f9f9f9;
  4239. }
  4240. .response-content {
  4241. display: flex;
  4242. flex-direction: column;
  4243. }
  4244. .answer-button-container {
  4245. position: absolute;
  4246. bottom: 50px; /* 将按钮放在底部而不是75%的位置 */
  4247. left: 50%;
  4248. transform: translateX(-50%); /* 只在X轴上平移,保持水平居中 */
  4249. z-index: 20;
  4250. }
  4251. /* 修改回答按钮样式 */
  4252. .answer-button {
  4253. width: 120px;
  4254. height: 40px; /* 改为矩形按钮 */
  4255. border-radius: 20px; /* 圆角矩形 */
  4256. background-color: #ffffff; /* 白色背景 */
  4257. color: #333; /* 深色文字 */
  4258. font-size: 16px;
  4259. border: none;
  4260. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  4261. display: flex;
  4262. justify-content: center;
  4263. align-items: center;
  4264. cursor: pointer;
  4265. animation: none; /* 移除脉动动画 */
  4266. }
  4267. .stop-recording-button-container {
  4268. position: absolute;
  4269. bottom: 50px; /* 统一与其他按钮的位置 */
  4270. left: 50%;
  4271. transform: translateX(-50%);
  4272. z-index: 20;
  4273. }
  4274. .stop-recording-button {
  4275. width: 120px;
  4276. height: 40px; /* 改为矩形按钮 */
  4277. border-radius: 20px; /* 圆角矩形 */
  4278. background-color: #0039b3; /* 白色背景 */
  4279. color: #fff; /* 深色文字 */
  4280. font-size: 16px;
  4281. border: none;
  4282. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  4283. display: flex;
  4284. justify-content: center;
  4285. align-items: center;
  4286. cursor: pointer;
  4287. animation: none; /* 移除脉动动画 */
  4288. }
  4289. .recording-indicator {
  4290. position: absolute;
  4291. top: 20px;
  4292. left: 20px;
  4293. display: flex;
  4294. align-items: center;
  4295. background-color: rgba(255, 255, 255, 0.9); /* 改为白色半透明背景 */
  4296. padding: 5px 10px;
  4297. border-radius: 15px;
  4298. z-index: 20;
  4299. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  4300. }
  4301. .recording-dot {
  4302. width: 12px;
  4303. height: 12px;
  4304. background-color: #ff6b00; /* 改为橙色,与图片中的颜色一致 */
  4305. border-radius: 50%;
  4306. margin-right: 8px;
  4307. animation: blink 1s infinite;
  4308. }
  4309. .recording-text {
  4310. color: #333; /* 改为深色文字 */
  4311. font-size: 14px;
  4312. }
  4313. .timer-text {
  4314. color: #333; /* 改为深色文字 */
  4315. font-size: 14px;
  4316. margin-left: 8px;
  4317. }
  4318. .start-recording-button-container {
  4319. position: absolute;
  4320. bottom: 50px; /* 统一与其他按钮的位置 */
  4321. left: 50%;
  4322. transform: translateX(-50%);
  4323. z-index: 101;
  4324. }
  4325. .start-recording-button {
  4326. width: 120px;
  4327. height: 40px; /* 改为矩形按钮 */
  4328. border-radius: 20px; /* 圆角矩形 */
  4329. background-color: #ffffff; /* 白色背景 */
  4330. color: #333; /* 深色文字 */
  4331. font-size: 16px;
  4332. border: none;
  4333. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  4334. display: flex;
  4335. justify-content: center;
  4336. align-items: center;
  4337. cursor: pointer;
  4338. animation: none; /* 移除脉动动画 */
  4339. }
  4340. .retry-button-container {
  4341. position: absolute;
  4342. bottom: 30px; /* 统一与其他按钮的位置 */
  4343. left: 50%;
  4344. transform: translateX(-50%);
  4345. z-index: 20;
  4346. }
  4347. .retry-button {
  4348. padding: 10px 20px;
  4349. background-color: #ffffff; /* 白色背景 */
  4350. color: #333; /* 深色文字 */
  4351. font-size: 16px;
  4352. border: none;
  4353. border-radius: 20px; /* 圆角矩形 */
  4354. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  4355. cursor: pointer;
  4356. }
  4357. .retry-button:hover {
  4358. background-color: #2980b9;
  4359. }
  4360. /* 录制时长显示 */
  4361. .recording-timer {
  4362. position: absolute;
  4363. top: 20px;
  4364. left: 130px; /* 放在录制指示器旁边 */
  4365. background-color: rgba(0, 0, 0, 0.6);
  4366. padding: 5px 10px;
  4367. border-radius: 15px;
  4368. z-index: 20;
  4369. display: flex;
  4370. flex-direction: column;
  4371. }
  4372. .timer-text {
  4373. color: #000;
  4374. font-size: 14px;
  4375. font-family: monospace; /* 使用等宽字体,使时间显示更稳定 */
  4376. }
  4377. .remaining-time {
  4378. color: white;
  4379. font-size: 12px;
  4380. margin-top: 2px;
  4381. }
  4382. .remaining-time.warning {
  4383. color: #ff6b6b; /* 剩余时间少时显示红色 */
  4384. animation: blink 1s infinite; /* 使用闪烁动画提醒用户 */
  4385. }
  4386. /* 添加上传状态指示器 */
  4387. .upload-status-indicator {
  4388. position: absolute;
  4389. top: 20px;
  4390. left: 130px; /* 放在录制指示器旁边 */
  4391. background-color: rgba(0, 0, 0, 0.6);
  4392. padding: 5px 10px;
  4393. border-radius: 15px;
  4394. z-index: 20;
  4395. }
  4396. .upload-status-content {
  4397. display: flex;
  4398. align-items: center;
  4399. }
  4400. .upload-status-icon {
  4401. width: 12px;
  4402. height: 12px;
  4403. border-radius: 50%;
  4404. margin-right: 8px;
  4405. }
  4406. .upload-status-text {
  4407. color: white;
  4408. font-size: 14px;
  4409. }
  4410. .uploading {
  4411. background-color: #e74c3c;
  4412. }
  4413. /* 添加倒计时蒙层样式 */
  4414. .countdown-overlay {
  4415. position: fixed;
  4416. top: 0;
  4417. left: 0;
  4418. width: 100%;
  4419. height: 100%;
  4420. background-color: rgba(0, 0, 0, 0.7);
  4421. z-index: 100;
  4422. display: flex;
  4423. justify-content: center;
  4424. align-items: center;
  4425. }
  4426. .countdown-content {
  4427. display: flex;
  4428. flex-direction: column;
  4429. align-items: center;
  4430. }
  4431. .countdown-number {
  4432. font-size: 80px;
  4433. color: #ffffff;
  4434. font-weight: bold;
  4435. margin-bottom: 20px;
  4436. }
  4437. .countdown-text {
  4438. font-size: 24px;
  4439. color: #ffffff;
  4440. }
  4441. /* 添加GIF播放器样式 */
  4442. .gif-player {
  4443. width: 100%;
  4444. height: 100%;
  4445. object-fit: cover;
  4446. position: absolute;
  4447. top: 0;
  4448. left: 0;
  4449. z-index: 5; /* 确保GIF在视频上方但在字幕和按钮下方 */
  4450. }
  4451. /* AI语音播放蒙层样式 */
  4452. .ai-voice-overlay {
  4453. position: fixed;
  4454. top: 0;
  4455. left: 0;
  4456. width: 100%;
  4457. height: 100%;
  4458. background-color: rgba(0, 0, 0, 0.8); /* 0.8的透明度 */
  4459. z-index: 99; /* 确保在其他元素之上,但在倒计时蒙层之下 */
  4460. display: flex;
  4461. justify-content: center;
  4462. align-items: center;
  4463. }
  4464. .ai-voice-content {
  4465. display: flex;
  4466. flex-direction: column;
  4467. align-items: center;
  4468. color: #ffffff;
  4469. }
  4470. .ai-voice-icon {
  4471. width: 40px;
  4472. height: 40px;
  4473. border-radius: 50%;
  4474. background-color: #ffffff;
  4475. margin-bottom: 15px;
  4476. position: relative;
  4477. animation: pulse 1.5s infinite;
  4478. }
  4479. .ai-voice-icon::before {
  4480. content: '';
  4481. position: absolute;
  4482. top: 50%;
  4483. left: 50%;
  4484. transform: translate(-50%, -50%);
  4485. width: 20px;
  4486. height: 20px;
  4487. background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23333"><path d="M12 15c1.66 0 3-1.34 3-3V6c0-1.66-1.34-3-3-3S9 4.34 9 6v6c0 1.66 1.34 3 3 3zm-1-9c0-.55.45-1 1-1s1 .45 1 1v6c0 .55-.45 1-1 1s-1-.45-1-1V6z"/><path d="M17 11c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z"/></svg>');
  4488. background-repeat: no-repeat;
  4489. background-position: center;
  4490. }
  4491. .ai-voice-text {
  4492. font-size: 18px;
  4493. color: #ffffff;
  4494. }
  4495. @keyframes pulse {
  4496. 0% {
  4497. transform: scale(1);
  4498. opacity: 1;
  4499. }
  4500. 50% {
  4501. transform: scale(1.1);
  4502. opacity: 0.8;
  4503. }
  4504. 100% {
  4505. transform: scale(1);
  4506. opacity: 1;
  4507. }
  4508. }
  4509. /* 继续提问按钮样式 */
  4510. .continue-question-container {
  4511. position: absolute;
  4512. bottom: 100px; /* 位置高于结束面试按钮 */
  4513. left: 50%;
  4514. transform: translateX(-50%);
  4515. z-index: 20;
  4516. }
  4517. .continue-question-button {
  4518. width: 120px;
  4519. height: 40px;
  4520. border-radius: 20px;
  4521. background-color: #ffffff;
  4522. color: #333;
  4523. font-size: 16px;
  4524. border: none;
  4525. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  4526. display: flex;
  4527. justify-content: center;
  4528. align-items: center;
  4529. cursor: pointer;
  4530. }
  4531. /* 结束面试按钮样式 */
  4532. .end-interview-container {
  4533. position: absolute;
  4534. bottom: 50px;
  4535. left: 50%;
  4536. transform: translateX(-50%);
  4537. z-index: 20;
  4538. }
  4539. .end-interview-button {
  4540. width: 120px;
  4541. height: 40px;
  4542. border-radius: 20px;
  4543. background-color: #e74c3c; /* 红色背景 */
  4544. color: #ffffff; /* 白色文字 */
  4545. font-size: 16px;
  4546. border: none;
  4547. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  4548. display: flex;
  4549. justify-content: center;
  4550. align-items: center;
  4551. cursor: pointer;
  4552. }
  4553. /* 提问轮次指示器样式 */
  4554. .question-round-indicator {
  4555. position: absolute;
  4556. top: 20px;
  4557. right: 120px; /* 位置在用户摄像头左侧 */
  4558. background-color: rgba(255, 255, 255, 0.9);
  4559. padding: 5px 10px;
  4560. border-radius: 15px;
  4561. z-index: 20;
  4562. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  4563. }
  4564. .round-text {
  4565. color: #333;
  4566. font-size: 14px;
  4567. }
  4568. </style>