identity-verify.vue 125 KB

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