identity-verify.vue 176 KB

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