identity-verify.vue 128 KB

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