identity-verify.vue 126 KB

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