identity-verify.vue 134 KB

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