identity-verify.vue 169 KB

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