demo.vue 196 KB

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