identity-verify.vue 190 KB

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