identity-verify.js 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const common_config = require("../../common/config.js");
  4. const _sfc_main = {
  5. name: "IdentityVerify",
  6. data() {
  7. return {
  8. loading: false,
  9. responses: [],
  10. processedResponses: [],
  11. assistantResponse: "",
  12. audioTranscript: "",
  13. videoPlaying: false,
  14. showDebugInfo: false,
  15. // 设置为true可以显示调试信息
  16. videoUrl: "",
  17. // 修改为空字符串,将通过API获取
  18. showReplayButton: false,
  19. cameraStream: null,
  20. // 存储摄像头流
  21. cameraError: null,
  22. // 存储摄像头错误信息
  23. useMiniProgramCameraComponent: false,
  24. // 添加小程序相机组件标志
  25. cameraContext: null,
  26. // 添加相机上下文
  27. currentSubtitle: "",
  28. currentTranslation: "",
  29. // 添加翻译文本
  30. subtitles: [],
  31. // 修改为空数组,将通过API获取
  32. // 移除硬编码的字幕数组
  33. // secondVideoSubtitles: [...],
  34. // thirdVideoSubtitles: [...],
  35. // 等等...
  36. showAnswerButton: false,
  37. // 控制答题按钮显示
  38. currentVideoIndex: 0,
  39. // 当前播放的视频索引
  40. videoList: [],
  41. // 修改为空数组,将通过API获取
  42. // 其他属性保持不变...
  43. questions: [],
  44. // 添加新属性存储API返回的问题数据
  45. introVideoUrl: "https://data.qicai321.com/minlong/ee4d9cce-c3d5-4350-8c6e-684283827897.mp4",
  46. // 保留介绍视频
  47. isRecording: false,
  48. recordingTimer: null,
  49. showStopRecordingButton: false,
  50. mediaRecorder: null,
  51. recordedChunks: [],
  52. recorder: null,
  53. lastUploadedVideoUrl: "",
  54. showStartRecordingButton: false,
  55. showRetryButton: false,
  56. // 控制重试按钮显示
  57. lastVideoToRetry: null,
  58. // 存储上次失败的视频URL,用于重试
  59. recordingStartTime: null,
  60. // 录制开始时间
  61. recordingTimerCount: 0,
  62. // 录制计时器计数
  63. recordingTimeDisplay: "00:00",
  64. // 格式化的录制时间显示
  65. // 添加上传队列相关数据
  66. uploadQueue: [],
  67. // 存储待上传的视频
  68. isUploading: false,
  69. // 标记是否正在上传
  70. uploadProgress: {},
  71. // 存储每个视频的上传进度
  72. uploadStatus: {},
  73. // 存储每个视频的上传状态
  74. showUploadStatus: false,
  75. // 是否显示上传状态指示器
  76. uploadStatusText: "",
  77. // 上传状态文本
  78. mediaRecorderTimeout: null,
  79. // 用于存储MediaRecorder的超时机制
  80. maxRecordingTime: 300,
  81. // 最大录制时间(秒)- 从60秒改为300秒(5分钟)
  82. remainingTime: 300,
  83. // 剩余录制时间(秒)- 从60秒改为300秒
  84. countdownValue: 10,
  85. // 倒计时数值
  86. showCountdown: false,
  87. // 是否显示倒计时蒙层
  88. countdownTimer: null,
  89. showGif: false,
  90. // 控制是否显示GIF
  91. gifUrl: "",
  92. // GIF图片的URL
  93. globalSocketTask: null,
  94. // 添加全局 WebSocket 连接对象
  95. lowScoreVideoUrl: "https://data.qicai321.com/minlong/latentsync/0530e7f5-1957-422d-8f34-ba4a92608081_result.mp4",
  96. // 低分提示视频URL
  97. showRerecordButton: false,
  98. // 控制重新录制按钮显示
  99. isPlayingLowScoreVideo: false,
  100. // 标记是否正在播放低分提示视频
  101. lowScoreVideoSubtitles: [
  102. {
  103. startTime: 0,
  104. endTime: 10,
  105. // 假设视频长度为10秒,可根据实际情况调整
  106. text: "我未听清楚您在说什么,请您再说一遍!"
  107. }
  108. ],
  109. // 用于存储低分提示视频的字幕
  110. retryCount: 0,
  111. // 添加重试次数计数器
  112. maxRetryAttempts: 2,
  113. // 最大重试次数限制
  114. needPlayLowScoreVideo: false,
  115. // 是否需要播放低分视频
  116. finalRecordingDuration: 0,
  117. // 最终录制时长
  118. historyTime: 0,
  119. // 添加历史时间记录
  120. followUpQuestions: [],
  121. // 存储追问问题数据
  122. currentParentQuestionId: null,
  123. // 当前父问题ID
  124. hasPlayedFollowUp: {},
  125. // 记录已播放的追问,格式: {questionId: true}
  126. isFollowUpQuestion: false,
  127. // 标记当前是否正在播放追问问题
  128. currentFollowUpQuestion: null,
  129. // 添加当前追问问题的完整信息
  130. lastQuestionWasFollowUp: false,
  131. lastFollowUpQuestionId: null,
  132. lastUpdateTime: Date.now(),
  133. // 添加最后更新时间戳
  134. subtitleMap: {},
  135. // 用于存储字幕和翻译的映射
  136. progressPercent: 0,
  137. // 录制进度百分比
  138. progressColor: "#05dc8b",
  139. // 进度条颜色
  140. progressBgColor: "rgba(0, 0, 0,0.3)",
  141. // 进度条背景色
  142. parentQuestion: ""
  143. // 添加父问题存储
  144. };
  145. },
  146. mounted() {
  147. this.fetchQuestions();
  148. this.fetchFollowUpQuestions();
  149. this.checkAudioPermission();
  150. this.initCamera();
  151. this.checkIOSCameraRecordPermission();
  152. this.checkAndFixRenderingIssues();
  153. setTimeout(() => {
  154. if (this.cameraStream && !this.useMiniProgramCameraComponent) {
  155. this.testAudioInput();
  156. }
  157. }, 3e3);
  158. this.historyTime = 0;
  159. common_vendor.index.setKeepScreenOn({
  160. keepScreenOn: true
  161. });
  162. },
  163. beforeDestroy() {
  164. this.stopUserCamera();
  165. this.clearCountdown();
  166. },
  167. methods: {
  168. // 初始化相机
  169. async initCamera() {
  170. const systemInfo = common_vendor.index.getSystemInfoSync();
  171. const isMiniProgram = systemInfo.uniPlatform === "mp-weixin" || systemInfo.uniPlatform === "mp-alipay" || systemInfo.uniPlatform === "mp-baidu";
  172. if (isMiniProgram) {
  173. this.useMiniProgramCameraComponent = true;
  174. this.cameraContext = common_vendor.index.createCameraContext();
  175. common_vendor.index.getSetting({
  176. success: (res) => {
  177. if (!res.authSetting["scope.record"]) {
  178. common_vendor.index.authorize({
  179. scope: "scope.record",
  180. success: () => {
  181. console.log("录音权限已获取");
  182. },
  183. fail: (err) => {
  184. console.error("录音权限获取失败:", err);
  185. this.showPermissionDialog("录音");
  186. }
  187. });
  188. }
  189. if (!res.authSetting["scope.camera"]) {
  190. common_vendor.index.authorize({
  191. scope: "scope.camera",
  192. success: () => {
  193. console.log("相机权限已获取");
  194. },
  195. fail: (err) => {
  196. console.error("相机权限获取失败:", err);
  197. this.showPermissionDialog("相机");
  198. }
  199. });
  200. }
  201. const systemInfo2 = common_vendor.index.getSystemInfoSync();
  202. if (systemInfo2.platform === "ios") {
  203. if (!res.authSetting["scope.camera"] || !res.authSetting["scope.record"]) {
  204. console.log("iOS需要同时获取相机和录音权限");
  205. }
  206. }
  207. }
  208. });
  209. } else {
  210. try {
  211. const constraints = {
  212. audio: {
  213. echoCancellation: true,
  214. noiseSuppression: true,
  215. autoGainControl: true
  216. },
  217. video: {
  218. width: { ideal: 640, max: 1280 },
  219. // 控制视频宽度
  220. height: { ideal: 480, max: 720 },
  221. // 控制视频高度
  222. frameRate: { ideal: 15, max: 24 },
  223. // 控制帧率
  224. facingMode: "user"
  225. }
  226. };
  227. const stream = await navigator.mediaDevices.getUserMedia(constraints);
  228. this.cameraStream = stream;
  229. const audioTracks = stream.getAudioTracks();
  230. console.log("音频轨道数量:", audioTracks.length);
  231. if (audioTracks.length > 0) {
  232. console.log("音频轨道已获取:", audioTracks[0].label);
  233. audioTracks[0].enabled = true;
  234. } else {
  235. console.warn("未检测到音频轨道,尝试单独获取音频");
  236. this.tryGetAudioOnly();
  237. }
  238. const videoElement = this.$refs.userCameraVideo;
  239. if (videoElement) {
  240. videoElement.srcObject = stream;
  241. videoElement.muted = true;
  242. }
  243. } catch (error) {
  244. console.error("获取摄像头失败:", error);
  245. this.cameraError = error.message || "无法访问摄像头";
  246. common_vendor.index.showToast({
  247. title: "无法访问摄像头,请检查权限设置",
  248. icon: "none"
  249. });
  250. }
  251. }
  252. },
  253. // 停止用户摄像头
  254. stopUserCamera() {
  255. if (this.cameraStream) {
  256. this.cameraStream.getTracks().forEach((track) => {
  257. track.stop();
  258. });
  259. this.cameraStream = null;
  260. }
  261. },
  262. async fetchData() {
  263. this.loading = true;
  264. this.assistantResponse = "";
  265. this.audioTranscript = "";
  266. this.processedResponses = [];
  267. try {
  268. const requestTask = common_vendor.index.request({
  269. url: "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions",
  270. method: "POST",
  271. header: {
  272. "Content-Type": "application/json",
  273. "Authorization": "Bearer sk-9e1ec73a7d97493b8613c63f06b6110c"
  274. },
  275. data: {
  276. "model": "qwen-omni-turbo",
  277. "messages": [
  278. {
  279. "role": "user",
  280. "content": [
  281. {
  282. "type": "input_audio",
  283. "input_audio": {
  284. "data": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250211/tixcef/cherry.wav",
  285. "format": "wav"
  286. }
  287. },
  288. {
  289. "type": "text",
  290. "text": "这段音频在说什么"
  291. }
  292. ]
  293. }
  294. ],
  295. "stream": true,
  296. "stream_options": {
  297. "include_usage": true
  298. },
  299. "modalities": ["text", "audio"],
  300. "audio": { "voice": "Cherry", "format": "wav" }
  301. },
  302. success: (res) => {
  303. console.log("请求成功,响应数据:", res.data);
  304. if (typeof res.data === "string" && res.data.includes("data: {")) {
  305. const chunks = res.data.split("data: ").filter((chunk) => chunk.trim() !== "");
  306. chunks.forEach((chunk) => {
  307. this.handleStreamResponse(chunk);
  308. });
  309. } else {
  310. this.handleStreamResponse(res.data);
  311. }
  312. this.playDigitalHumanVideo();
  313. },
  314. fail: (err) => {
  315. console.error("请求失败:", err);
  316. },
  317. complete: () => {
  318. this.loading = false;
  319. }
  320. });
  321. } catch (error) {
  322. console.error("获取数据失败:", error);
  323. this.loading = false;
  324. }
  325. },
  326. handleStreamResponse(data) {
  327. if (typeof data === "string") {
  328. if (data === "[DONE]")
  329. return;
  330. try {
  331. const cleanData = data.trim();
  332. if (cleanData.startsWith("{") && cleanData.endsWith("}")) {
  333. const jsonData = JSON.parse(cleanData);
  334. this.processStreamChunk(jsonData);
  335. }
  336. } catch (e) {
  337. console.error("解析JSON失败:", e, "原始数据:", data);
  338. }
  339. } else {
  340. this.processStreamChunk(data);
  341. }
  342. },
  343. processStreamChunk(chunk) {
  344. if (chunk.choices && chunk.choices.length > 0) {
  345. const choice = chunk.choices[0];
  346. if (choice.delta && choice.delta.content) {
  347. this.assistantResponse += choice.delta.content;
  348. }
  349. if (choice.delta && choice.delta.audio && choice.delta.audio.transcript) {
  350. this.audioTranscript += choice.delta.audio.transcript;
  351. }
  352. if (choice.delta) {
  353. const result = {};
  354. if (choice.delta.role) {
  355. result.role = choice.delta.role;
  356. }
  357. if (choice.delta.audio && choice.delta.audio.transcript) {
  358. result.transcript = choice.delta.audio.transcript;
  359. }
  360. if (Object.keys(result).length > 0) {
  361. this.processedResponses.push(result);
  362. }
  363. }
  364. }
  365. },
  366. processResponseData() {
  367. this.processedResponses = this.responses.map((item) => {
  368. const result = {};
  369. if (item.delta && item.delta.role) {
  370. result.role = item.delta.role;
  371. }
  372. if (item.delta && item.delta.audio && item.delta.audio.transcript) {
  373. result.transcript = item.delta.audio.transcript;
  374. }
  375. return result;
  376. }).filter((item) => Object.keys(item).length > 0);
  377. },
  378. // 播放数字人视频
  379. playDigitalHumanVideo() {
  380. if (this.videoList.length === 0) {
  381. this.fetchQuestions();
  382. return;
  383. }
  384. this.videoUrl = this.videoList[this.currentVideoIndex];
  385. this.videoPlaying = true;
  386. this.$nextTick(() => {
  387. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  388. if (videoContext) {
  389. videoContext.play();
  390. setTimeout(() => {
  391. if (this.videoPlaying && this.$refs.videoPlayer) {
  392. console.log("视频应该正在播放");
  393. } else {
  394. console.log("视频可能未成功播放,尝试替代方案");
  395. this.tryAlternativeVideoPath();
  396. }
  397. }, 1e3);
  398. } else {
  399. console.error("无法创建视频上下文");
  400. this.tryAlternativeVideoPath();
  401. }
  402. });
  403. },
  404. // 修改 tryAlternativeVideoPath 方法
  405. tryAlternativeVideoPath() {
  406. console.log("尝试使用替代路径");
  407. const alternativePaths = [
  408. "./static/demo.mp4",
  409. "../static/demo.mp4",
  410. "static/demo.mp4",
  411. "/static/demo.mp4",
  412. // 添加绝对路径
  413. `${window.location.origin}/static/demo.mp4`
  414. ];
  415. const currentPathIndex = alternativePaths.indexOf(this.videoUrl);
  416. const nextPathIndex = (currentPathIndex + 1) % alternativePaths.length;
  417. this.videoUrl = alternativePaths[nextPathIndex];
  418. console.log("尝试新路径:", this.videoUrl);
  419. this.$nextTick(() => {
  420. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  421. if (videoContext) {
  422. videoContext.stop();
  423. videoContext.play();
  424. setTimeout(() => {
  425. if (nextPathIndex === alternativePaths.length - 1 && !this.videoPlaying) {
  426. console.log("所有路径均失败,尝试使用uni.getVideoInfo检查视频");
  427. this.checkVideoWithAPI();
  428. }
  429. }, 1e3);
  430. }
  431. });
  432. },
  433. // 添加新方法:使用uni API检查视频
  434. checkVideoWithAPI() {
  435. common_vendor.index.getVideoInfo({
  436. src: "/static/demo.mp4",
  437. success: (res) => {
  438. console.log("视频信息获取成功:", res);
  439. this.videoUrl = "/static/demo.mp4";
  440. this.$nextTick(() => {
  441. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  442. if (videoContext) {
  443. videoContext.play();
  444. }
  445. });
  446. },
  447. fail: (err) => {
  448. console.error("视频信息获取失败:", err);
  449. this.fallbackToLocalVideo();
  450. }
  451. });
  452. },
  453. // 添加新方法:回退到本地视频
  454. fallbackToLocalVideo() {
  455. console.log("尝试使用本地视频资源");
  456. const platform = common_vendor.index.getSystemInfoSync().platform;
  457. if (platform === "android" || platform === "ios") {
  458. this.videoUrl = platform === "android" ? "android.resource://package_name/raw/demo" : "file:///assets/demo.mp4";
  459. this.$nextTick(() => {
  460. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  461. if (videoContext) {
  462. videoContext.play();
  463. }
  464. });
  465. } else {
  466. this.videoPlaying = false;
  467. common_vendor.index.showToast({
  468. title: "视频加载失败,显示静态图片",
  469. icon: "none"
  470. });
  471. }
  472. },
  473. // 修改 handleVideoError 方法
  474. handleVideoError(e) {
  475. console.error("视频加载错误:", e);
  476. if (e && e.detail) {
  477. console.error("详细错误信息:", e.detail);
  478. }
  479. common_vendor.index.getFileInfo({
  480. filePath: this.videoUrl.startsWith("/") ? this.videoUrl.substring(1) : this.videoUrl,
  481. success: (res) => {
  482. console.log("文件存在,大小:", res.size);
  483. this.tryDifferentFormat();
  484. },
  485. fail: (err) => {
  486. console.error("文件不存在或无法访问:", err);
  487. this.tryAlternativeVideoPath();
  488. }
  489. });
  490. common_vendor.index.showToast({
  491. title: "视频加载失败,请检查文件是否存在",
  492. icon: "none",
  493. duration: 2e3
  494. });
  495. },
  496. // 添加新方法:尝试不同格式
  497. tryDifferentFormat() {
  498. console.log("尝试不同的视频格式");
  499. const formats = [
  500. { ext: "mp4", mime: "video/mp4" },
  501. { ext: "webm", mime: "video/webm" },
  502. { ext: "ogg", mime: "video/ogg" },
  503. { ext: "mov", mime: "video/quicktime" }
  504. ];
  505. const currentPath = this.videoUrl;
  506. const basePath = currentPath.substring(0, currentPath.lastIndexOf(".")) || "/static/demo";
  507. let nextFormat = formats.find((f) => !currentPath.endsWith(f.ext));
  508. if (nextFormat) {
  509. this.videoUrl = `${basePath}.${nextFormat.ext}`;
  510. console.log("尝试新格式:", this.videoUrl);
  511. this.$nextTick(() => {
  512. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  513. if (videoContext) {
  514. videoContext.stop();
  515. videoContext.play();
  516. }
  517. });
  518. } else {
  519. this.useBuiltInResource();
  520. }
  521. },
  522. // 添加新方法:使用内置资源
  523. useBuiltInResource() {
  524. console.log("尝试使用内置资源");
  525. const platform = common_vendor.index.getSystemInfoSync().platform;
  526. if (platform === "windows") {
  527. process.env.UNI_INPUT_DIR || "";
  528. this.videoUrl = `./static/demo.mp4`;
  529. console.log("Windows平台尝试路径:", this.videoUrl);
  530. } else if (platform === "android" || platform === "ios") {
  531. this.useNativeVideo();
  532. } else {
  533. const baseUrl = window.location.origin;
  534. this.videoUrl = `${baseUrl}/static/demo.mp4`;
  535. console.log("Web平台尝试URL:", this.videoUrl);
  536. }
  537. this.$nextTick(() => {
  538. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  539. if (videoContext) {
  540. videoContext.play();
  541. }
  542. });
  543. },
  544. // 添加新方法:使用原生视频能力
  545. useNativeVideo() {
  546. console.log("尝试使用原生视频能力");
  547. common_vendor.index.chooseVideo({
  548. sourceType: ["album"],
  549. success: (res) => {
  550. this.videoUrl = res.tempFilePath;
  551. this.$nextTick(() => {
  552. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  553. if (videoContext) {
  554. videoContext.play();
  555. }
  556. });
  557. },
  558. fail: () => {
  559. this.videoPlaying = false;
  560. common_vendor.index.showToast({
  561. title: "无法加载视频,显示静态图片",
  562. icon: "none"
  563. });
  564. }
  565. });
  566. },
  567. // 处理视频结束事件
  568. handleVideoEnded() {
  569. console.log("视频播放结束事件触发");
  570. const videoElement = this.$refs.videoPlayer;
  571. if (videoElement) {
  572. const currentTime = videoElement.currentTime || 0;
  573. const duration = videoElement.duration || 0;
  574. if (duration > 0 && duration - currentTime > 0.5) {
  575. console.log("检测到可能的误触发结束事件,继续播放", currentTime, duration);
  576. setTimeout(() => {
  577. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  578. if (videoContext) {
  579. if (duration - currentTime > 2) {
  580. videoContext.seek(this.historyTime || 0);
  581. } else {
  582. videoContext.play();
  583. }
  584. }
  585. }, 100);
  586. return;
  587. }
  588. console.log("视频确认结束,当前时间:", currentTime, "总时长:", duration);
  589. }
  590. this.videoPlaying = false;
  591. if (this.isPlayingLowScoreVideo) {
  592. console.log("低分提示视频播放完成");
  593. if (this.retryCount < this.maxRetryAttempts) {
  594. console.log(`显示重新录制按钮 (重试次数: ${this.retryCount + 1}/${this.maxRetryAttempts})`);
  595. this.showRerecordButton = true;
  596. if (this.isFollowUpQuestion && this.currentFollowUpQuestion) {
  597. this.currentSubtitle = this.currentFollowUpQuestion.digital_human_video_subtitle || this.currentFollowUpQuestion.question;
  598. }
  599. } else {
  600. console.log("已达到最大重试次数,继续下一题");
  601. this.retryCount = 0;
  602. this.proceedToNextQuestion();
  603. }
  604. this.isPlayingLowScoreVideo = false;
  605. return;
  606. }
  607. if (this.isFollowUpQuestion) {
  608. console.log("追问问题视频播放完成");
  609. this.showStartRecordingButton = true;
  610. this.startCountdown();
  611. return;
  612. }
  613. if (this.currentVideoIndex >= 1) {
  614. this.showStartRecordingButton = true;
  615. this.startCountdown();
  616. } else {
  617. this.showAnswerButton = true;
  618. }
  619. if (this.isFollowUpQuestion) {
  620. this.isFollowUpQuestion = false;
  621. this.currentFollowUpQuestion = null;
  622. }
  623. },
  624. // 添加新方法:开始倒计时
  625. startCountdown() {
  626. this.showCountdown = true;
  627. this.countdownValue = 10;
  628. this.countdownTimer = setInterval(() => {
  629. this.countdownValue--;
  630. if (this.countdownValue <= 0) {
  631. this.clearCountdown();
  632. this.showStartRecordingButton = false;
  633. this.startRecordingAnswer();
  634. }
  635. }, 1e3);
  636. },
  637. // 添加新方法:清除倒计时
  638. clearCountdown() {
  639. if (this.countdownTimer) {
  640. clearInterval(this.countdownTimer);
  641. this.countdownTimer = null;
  642. }
  643. this.showCountdown = false;
  644. },
  645. // 修改 handleStartRecordingClick 方法,使其可以终止倒计时
  646. handleStartRecordingClick() {
  647. this.showStartRecordingButton = false;
  648. this.clearCountdown();
  649. this.startRecordingAnswer();
  650. },
  651. // 修改 stopRecordingAnswer 方法,添加录制时长检查
  652. stopRecordingAnswer() {
  653. this.clearCountdown();
  654. const recordingDuration = this.getRecordingDuration();
  655. const minimumDuration = 3;
  656. const lowScoreDuration = 7;
  657. if (recordingDuration < minimumDuration) {
  658. common_vendor.index.showToast({
  659. title: "录制时间过短,请至少录制3秒",
  660. icon: "none",
  661. duration: 2e3
  662. });
  663. return;
  664. }
  665. this.completeRecordingStop();
  666. if (recordingDuration < lowScoreDuration) {
  667. console.log(`录制时间 ${recordingDuration} 秒,少于 ${lowScoreDuration} 秒,将播放低分提示视频`);
  668. this.needPlayLowScoreVideo = true;
  669. } else {
  670. this.needPlayLowScoreVideo = false;
  671. }
  672. },
  673. // 添加新方法:开始录制用户回答
  674. startRecordingAnswer() {
  675. console.log("开始录制用户回答");
  676. this.isRecording = true;
  677. this.recordingStartTime = Date.now();
  678. this.recordingTimerCount = 0;
  679. this.remainingTime = this.maxRecordingTime;
  680. this.recordingTimer = setInterval(() => {
  681. this.recordingTimerCount++;
  682. this.remainingTime = Math.max(0, this.maxRecordingTime - this.recordingTimerCount);
  683. this.recordingTimeDisplay = this.formatTime(this.recordingTimerCount);
  684. this.progressPercent = this.recordingTimerCount / this.maxRecordingTime * 100;
  685. if (this.recordingTimerCount >= this.maxRecordingTime) {
  686. console.log("已达到最大录制时间(5分钟),自动停止录制");
  687. this.stopRecordingAnswer();
  688. }
  689. }, 1e3);
  690. const systemInfo = common_vendor.index.getSystemInfoSync();
  691. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
  692. if (isMiniProgram) {
  693. this.startMiniProgramRecording();
  694. } else {
  695. this.startBrowserRecording();
  696. }
  697. this.showStopRecordingButton = true;
  698. },
  699. // 添加一个新方法:重置相机组件
  700. resetCamera() {
  701. console.log("重置相机组件");
  702. this.useMiniProgramCameraComponent = false;
  703. if (this.cameraContext) {
  704. this.cameraContext = null;
  705. }
  706. setTimeout(() => {
  707. this.useMiniProgramCameraComponent = true;
  708. setTimeout(() => {
  709. this.cameraContext = common_vendor.index.createCameraContext();
  710. console.log("相机组件已重置");
  711. }, 500);
  712. }, 500);
  713. },
  714. // 修改 startMiniProgramRecording 方法
  715. startMiniProgramRecording() {
  716. console.log("开始小程序录制方法");
  717. const systemInfo = common_vendor.index.getSystemInfoSync();
  718. const isIOS = systemInfo.platform === "ios";
  719. if (isIOS) {
  720. this.resetCamera();
  721. setTimeout(() => {
  722. this.actualStartRecording(isIOS);
  723. }, 1e3);
  724. } else {
  725. this.actualStartRecording(isIOS);
  726. }
  727. },
  728. // 添加新方法:实际开始录制
  729. actualStartRecording(isIOS) {
  730. if (!this.cameraContext) {
  731. this.cameraContext = common_vendor.index.createCameraContext();
  732. console.log("创建新的相机上下文");
  733. }
  734. common_vendor.index.getSetting({
  735. success: (res) => {
  736. const hasRecordAuth = res.authSetting["scope.record"];
  737. const hasCameraAuth = res.authSetting["scope.camera"];
  738. if (!hasRecordAuth || !hasCameraAuth) {
  739. console.warn("缺少必要权限,请求权限");
  740. this.requestMiniProgramPermissions();
  741. return;
  742. }
  743. if (isIOS) {
  744. console.log("iOS: 检查相机状态");
  745. const options = {
  746. timeout: 3e5,
  747. // 300秒超时 (5分钟)
  748. quality: "low",
  749. // 降低质量
  750. compressed: true,
  751. success: () => {
  752. console.log("iOS录制开始成功");
  753. },
  754. fail: (err) => {
  755. console.error("iOS录制失败:", err);
  756. this.useAlternativeRecordingMethod();
  757. }
  758. };
  759. try {
  760. console.log("尝试开始录制");
  761. this.recorder = this.cameraContext.startRecord(options);
  762. } catch (e) {
  763. console.error("开始录制异常:", e);
  764. this.useAlternativeRecordingMethod();
  765. }
  766. } else {
  767. const options = {
  768. timeout: 3e5,
  769. // 300秒超时 (5分钟)
  770. quality: "medium",
  771. compressed: true,
  772. success: () => {
  773. console.log("Android录制开始成功");
  774. },
  775. fail: (err) => {
  776. console.error("Android录制失败:", err);
  777. common_vendor.index.showToast({
  778. title: "录制失败,请检查相机权限",
  779. icon: "none"
  780. });
  781. this.proceedToNextQuestion();
  782. }
  783. };
  784. this.recorder = this.cameraContext.startRecord(options);
  785. }
  786. }
  787. });
  788. },
  789. // 添加新方法:使用替代录制方法
  790. useAlternativeRecordingMethod() {
  791. console.log("使用替代录制方法");
  792. common_vendor.index.showActionSheet({
  793. itemList: ["使用相册中的视频", "跳过此问题"],
  794. success: (res) => {
  795. if (res.tapIndex === 0) {
  796. common_vendor.index.chooseVideo({
  797. sourceType: ["album"],
  798. maxDuration: 300,
  799. // 从60秒改为300秒
  800. camera: "front",
  801. success: (res2) => {
  802. console.log("选择视频成功:", res2.tempFilePath);
  803. this.isRecording = false;
  804. this.showStopRecordingButton = false;
  805. this.uploadRecordedVideo(res2.tempFilePath);
  806. },
  807. fail: () => {
  808. console.log("用户取消选择视频");
  809. this.proceedToNextQuestion();
  810. }
  811. });
  812. } else {
  813. console.log("用户选择跳过问题");
  814. this.proceedToNextQuestion();
  815. }
  816. },
  817. fail: () => {
  818. console.log("操作取消");
  819. this.proceedToNextQuestion();
  820. }
  821. });
  822. },
  823. // 添加新方法:请求小程序权限
  824. requestMiniProgramPermissions() {
  825. common_vendor.index.authorize({
  826. scope: "scope.record",
  827. success: () => {
  828. console.log("录音权限已获取");
  829. common_vendor.index.authorize({
  830. scope: "scope.camera",
  831. success: () => {
  832. console.log("相机权限已获取");
  833. this.startMiniProgramRecording();
  834. },
  835. fail: (err) => {
  836. console.error("相机权限获取失败:", err);
  837. this.showPermissionDialog("相机");
  838. }
  839. });
  840. },
  841. fail: (err) => {
  842. console.error("录音权限获取失败:", err);
  843. this.showPermissionDialog("录音");
  844. }
  845. });
  846. },
  847. // 修改浏览器环境下的录制方法
  848. startBrowserRecording() {
  849. if (!this.cameraStream) {
  850. console.error("没有可用的摄像头流");
  851. common_vendor.index.showToast({
  852. title: "录制失败,摄像头未就绪",
  853. icon: "none"
  854. });
  855. this.proceedToNextQuestion();
  856. return;
  857. }
  858. try {
  859. const hasAudio = this.cameraStream.getAudioTracks().length > 0;
  860. if (!hasAudio) {
  861. console.warn("警告:媒体流中没有音频轨道,尝试重新获取带音频的媒体流");
  862. navigator.mediaDevices.getUserMedia({
  863. audio: {
  864. echoCancellation: true,
  865. noiseSuppression: true,
  866. autoGainControl: true
  867. },
  868. video: true
  869. }).then((newStream) => {
  870. const audioTracks = newStream.getAudioTracks();
  871. if (audioTracks.length > 0) {
  872. console.log("成功获取音频轨道:", audioTracks[0].label);
  873. const videoTrack = this.cameraStream.getVideoTracks()[0];
  874. const audioTrack = newStream.getAudioTracks()[0];
  875. const combinedStream = new MediaStream();
  876. if (videoTrack)
  877. combinedStream.addTrack(videoTrack);
  878. if (audioTrack)
  879. combinedStream.addTrack(audioTrack);
  880. this.cameraStream = combinedStream;
  881. const videoElement = this.$refs.userCameraVideo;
  882. if (videoElement) {
  883. videoElement.srcObject = combinedStream;
  884. videoElement.muted = true;
  885. }
  886. this.setupMediaRecorder(combinedStream);
  887. } else {
  888. console.warn("仍然无法获取音频轨道");
  889. this.setupMediaRecorder(this.cameraStream);
  890. }
  891. }).catch((err) => {
  892. console.error("获取音频失败:", err);
  893. this.setupMediaRecorder(this.cameraStream);
  894. });
  895. } else {
  896. console.log("检测到音频轨道,直接使用");
  897. this.setupMediaRecorder(this.cameraStream);
  898. }
  899. } catch (error) {
  900. console.error("浏览器录制失败:", error);
  901. common_vendor.index.showToast({
  902. title: "录制失败,浏览器可能不支持此功能",
  903. icon: "none"
  904. });
  905. this.proceedToNextQuestion();
  906. }
  907. },
  908. // 修改 setupMediaRecorder 方法
  909. setupMediaRecorder(stream) {
  910. const videoTracks = stream.getVideoTracks();
  911. const audioTracks = stream.getAudioTracks();
  912. console.log("设置MediaRecorder - 视频轨道:", videoTracks.length, "音频轨道:", audioTracks.length);
  913. let mimeType = "";
  914. const supportedTypes = [
  915. "video/webm;codecs=vp9,opus",
  916. "video/webm;codecs=vp8,opus",
  917. "video/webm;codecs=h264,opus",
  918. "video/mp4;codecs=h264,aac",
  919. "video/webm",
  920. "video/mp4"
  921. ];
  922. for (const type of supportedTypes) {
  923. if (MediaRecorder.isTypeSupported(type)) {
  924. mimeType = type;
  925. console.log("使用支持的MIME类型:", mimeType);
  926. break;
  927. }
  928. }
  929. const options = {
  930. mimeType: mimeType || "",
  931. audioBitsPerSecond: 64e3,
  932. // 降低音频比特率
  933. videoBitsPerSecond: 1e6
  934. // 降低视频比特率到1Mbps
  935. };
  936. try {
  937. this.mediaRecorder = new MediaRecorder(stream, options);
  938. console.log("MediaRecorder创建成功,使用选项:", options);
  939. } catch (e) {
  940. console.warn("使用指定选项创建MediaRecorder失败,尝试使用默认选项");
  941. this.mediaRecorder = new MediaRecorder(stream);
  942. }
  943. this.recordedChunks = [];
  944. this.mediaRecorder.ondataavailable = (event) => {
  945. if (event.data && event.data.size > 0) {
  946. this.recordedChunks.push(event.data);
  947. console.log(`收到数据块: ${event.data.size} 字节`);
  948. }
  949. };
  950. this.mediaRecorder.onstop = async () => {
  951. console.log("MediaRecorder停止,数据块数量:", this.recordedChunks.length);
  952. if (this.recordedChunks.length === 0) {
  953. console.error("没有录制到数据");
  954. common_vendor.index.showToast({
  955. title: "录制失败,未捕获到数据",
  956. icon: "none"
  957. });
  958. this.proceedToNextQuestion();
  959. return;
  960. }
  961. const mimeType2 = this.mediaRecorder.mimeType || "video/webm";
  962. const blob = new Blob(this.recordedChunks, { type: mimeType2 });
  963. console.log("创建Blob,原始大小:", blob.size, "类型:", mimeType2);
  964. common_vendor.index.showLoading({
  965. title: "正在处理视频...",
  966. mask: true
  967. });
  968. try {
  969. const compressedBlob = await this.compressVideo(blob);
  970. const fileName = `answer_${this.currentVideoIndex}_${Date.now()}.webm`;
  971. const file = new File([compressedBlob], fileName, { type: mimeType2 });
  972. common_vendor.index.hideLoading();
  973. this.uploadRecordedVideo(file);
  974. } catch (error) {
  975. console.error("视频处理失败:", error);
  976. common_vendor.index.hideLoading();
  977. const fileName = `answer_${this.currentVideoIndex}_${Date.now()}.webm`;
  978. const file = new File([blob], fileName, { type: mimeType2 });
  979. this.uploadRecordedVideo(file);
  980. }
  981. };
  982. this.mediaRecorder.onerror = (event) => {
  983. console.error("MediaRecorder错误:", event.error);
  984. };
  985. try {
  986. this.mediaRecorder.start(1e3);
  987. console.log("MediaRecorder开始录制");
  988. this.mediaRecorderTimeout = setTimeout(() => {
  989. if (this.mediaRecorder && this.mediaRecorder.state === "recording") {
  990. console.log("MediaRecorder备份超时机制触发,停止录制");
  991. this.mediaRecorder.stop();
  992. }
  993. }, 3e5);
  994. } catch (e) {
  995. console.error("开始录制失败:", e);
  996. }
  997. },
  998. // 添加新方法:停止录制用户回答
  999. stopRecordingAnswer() {
  1000. console.log("停止录制用户回答");
  1001. if (this.countdownTimer) {
  1002. clearInterval(this.countdownTimer);
  1003. this.countdownTimer = null;
  1004. this.showCountdown = false;
  1005. }
  1006. const recordingDuration = this.getRecordingDuration();
  1007. const minimumDuration = 3;
  1008. const lowScoreDuration = 7;
  1009. if (recordingDuration < minimumDuration) {
  1010. common_vendor.index.showToast({
  1011. title: "录制时间过短,请至少录制3秒",
  1012. icon: "none",
  1013. duration: 2e3
  1014. });
  1015. return;
  1016. }
  1017. this.completeRecordingStop();
  1018. if (recordingDuration < lowScoreDuration) {
  1019. console.log(`录制时间 ${recordingDuration} 秒,少于 ${lowScoreDuration} 秒,将播放低分提示视频`);
  1020. this.needPlayLowScoreVideo = true;
  1021. } else {
  1022. this.needPlayLowScoreVideo = false;
  1023. }
  1024. },
  1025. // 添加新方法:获取录制时长
  1026. getRecordingDuration() {
  1027. if (this.recordingStartTime) {
  1028. return (Date.now() - this.recordingStartTime) / 1e3;
  1029. }
  1030. if (this.mediaRecorder && this.$refs.userCameraVideo) {
  1031. return this.$refs.userCameraVideo.currentTime || 0;
  1032. }
  1033. if (this.recordingTimerCount) {
  1034. return this.recordingTimerCount;
  1035. }
  1036. return 0;
  1037. },
  1038. // 添加新方法:重置录制
  1039. resetRecording() {
  1040. if (this.recordingTimer) {
  1041. clearTimeout(this.recordingTimer);
  1042. }
  1043. this.recordingStartTime = Date.now();
  1044. this.recordingTimerCount = 0;
  1045. if (this.mediaRecorder && this.mediaRecorder.state !== "inactive") {
  1046. this.mediaRecorder.stop();
  1047. this.recordedChunks = [];
  1048. setTimeout(() => {
  1049. this.startBrowserRecording();
  1050. }, 500);
  1051. } else if (this.cameraContext) {
  1052. this.cameraContext.stopRecord({
  1053. success: () => {
  1054. console.log("相机录制已停止");
  1055. },
  1056. fail: (err) => {
  1057. console.error("停止相机录制失败:", err);
  1058. }
  1059. });
  1060. }
  1061. common_vendor.index.showToast({
  1062. title: "请重新开始回答",
  1063. icon: "none",
  1064. duration: 2e3
  1065. });
  1066. },
  1067. // 修改 completeRecordingStop 方法,确保正确处理追问问题ID
  1068. completeRecordingStop() {
  1069. console.log("完成录制停止");
  1070. if (this.recordingTimer) {
  1071. clearInterval(this.recordingTimer);
  1072. this.recordingTimer = null;
  1073. }
  1074. this.finalRecordingDuration = this.recordingTimerCount;
  1075. this.showStopRecordingButton = false;
  1076. this.isRecording = false;
  1077. const systemInfo = common_vendor.index.getSystemInfoSync();
  1078. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
  1079. if (isMiniProgram) {
  1080. this.stopMiniProgramRecording();
  1081. } else {
  1082. this.stopBrowserRecording();
  1083. }
  1084. if (this.isFollowUpQuestion && this.currentFollowUpQuestion) {
  1085. console.log("当前是追问问题,记录追问问题ID:", this.currentFollowUpQuestion.id);
  1086. this.lastQuestionWasFollowUp = true;
  1087. this.lastFollowUpQuestionId = this.currentFollowUpQuestion.id;
  1088. } else {
  1089. this.lastQuestionWasFollowUp = false;
  1090. this.lastFollowUpQuestionId = null;
  1091. }
  1092. },
  1093. // 修改 stopMiniProgramRecording 方法,确保正确传递追问问题ID
  1094. stopMiniProgramRecording() {
  1095. console.log("停止小程序录制");
  1096. if (!this.cameraContext) {
  1097. console.error("相机上下文不存在");
  1098. this.proceedToNextQuestion();
  1099. return;
  1100. }
  1101. this.cameraContext.stopRecord({
  1102. success: (res) => {
  1103. console.log("小程序录制停止成功:", res);
  1104. const videoPath = res.tempVideoPath;
  1105. if (videoPath) {
  1106. this.uploadRecordedVideo(videoPath);
  1107. } else {
  1108. console.error("未获取到录制视频路径");
  1109. this.proceedToNextQuestion();
  1110. }
  1111. },
  1112. fail: (err) => {
  1113. console.error("小程序录制停止失败:", err);
  1114. this.proceedToNextQuestion();
  1115. }
  1116. });
  1117. },
  1118. // 添加新方法:停止浏览器录制
  1119. stopBrowserRecording() {
  1120. if (this.mediaRecorder && this.mediaRecorder.state !== "inactive") {
  1121. this.mediaRecorder.stop();
  1122. console.log("浏览器录制停止成功");
  1123. } else {
  1124. console.error("MediaRecorder不存在或已经停止");
  1125. this.proceedToNextQuestion();
  1126. }
  1127. },
  1128. // 修改 uploadRecordedVideo 方法,添加记录父问题ID的逻辑
  1129. uploadRecordedVideo(fileOrPath) {
  1130. console.log("准备上传视频:", typeof fileOrPath === "string" ? fileOrPath : fileOrPath.name);
  1131. console.log("当前问题ID:", this.currentParentQuestionId);
  1132. console.log("当前问题类型:", this.isFollowUpQuestion);
  1133. console.log("当前追问问题:", this.currentFollowUpQuestion);
  1134. let questionId;
  1135. let isFollowUpQuestionUpload = false;
  1136. let questionText = "";
  1137. let questionForm = 0;
  1138. if (this.currentFollowUpQuestion && (this.currentFollowUpQuestion.question_form === 5 || this.isFollowUpQuestion)) {
  1139. questionId = this.currentFollowUpQuestion.id;
  1140. isFollowUpQuestionUpload = true;
  1141. questionText = this.currentFollowUpQuestion.question || "";
  1142. questionForm = 5;
  1143. console.log("正在上传追问问题的回答:", {
  1144. questionId,
  1145. questionText,
  1146. questionForm,
  1147. isFollowUp: true
  1148. });
  1149. } else {
  1150. const currentQuestion = this.getCurrentQuestionByIndex(this.currentVideoIndex);
  1151. if (currentQuestion && currentQuestion.id) {
  1152. questionId = currentQuestion.id;
  1153. questionText = currentQuestion.question || "";
  1154. console.log("正在上传常规问题的回答:", {
  1155. questionId,
  1156. questionText,
  1157. questionForm: 0
  1158. });
  1159. } else {
  1160. questionId = this.getDefaultQuestionId(this.currentVideoIndex);
  1161. console.log("使用默认问题ID:", questionId);
  1162. }
  1163. }
  1164. const uploadTask = {
  1165. id: Date.now().toString(),
  1166. file: fileOrPath,
  1167. questionId,
  1168. isFollowUp: isFollowUpQuestionUpload,
  1169. questionText,
  1170. questionForm,
  1171. attempts: 0,
  1172. maxAttempts: 3,
  1173. parentQuestionId: this.currentParentQuestionId
  1174. // 添加父问题ID
  1175. };
  1176. if (!isFollowUpQuestionUpload) {
  1177. this.currentParentQuestionId = questionId;
  1178. }
  1179. this.uploadQueue.push(uploadTask);
  1180. this.uploadProgress[uploadTask.id] = 0;
  1181. this.uploadStatus[uploadTask.id] = "pending";
  1182. common_vendor.index.showToast({
  1183. title: "已完成回答",
  1184. icon: "none",
  1185. duration: 1500
  1186. });
  1187. this.updateUploadStatusText();
  1188. if (!this.isUploading) {
  1189. this.processUploadQueue();
  1190. }
  1191. this.handlePostUploadActions(uploadTask);
  1192. },
  1193. // 添加新方法:处理上传后的逻辑
  1194. handlePostUploadActions(task) {
  1195. if (this.needPlayLowScoreVideo && this.retryCount < 1) {
  1196. this.playLowScoreVideo();
  1197. this.needPlayLowScoreVideo = false;
  1198. } else {
  1199. if (task.isFollowUp) {
  1200. console.log("追问问题回答完成,进入下一个问题");
  1201. this.retryCount = 0;
  1202. this.isFollowUpQuestion = false;
  1203. this.currentFollowUpQuestion = null;
  1204. this.proceedToNextQuestion();
  1205. } else {
  1206. this.currentParentQuestionId = task.questionId;
  1207. console.log("检查常规问题的追问,父问题ID:", this.currentParentQuestionId);
  1208. this.checkAndPlayFollowUpQuestion(this.currentParentQuestionId);
  1209. }
  1210. }
  1211. },
  1212. // 修改 processUploadQueue 方法
  1213. processUploadQueue() {
  1214. if (this.uploadQueue.length === 0) {
  1215. this.isUploading = false;
  1216. this.showUploadStatus = false;
  1217. return;
  1218. }
  1219. this.isUploading = true;
  1220. this.showUploadStatus = true;
  1221. const task = this.uploadQueue[0];
  1222. this.uploadStatus[task.id] = "uploading";
  1223. this.updateUploadStatusText();
  1224. task.attempts++;
  1225. if (typeof task.file === "string") {
  1226. this.uploadFileWithUni(task);
  1227. } else {
  1228. this.uploadFileWithXHR(task);
  1229. }
  1230. },
  1231. // 添加新方法:使用XMLHttpRequest上传文件
  1232. uploadFileWithXHR(task) {
  1233. const userInfo = common_vendor.index.getStorageSync("userInfo");
  1234. const openid = userInfo ? JSON.parse(userInfo).openid || "" : "";
  1235. const tenant_id = JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || "1";
  1236. const formData = new FormData();
  1237. formData.append("file", task.file);
  1238. formData.append("openid", openid);
  1239. formData.append("tenant_id", tenant_id);
  1240. formData.append("application_id", common_vendor.index.getStorageSync("appId"));
  1241. formData.append("question_id", task.questionId);
  1242. formData.append("video_duration", 0);
  1243. formData.append("has_audio", "true");
  1244. const xhr = new XMLHttpRequest();
  1245. xhr.open("POST", `${common_config.apiBaseUrl}/api/upload/`, true);
  1246. xhr.timeout = 12e4;
  1247. xhr.upload.onprogress = (event) => {
  1248. if (event.lengthComputable) {
  1249. const percentComplete = Math.round(event.loaded / event.total * 100);
  1250. this.uploadProgress[task.id] = percentComplete;
  1251. this.updateUploadStatusText();
  1252. }
  1253. };
  1254. xhr.onload = () => {
  1255. if (xhr.status === 200) {
  1256. try {
  1257. const res = JSON.parse(xhr.responseText);
  1258. console.log("上传响应:", res);
  1259. if (res.code === 2e3) {
  1260. const videoUrl = res.data.url || res.data.photoUrl || "";
  1261. if (videoUrl) {
  1262. this.uploadStatus[task.id] = "success";
  1263. this.updateUploadStatusText();
  1264. this.submitVideoToInterview(videoUrl, task);
  1265. } else {
  1266. this.handleUploadFailure(task, "视频URL获取失败");
  1267. }
  1268. } else {
  1269. this.handleUploadFailure(task, res.msg || "上传失败");
  1270. }
  1271. } catch (e) {
  1272. this.handleUploadFailure(task, "解析响应失败");
  1273. }
  1274. } else {
  1275. this.handleUploadFailure(task, "HTTP状态: " + xhr.status);
  1276. }
  1277. };
  1278. xhr.onerror = () => {
  1279. this.handleUploadFailure(task, "网络错误");
  1280. };
  1281. xhr.ontimeout = () => {
  1282. this.handleUploadFailure(task, "上传超时");
  1283. };
  1284. xhr.send(formData);
  1285. },
  1286. // 添加新方法:使用uni.uploadFile上传文件
  1287. uploadFileWithUni(task) {
  1288. const userInfo = common_vendor.index.getStorageSync("userInfo");
  1289. const openid = userInfo ? JSON.parse(userInfo).openid || "" : "";
  1290. const tenant_id = JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || "1";
  1291. const uploadTask = common_vendor.index.uploadFile({
  1292. url: `${common_config.apiBaseUrl}/api/upload/`,
  1293. filePath: task.file,
  1294. name: "file",
  1295. formData: {
  1296. openid,
  1297. tenant_id,
  1298. application_id: common_vendor.index.getStorageSync("appId"),
  1299. question_id: task.questionId,
  1300. video_duration: 0,
  1301. has_audio: "true"
  1302. },
  1303. success: (uploadRes) => {
  1304. try {
  1305. const res = JSON.parse(uploadRes.data);
  1306. console.log("上传响应:", res);
  1307. if (res.code === 2e3) {
  1308. const videoUrl = res.data.permanent_link || res.data.url || "";
  1309. if (videoUrl) {
  1310. this.uploadStatus[task.id] = "success";
  1311. this.updateUploadStatusText();
  1312. this.submitVideoToInterview(videoUrl, task);
  1313. } else {
  1314. this.handleUploadFailure(task, "视频URL获取失败");
  1315. }
  1316. } else {
  1317. this.handleUploadFailure(task, res.msg || "上传失败");
  1318. }
  1319. } catch (e) {
  1320. this.handleUploadFailure(task, "解析响应失败");
  1321. }
  1322. },
  1323. fail: (err) => {
  1324. this.handleUploadFailure(task, err.errMsg || "上传失败");
  1325. }
  1326. });
  1327. uploadTask.onProgressUpdate((res) => {
  1328. this.uploadProgress[task.id] = res.progress;
  1329. this.updateUploadStatusText();
  1330. });
  1331. },
  1332. // 添加新方法:处理上传失败
  1333. handleUploadFailure(task, errorMsg) {
  1334. console.error("上传失败:", errorMsg);
  1335. this.uploadStatus[task.id] = "failed";
  1336. this.updateUploadStatusText();
  1337. if (task.attempts < task.maxAttempts) {
  1338. console.log(`将在5秒后重试上传,当前尝试次数: ${task.attempts}/${task.maxAttempts}`);
  1339. setTimeout(() => {
  1340. this.uploadProgress[task.id] = 0;
  1341. if (typeof task.file !== "string") {
  1342. this.uploadFileWithXHR(task);
  1343. } else {
  1344. this.uploadFileWithUni(task);
  1345. }
  1346. }, 5e3);
  1347. } else {
  1348. console.log("超过最大重试次数,放弃上传");
  1349. common_vendor.index.showToast({
  1350. title: "视频上传失败,请稍后重试",
  1351. icon: "none",
  1352. duration: 2e3
  1353. });
  1354. this.uploadQueue.shift();
  1355. this.processUploadQueue();
  1356. }
  1357. },
  1358. // 修改 submitVideoToInterview 方法
  1359. submitVideoToInterview(videoUrl, task) {
  1360. const requestData = {
  1361. application_id: common_vendor.index.getStorageSync("appId"),
  1362. question_id: task.questionId,
  1363. video_url: videoUrl,
  1364. tenant_id: JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || "1",
  1365. is_follow_up: task.isFollowUp ? 1 : 0,
  1366. question_form: task.questionForm,
  1367. question_text: task.questionText
  1368. };
  1369. common_vendor.index.request({
  1370. url: `${common_config.apiBaseUrl}/api/job/upload_video`,
  1371. method: "POST",
  1372. data: requestData,
  1373. header: {
  1374. "content-type": "application/x-www-form-urlencoded"
  1375. },
  1376. success: (res) => {
  1377. if (res.data.code === 200 || res.data.code === 2e3) {
  1378. this.uploadQueue.shift();
  1379. this.processUploadQueue();
  1380. } else {
  1381. this.handleUploadError(task, "提交失败: " + (res.data.msg || "未知错误"));
  1382. }
  1383. },
  1384. fail: (err) => {
  1385. this.handleUploadError(task, "网络错误: " + err.errMsg);
  1386. }
  1387. });
  1388. },
  1389. // 添加新方法:处理提交失败
  1390. handleSubmitFailure(task, errorMsg) {
  1391. console.error("提交失败:", errorMsg);
  1392. this.uploadStatus[task.id] = "failed";
  1393. this.updateUploadStatusText();
  1394. if (task.attempts < task.maxAttempts) {
  1395. console.log(`将在5秒后重试提交,当前尝试次数: ${task.attempts}/${task.maxAttempts}`);
  1396. setTimeout(() => {
  1397. this.submitVideoToInterview(task.videoUrl, task);
  1398. }, 5e3);
  1399. } else {
  1400. console.log("超过最大重试次数,放弃提交");
  1401. common_vendor.index.showToast({
  1402. title: "视频提交失败,请稍后重试",
  1403. icon: "none",
  1404. duration: 2e3
  1405. });
  1406. this.uploadQueue.shift();
  1407. this.processUploadQueue();
  1408. }
  1409. },
  1410. // 添加新方法:更新上传状态文本
  1411. updateUploadStatusText() {
  1412. if (this.uploadQueue.length === 0) {
  1413. this.uploadStatusText = "";
  1414. return;
  1415. }
  1416. const currentTask = this.uploadQueue[0];
  1417. const progress = this.uploadProgress[currentTask.id] || 0;
  1418. const status = this.uploadStatus[currentTask.id] || "pending";
  1419. let statusText = "";
  1420. switch (status) {
  1421. case "pending":
  1422. statusText = "等待上传";
  1423. break;
  1424. case "uploading":
  1425. statusText = `上传中 ${progress}%`;
  1426. break;
  1427. case "success":
  1428. statusText = "上传成功,提交中...";
  1429. break;
  1430. case "failed":
  1431. statusText = `上传失败,${currentTask.attempts < currentTask.maxAttempts ? "即将重试" : "已放弃"}`;
  1432. break;
  1433. }
  1434. const questionTypeText = currentTask.isFollowUp ? "追问" : "问题";
  1435. const questionShortText = currentTask.questionText ? currentTask.questionText.length > 10 ? currentTask.questionText.substring(0, 10) + "..." : currentTask.questionText : `${questionTypeText}${currentTask.questionId}`;
  1436. this.uploadStatusText = `${questionTypeText}「${questionShortText}」:${statusText}`;
  1437. if (this.uploadQueue.length > 1) {
  1438. this.uploadStatusText += ` (${this.uploadQueue.length}个视频待处理)`;
  1439. }
  1440. },
  1441. // 修改 proceedToNextQuestion 方法,确保在切换视频时重置历史时间
  1442. proceedToNextQuestion() {
  1443. console.log("继续下一个问题");
  1444. this.currentVideoIndex++;
  1445. this.historyTime = 0;
  1446. if (this.currentVideoIndex < this.videoList.length) {
  1447. this.videoUrl = this.videoList[this.currentVideoIndex];
  1448. this.videoPlaying = true;
  1449. this.$nextTick(() => {
  1450. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  1451. if (videoContext) {
  1452. videoContext.play();
  1453. }
  1454. });
  1455. } else {
  1456. console.log("所有视频已播放完毕");
  1457. this.stopUserCamera();
  1458. this.clearCountdown();
  1459. const currentJobDetail = JSON.parse(common_vendor.index.getStorageSync("selectedJob"));
  1460. console.log("当前职位ID:", currentJobDetail);
  1461. const jobId = currentJobDetail ? currentJobDetail.id : null;
  1462. console.log("当前职位ID:", jobId);
  1463. setTimeout(() => {
  1464. if (jobId === 9) {
  1465. common_vendor.index.navigateTo({
  1466. url: "/pages/interview-question/interview-question",
  1467. success: () => {
  1468. console.log("成功跳转到interview-question页面");
  1469. },
  1470. fail: (err) => {
  1471. console.error("跳转到interview-question页面失败:", err);
  1472. common_vendor.index.redirectTo({
  1473. url: "/pages/interview-question/interview-question",
  1474. fail: (redirectErr) => {
  1475. console.error("重定向到interview-question页面也失败:", redirectErr);
  1476. common_vendor.index.navigateBack({
  1477. delta: 1
  1478. });
  1479. }
  1480. });
  1481. }
  1482. });
  1483. } else {
  1484. common_vendor.index.navigateTo({
  1485. url: "/pages/camera/camera",
  1486. success: () => {
  1487. console.log("成功跳转到camera页面");
  1488. },
  1489. fail: (err) => {
  1490. console.error("跳转到camera页面失败:", err);
  1491. common_vendor.index.redirectTo({
  1492. url: "/pages/camera/camera",
  1493. fail: (redirectErr) => {
  1494. console.error("重定向到camera页面也失败:", redirectErr);
  1495. common_vendor.index.switchTab({
  1496. url: "/pages/camera/camera",
  1497. fail: (switchErr) => {
  1498. console.error("所有跳转方式都失败:", switchErr);
  1499. common_vendor.index.navigateBack({
  1500. delta: 1
  1501. });
  1502. }
  1503. });
  1504. }
  1505. });
  1506. }
  1507. });
  1508. }
  1509. }, 2e3);
  1510. }
  1511. },
  1512. // 修改 handleAnswerButtonClick 方法,确保在切换视频时重置历史时间
  1513. handleAnswerButtonClick() {
  1514. console.log("点击开始回答按钮");
  1515. this.showAnswerButton = false;
  1516. this.currentVideoIndex++;
  1517. this.historyTime = 0;
  1518. if (this.currentVideoIndex < this.videoList.length) {
  1519. this.videoUrl = this.videoList[this.currentVideoIndex];
  1520. this.videoPlaying = true;
  1521. this.$nextTick(() => {
  1522. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  1523. if (videoContext) {
  1524. videoContext.play();
  1525. }
  1526. });
  1527. }
  1528. },
  1529. // 处理相机错误
  1530. handleCameraError(e) {
  1531. console.error("相机错误:", e);
  1532. const systemInfo = common_vendor.index.getSystemInfoSync();
  1533. const isIOS = systemInfo.platform === "ios";
  1534. if (isIOS) {
  1535. console.log("iOS相机错误,尝试重新初始化");
  1536. common_vendor.index.showToast({
  1537. title: "相机初始化中...",
  1538. icon: "loading",
  1539. duration: 2e3
  1540. });
  1541. this.resetCamera();
  1542. if (this.isRecording) {
  1543. this.isRecording = false;
  1544. this.showStopRecordingButton = false;
  1545. setTimeout(() => {
  1546. this.useAlternativeRecordingMethod();
  1547. }, 1e3);
  1548. }
  1549. } else {
  1550. common_vendor.index.showToast({
  1551. title: "相机初始化失败,请检查权限设置",
  1552. icon: "none"
  1553. });
  1554. this.tryFallbackOptions();
  1555. }
  1556. },
  1557. // 添加新方法:尝试备用选项
  1558. tryFallbackOptions() {
  1559. const systemInfo = common_vendor.index.getSystemInfoSync();
  1560. if (systemInfo.uniPlatform === "mp-weixin" || systemInfo.uniPlatform === "mp-alipay") {
  1561. this.useMiniProgramCamera();
  1562. } else {
  1563. this.showStaticCameraPlaceholder();
  1564. }
  1565. },
  1566. // 添加新方法:使用小程序相机API
  1567. useMiniProgramCamera() {
  1568. console.log("尝试使用小程序相机组件");
  1569. this.useMiniProgramCameraComponent = true;
  1570. },
  1571. // 添加新方法:显示静态图像
  1572. showStaticCameraPlaceholder() {
  1573. console.log("显示静态摄像头占位图");
  1574. const img = document.createElement("img");
  1575. img.src = "/static/images/camera-placeholder.png";
  1576. img.className = "static-camera-image";
  1577. img.style.width = "100%";
  1578. img.style.height = "100%";
  1579. img.style.objectFit = "cover";
  1580. const container = this.$refs.userCameraVideo.parentNode;
  1581. container.appendChild(img);
  1582. },
  1583. // 修改 handleTimeUpdate 方法
  1584. handleTimeUpdate(e) {
  1585. const currentTime = e.detail.currentTime || e.target.currentTime;
  1586. if (this.isRecording && this.recordingTimerCount) {
  1587. this.recordingTimeDisplay = this.formatTime(this.recordingTimerCount);
  1588. }
  1589. if (this.isPlayingLowScoreVideo) {
  1590. if (this.lowScoreVideoSubtitles && this.lowScoreVideoSubtitles.length > 0) {
  1591. const subtitle = this.lowScoreVideoSubtitles[0];
  1592. this.currentSubtitle = subtitle.text;
  1593. }
  1594. return;
  1595. }
  1596. let currentSubtitles = null;
  1597. if (this.isFollowUpQuestion && this.currentFollowUpQuestion) {
  1598. const subtitleKey = `followUpSubtitles_${this.currentFollowUpQuestion.id}`;
  1599. currentSubtitles = this[subtitleKey] || [{
  1600. startTime: 0,
  1601. endTime: 30,
  1602. text: this.currentFollowUpQuestion.digital_human_video_subtitle || this.currentFollowUpQuestion.question
  1603. }];
  1604. } else {
  1605. if (this.currentVideoIndex === 0) {
  1606. currentSubtitles = this.subtitles;
  1607. } else {
  1608. const subtitleArrayName = `question${this.currentVideoIndex}Subtitles`;
  1609. currentSubtitles = this[subtitleArrayName];
  1610. }
  1611. }
  1612. if (currentSubtitles && currentSubtitles.length > 0) {
  1613. const subtitle = currentSubtitles.find(
  1614. (sub) => currentTime >= sub.startTime && currentTime <= sub.endTime
  1615. ) || currentSubtitles[0];
  1616. if (subtitle) {
  1617. this.currentSubtitle = subtitle.text;
  1618. }
  1619. }
  1620. this.historyTime = currentTime;
  1621. this.lastUpdateTime = Date.now();
  1622. },
  1623. // Add a new method to handle the "Start Recording" button click
  1624. handleStartRecordingClick() {
  1625. this.showStartRecordingButton = false;
  1626. this.clearCountdown();
  1627. this.startRecordingAnswer();
  1628. },
  1629. // 修改 checkAudioPermission 方法,确保在录制前获取音频权限
  1630. checkAudioPermission() {
  1631. const systemInfo = common_vendor.index.getSystemInfoSync();
  1632. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
  1633. if (isMiniProgram) {
  1634. common_vendor.index.getSetting({
  1635. success: (res) => {
  1636. if (!res.authSetting["scope.record"]) {
  1637. common_vendor.index.authorize({
  1638. scope: "scope.record",
  1639. success: () => {
  1640. console.log("录音权限已获取");
  1641. },
  1642. fail: (err) => {
  1643. console.error("录音权限获取失败:", err);
  1644. this.showPermissionDialog("录音");
  1645. }
  1646. });
  1647. }
  1648. if (!res.authSetting["scope.camera"]) {
  1649. common_vendor.index.authorize({
  1650. scope: "scope.camera",
  1651. success: () => {
  1652. console.log("相机权限已获取");
  1653. },
  1654. fail: (err) => {
  1655. console.error("相机权限获取失败:", err);
  1656. this.showPermissionDialog("相机");
  1657. }
  1658. });
  1659. }
  1660. }
  1661. });
  1662. }
  1663. },
  1664. // 添加新方法:测试音频输入
  1665. testAudioInput() {
  1666. if (!this.cameraStream) {
  1667. console.warn("没有可用的媒体流,无法测试音频");
  1668. return;
  1669. }
  1670. const audioTracks = this.cameraStream.getAudioTracks();
  1671. if (audioTracks.length === 0) {
  1672. console.warn("没有检测到音频轨道,尝试重新获取");
  1673. this.tryGetAudioOnly();
  1674. return;
  1675. }
  1676. console.log("音频轨道信息:", audioTracks[0].getSettings());
  1677. try {
  1678. const AudioContext = window.AudioContext || window.webkitAudioContext;
  1679. if (!AudioContext) {
  1680. console.warn("浏览器不支持AudioContext");
  1681. return;
  1682. }
  1683. const audioContext = new AudioContext();
  1684. const analyser = audioContext.createAnalyser();
  1685. const microphone = audioContext.createMediaStreamSource(this.cameraStream);
  1686. microphone.connect(analyser);
  1687. analyser.fftSize = 256;
  1688. const bufferLength = analyser.frequencyBinCount;
  1689. const dataArray = new Uint8Array(bufferLength);
  1690. let silenceCounter = 0;
  1691. const checkAudio = () => {
  1692. if (this.isRecording)
  1693. return;
  1694. analyser.getByteFrequencyData(dataArray);
  1695. let sum = 0;
  1696. for (let i = 0; i < bufferLength; i++) {
  1697. sum += dataArray[i];
  1698. }
  1699. const average = sum / bufferLength;
  1700. if (average > 10) {
  1701. console.log("检测到音频输入,音量:", average);
  1702. silenceCounter = 0;
  1703. } else {
  1704. silenceCounter++;
  1705. if (silenceCounter > 10) {
  1706. console.warn("持续检测不到音频输入,可能麦克风未正常工作");
  1707. silenceCounter = 0;
  1708. }
  1709. }
  1710. requestAnimationFrame(checkAudio);
  1711. };
  1712. checkAudio();
  1713. } catch (e) {
  1714. console.error("音频测试失败:", e);
  1715. }
  1716. },
  1717. // 添加新方法:尝试单独获取音频
  1718. tryGetAudioOnly() {
  1719. navigator.mediaDevices.getUserMedia({ audio: true }).then((audioStream) => {
  1720. if (this.cameraStream) {
  1721. const videoTrack = this.cameraStream.getVideoTracks()[0];
  1722. const audioTrack = audioStream.getAudioTracks()[0];
  1723. const combinedStream = new MediaStream();
  1724. if (videoTrack)
  1725. combinedStream.addTrack(videoTrack);
  1726. if (audioTrack)
  1727. combinedStream.addTrack(audioTrack);
  1728. this.cameraStream = combinedStream;
  1729. const videoElement = this.$refs.userCameraVideo;
  1730. if (videoElement) {
  1731. videoElement.srcObject = combinedStream;
  1732. videoElement.muted = true;
  1733. }
  1734. console.log("成功合并音频和视频轨道");
  1735. } else {
  1736. console.warn("没有视频流可合并");
  1737. }
  1738. }).catch((err) => {
  1739. console.error("单独获取音频失败:", err);
  1740. });
  1741. },
  1742. // 添加新方法:显示权限对话框
  1743. showPermissionDialog(permissionType) {
  1744. common_vendor.index.showModal({
  1745. title: "需要权限",
  1746. content: `请允许使用${permissionType}权限,否则可能影响面试功能`,
  1747. confirmText: "去设置",
  1748. success: (res) => {
  1749. if (res.confirm) {
  1750. common_vendor.index.openSetting({
  1751. success: (settingRes) => {
  1752. console.log("设置页面打开成功", settingRes);
  1753. }
  1754. });
  1755. }
  1756. }
  1757. });
  1758. },
  1759. // 添加重试上传方法
  1760. retryVideoUpload() {
  1761. if (this.lastVideoToRetry) {
  1762. this.showRetryButton = false;
  1763. common_vendor.index.showLoading({
  1764. title: "正在重新提交...",
  1765. mask: true
  1766. });
  1767. this.submitVideoToInterview(this.lastVideoToRetry);
  1768. } else {
  1769. common_vendor.index.showToast({
  1770. title: "没有可重试的视频",
  1771. icon: "none"
  1772. });
  1773. }
  1774. },
  1775. // 添加一个新方法用于压缩视频
  1776. async compressVideo(videoBlob) {
  1777. if (videoBlob.size < 5 * 1024 * 1024) {
  1778. return videoBlob;
  1779. }
  1780. console.log("开始压缩视频,原始大小:", videoBlob.size);
  1781. const videoElement = document.createElement("video");
  1782. videoElement.muted = true;
  1783. videoElement.autoplay = false;
  1784. const canvas = document.createElement("canvas");
  1785. const ctx = canvas.getContext("2d");
  1786. videoElement.src = URL.createObjectURL(videoBlob);
  1787. return new Promise((resolve) => {
  1788. videoElement.onloadedmetadata = () => {
  1789. const width = Math.floor(videoElement.videoWidth / 2);
  1790. const height = Math.floor(videoElement.videoHeight / 2);
  1791. canvas.width = width;
  1792. canvas.height = height;
  1793. const stream = canvas.captureStream(15);
  1794. if (videoElement.captureStream) {
  1795. const originalStream = videoElement.captureStream();
  1796. const audioTracks = originalStream.getAudioTracks();
  1797. if (audioTracks.length > 0) {
  1798. stream.addTrack(audioTracks[0]);
  1799. }
  1800. }
  1801. const options = {
  1802. mimeType: "video/webm;codecs=vp8,opus",
  1803. audioBitsPerSecond: 64e3,
  1804. videoBitsPerSecond: 8e5
  1805. // 800kbps
  1806. };
  1807. const mediaRecorder = new MediaRecorder(stream, options);
  1808. const chunks = [];
  1809. mediaRecorder.ondataavailable = (e) => {
  1810. if (e.data.size > 0) {
  1811. chunks.push(e.data);
  1812. }
  1813. };
  1814. mediaRecorder.onstop = () => {
  1815. const compressedBlob = new Blob(chunks, { type: "video/webm" });
  1816. console.log("视频压缩完成,压缩后大小:", compressedBlob.size);
  1817. resolve(compressedBlob);
  1818. };
  1819. videoElement.onplay = () => {
  1820. mediaRecorder.start(10);
  1821. const drawFrame = () => {
  1822. if (videoElement.paused || videoElement.ended) {
  1823. mediaRecorder.stop();
  1824. return;
  1825. }
  1826. ctx.drawImage(videoElement, 0, 0, width, height);
  1827. requestAnimationFrame(drawFrame);
  1828. };
  1829. drawFrame();
  1830. };
  1831. videoElement.play();
  1832. };
  1833. });
  1834. },
  1835. // 修改 checkIOSCameraRecordPermission 方法
  1836. checkIOSCameraRecordPermission() {
  1837. const systemInfo = common_vendor.index.getSystemInfoSync();
  1838. if (systemInfo.platform !== "ios")
  1839. return;
  1840. common_vendor.index.getSetting({
  1841. success: (res) => {
  1842. if (!res.authSetting["scope.camera"]) {
  1843. common_vendor.index.authorize({
  1844. scope: "scope.camera",
  1845. success: () => {
  1846. console.log("iOS相机权限已获取");
  1847. },
  1848. fail: (err) => {
  1849. console.error("iOS相机权限获取失败:", err);
  1850. this.showPermissionDialog("相机");
  1851. }
  1852. });
  1853. }
  1854. if (!res.authSetting["scope.record"]) {
  1855. common_vendor.index.authorize({
  1856. scope: "scope.record",
  1857. success: () => {
  1858. console.log("iOS录音权限已获取");
  1859. },
  1860. fail: (err) => {
  1861. console.error("iOS录音权限获取失败:", err);
  1862. this.showPermissionDialog("录音");
  1863. }
  1864. });
  1865. }
  1866. }
  1867. });
  1868. },
  1869. // 添加新方法:检查并修复渲染问题
  1870. checkAndFixRenderingIssues() {
  1871. try {
  1872. if (typeof u !== "undefined" && u) {
  1873. if (!u.currentQuestion) {
  1874. console.log("修复: 创建缺失的currentQuestion对象");
  1875. u.currentQuestion = {};
  1876. }
  1877. if (u.currentQuestion && typeof u.currentQuestion.isImportant === "undefined") {
  1878. console.log("修复: 设置缺失的isImportant属性");
  1879. u.currentQuestion.isImportant = false;
  1880. }
  1881. }
  1882. } catch (e) {
  1883. console.log("防御性检查异常:", e);
  1884. }
  1885. },
  1886. // 添加格式化时间的辅助方法
  1887. formatTime(seconds) {
  1888. if (!seconds && seconds !== 0)
  1889. return "03:30";
  1890. const minutes = Math.floor(seconds / 60);
  1891. const remainingSeconds = seconds % 60;
  1892. return `${minutes.toString().padStart(2, "0")}:${remainingSeconds.toString().padStart(2, "0")}`;
  1893. },
  1894. // 添加获取问题数据的方法
  1895. fetchQuestions() {
  1896. this.loading = true;
  1897. const tenant_id = JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || "1";
  1898. let position_id = 1;
  1899. try {
  1900. const selectedJob = JSON.parse(common_vendor.index.getStorageSync("selectedJob") || "{}");
  1901. if (selectedJob && selectedJob.id) {
  1902. position_id = selectedJob.id;
  1903. console.log("使用选择的职位ID获取问题:", position_id);
  1904. } else {
  1905. console.warn("未找到选择的职位信息,使用默认职位ID:", position_id);
  1906. }
  1907. } catch (e) {
  1908. console.error("解析职位信息失败:", e);
  1909. }
  1910. const timestamp = Date.now();
  1911. const requestUrl = `${common_config.apiBaseUrl}/api/wechat/open_questions/?position_id=${position_id}&tenant_id=${tenant_id}&question_form=0&_t=${timestamp}`;
  1912. console.log("完整的请求URL:", requestUrl);
  1913. common_vendor.index.request({
  1914. url: requestUrl,
  1915. method: "GET",
  1916. success: (res) => {
  1917. if (res.data && res.data.code === 2e3 && res.data.data && res.data.data.items) {
  1918. console.log("获取问题数据成功:", res.data.data.items);
  1919. this.questions = res.data.data.items;
  1920. this.processQuestionData();
  1921. this.playIntroVideo();
  1922. } else {
  1923. console.error("获取问题数据失败:", res.data);
  1924. common_vendor.index.showToast({
  1925. title: "获取问题数据失败",
  1926. icon: "none"
  1927. });
  1928. }
  1929. },
  1930. fail: (err) => {
  1931. console.error("请求问题数据失败:", err);
  1932. common_vendor.index.showToast({
  1933. title: "网络错误,请检查网络连接",
  1934. icon: "none"
  1935. });
  1936. },
  1937. complete: () => {
  1938. this.loading = false;
  1939. }
  1940. });
  1941. },
  1942. // 处理问题数据,提取视频URL和字幕
  1943. processQuestionData() {
  1944. this.videoList = [];
  1945. this.videoList.push(this.introVideoUrl);
  1946. this.subtitles = [
  1947. {
  1948. startTime: 0,
  1949. endTime: 5,
  1950. text: "你好,我是本次面试的面试官,欢迎参加本公司的线上面试!"
  1951. },
  1952. {
  1953. startTime: 5,
  1954. endTime: 13,
  1955. text: "面试预计需要15分钟,请你提前安排在网络良好、光线亮度合适、且相对安静的环境参加这次面试"
  1956. },
  1957. {
  1958. startTime: 13,
  1959. endTime: 20,
  1960. text: "以免影响本次面试的结果。如果你在面试过程中遇到问题,请与我们的招聘人员联系。"
  1961. }
  1962. ];
  1963. const sortedQuestions = [...this.questions].sort((a, b) => a.sequence_number - b.sequence_number);
  1964. const questionsToUse = sortedQuestions.slice(0, 5);
  1965. questionsToUse.forEach((question, index) => {
  1966. if (question.digital_human_video_url) {
  1967. this.videoList.push(question.digital_human_video_url);
  1968. const subtitleArray = [{
  1969. startTime: 0,
  1970. endTime: 30,
  1971. // 延长字幕显示时间到30秒
  1972. text: question.digital_human_video_subtitle || question.question
  1973. }];
  1974. const videoIndex = this.videoList.length - 1;
  1975. this[`question${videoIndex}Subtitles`] = subtitleArray;
  1976. this.subtitleMap[question.digital_human_video_url] = subtitleArray;
  1977. }
  1978. });
  1979. if (this.videoList.length <= 1)
  1980. ;
  1981. else {
  1982. console.log("处理后的视频列表:", this.videoList);
  1983. console.log("处理后的字幕:", this.subtitles);
  1984. }
  1985. },
  1986. // 使用默认视频和字幕(作为备用)
  1987. useDefaultVideosAndSubtitles() {
  1988. console.log("使用默认视频和字幕");
  1989. this.subtitles = [
  1990. {
  1991. startTime: 0,
  1992. endTime: 5,
  1993. text: "你好,我是本次面试的面试官,欢迎参加本公司的线上面试!"
  1994. },
  1995. {
  1996. startTime: 5,
  1997. endTime: 13,
  1998. text: "面试预计需要15分钟,请你提前安排在网络良好、光线亮度合适、且相对安静的环境参加这次面试"
  1999. },
  2000. {
  2001. startTime: 13,
  2002. endTime: 20,
  2003. text: "以免影响本次面试的结果。如果你在面试过程中遇到问题,请与我们的招聘人员联系。"
  2004. }
  2005. ];
  2006. this.question1Subtitles = [{
  2007. startTime: 0,
  2008. endTime: 10,
  2009. text: "请结合您的基本信息与过往履历进行简单的自我介绍,并讲一讲您有哪些优势胜任本岗位:"
  2010. }];
  2011. this.question2Subtitles = [{
  2012. startTime: 0,
  2013. endTime: 4,
  2014. text: "在工作中,你如何确保个人防护装备的正确使用?"
  2015. }];
  2016. this.question3Subtitles = [{
  2017. startTime: 0,
  2018. endTime: 4,
  2019. text: "描述一次你与团队合作改善生产流程的经历。"
  2020. }];
  2021. this.question4Subtitles = [{
  2022. startTime: 0,
  2023. endTime: 6,
  2024. text: "你在团队合作中曾遇到过哪些挑战?如何解决团队内部的分歧?"
  2025. }];
  2026. this.question5Subtitles = [{
  2027. startTime: 0,
  2028. endTime: 5,
  2029. text: "您已完成本次面试全部题目,请问您对于这个岗位还有什么想要了解的吗?"
  2030. }];
  2031. },
  2032. // 播放介绍视频
  2033. playIntroVideo() {
  2034. this.videoUrl = this.videoList[0];
  2035. this.videoPlaying = true;
  2036. this.$nextTick(() => {
  2037. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  2038. if (videoContext) {
  2039. videoContext.play();
  2040. }
  2041. });
  2042. },
  2043. // 添加新方法:获取默认问题ID
  2044. getDefaultQuestionId(videoIndex) {
  2045. switch (videoIndex) {
  2046. case 1:
  2047. return 10;
  2048. case 2:
  2049. return 11;
  2050. case 3:
  2051. return 12;
  2052. case 4:
  2053. return 13;
  2054. default:
  2055. return 10;
  2056. }
  2057. },
  2058. // 添加新方法:根据索引获取当前问题
  2059. getCurrentQuestionByIndex(videoIndex) {
  2060. const questionIndex = videoIndex - 1;
  2061. const sortedQuestions = [...this.questions].sort((a, b) => a.sequence_number - b.sequence_number);
  2062. if (questionIndex >= 0 && questionIndex < sortedQuestions.length) {
  2063. return sortedQuestions[questionIndex];
  2064. }
  2065. return null;
  2066. },
  2067. onShow() {
  2068. console.log("identity-verify页面onShow");
  2069. console.log("当前本地存储中的职位信息:", common_vendor.index.getStorageSync("selectedJob"));
  2070. this.fetchQuestions();
  2071. this.fetchFollowUpQuestions();
  2072. },
  2073. // 添加新方法:重置录制状态,准备重新回答
  2074. resetForRerecording() {
  2075. console.log("重置录制状态,准备重新回答");
  2076. this.isRecording = false;
  2077. this.showStopRecordingButton = false;
  2078. this.showStartRecordingButton = true;
  2079. this.clearCountdown();
  2080. if (this.recordingTimer) {
  2081. clearInterval(this.recordingTimer);
  2082. this.recordingTimer = null;
  2083. }
  2084. this.recordingTimerCount = 0;
  2085. this.recordingTimeDisplay = "00:00 ";
  2086. this.remainingTime = this.maxRecordingTime;
  2087. if (this.mediaRecorder && this.mediaRecorder.state !== "inactive") {
  2088. this.mediaRecorder.stop();
  2089. this.recordedChunks = [];
  2090. }
  2091. if (this.cameraContext) {
  2092. this.cameraContext.stopRecord({
  2093. success: () => {
  2094. console.log("相机录制已停止");
  2095. },
  2096. fail: (err) => {
  2097. console.error("停止相机录制失败:", err);
  2098. }
  2099. });
  2100. }
  2101. },
  2102. // 修改 playLowScoreVideo 方法,优化字幕显示
  2103. playLowScoreVideo() {
  2104. console.log("播放低分提示视频");
  2105. this.isPlayingLowScoreVideo = true;
  2106. this.showStartRecordingButton = false;
  2107. this.showStopRecordingButton = false;
  2108. this.showRerecordButton = false;
  2109. this.videoUrl = this.lowScoreVideoUrl;
  2110. this.videoPlaying = true;
  2111. const originalSubtitle = this.currentSubtitle;
  2112. this.currentSubtitle = "";
  2113. this.$nextTick(() => {
  2114. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  2115. if (videoContext) {
  2116. videoContext.play();
  2117. setTimeout(() => {
  2118. this.currentSubtitle = "我未听清楚您在说什么,请您再说一遍!";
  2119. this.lowScoreVideoSubtitles = [
  2120. {
  2121. startTime: 0,
  2122. endTime: 30,
  2123. text: "我未听清楚您在说什么,请您再说一遍!",
  2124. translation: "I didn't quite catch what you said, could you please repeat it?"
  2125. }
  2126. ];
  2127. setTimeout(() => {
  2128. if (this.isFollowUpQuestion && this.currentFollowUpQuestion) {
  2129. this.currentSubtitle = this.currentFollowUpQuestion.digital_human_video_subtitle || this.currentFollowUpQuestion.question;
  2130. } else {
  2131. this.currentSubtitle = originalSubtitle;
  2132. }
  2133. }, 3e3);
  2134. }, 500);
  2135. }
  2136. });
  2137. },
  2138. // 添加新方法:处理重新录制按钮点击
  2139. handleRerecordButtonClick() {
  2140. console.log("点击重新录制按钮");
  2141. this.retryCount++;
  2142. console.log(`当前重试次数: ${this.retryCount}/${this.maxRetryAttempts}`);
  2143. this.showRerecordButton = false;
  2144. this.handleStartRecordingClick();
  2145. },
  2146. // 添加 onUnload 生命周期钩子,移除 WebSocket 关闭
  2147. onUnload() {
  2148. console.log("页面卸载");
  2149. },
  2150. // 修改 onHide 生命周期钩子,移除 WebSocket 关闭
  2151. onHide() {
  2152. console.log("页面隐藏");
  2153. },
  2154. // 添加新方法:阻止视频控制
  2155. preventVideoControl(e) {
  2156. e.preventDefault();
  2157. e.stopPropagation();
  2158. console.log("阻止视频控制操作");
  2159. return false;
  2160. },
  2161. // 添加获取追问问题的方法
  2162. fetchFollowUpQuestions() {
  2163. const tenant_id = JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || "1";
  2164. let position_id = 1;
  2165. try {
  2166. const selectedJob = JSON.parse(common_vendor.index.getStorageSync("selectedJob") || "{}");
  2167. if (selectedJob && selectedJob.id) {
  2168. position_id = selectedJob.id;
  2169. console.log("使用选择的职位ID获取追问问题:", position_id);
  2170. } else {
  2171. console.warn("未找到选择的职位信息,使用默认职位ID:", position_id);
  2172. }
  2173. } catch (e) {
  2174. console.error("解析职位信息失败:", e);
  2175. }
  2176. const timestamp = Date.now();
  2177. const requestUrl = `${common_config.apiBaseUrl}/api/wechat/open_questions/?position_id=${position_id}&tenant_id=${tenant_id}&question_form=5&_t=${timestamp}`;
  2178. console.log("获取追问问题的请求URL:", requestUrl);
  2179. common_vendor.index.request({
  2180. url: requestUrl,
  2181. method: "GET",
  2182. success: (res) => {
  2183. if (res.data && res.data.code === 2e3 && res.data.data && res.data.data.items) {
  2184. console.log("获取追问问题数据成功:", res.data.data.items);
  2185. this.followUpQuestions = res.data.data.items.map((item) => ({
  2186. ...item,
  2187. question_form: 5
  2188. // 确保每个追问问题都有正确的question_form值
  2189. }));
  2190. this.processFollowUpQuestions();
  2191. } else {
  2192. console.error("获取追问问题数据失败:", res.data);
  2193. this.followUpQuestions = [];
  2194. }
  2195. },
  2196. fail: (err) => {
  2197. console.error("请求追问问题数据失败:", err);
  2198. this.followUpQuestions = [];
  2199. }
  2200. });
  2201. },
  2202. // 改进处理追问问题数据的方法
  2203. processFollowUpQuestions() {
  2204. if (!this.followUpQuestions || this.followUpQuestions.length === 0) {
  2205. console.log("没有追问问题数据");
  2206. this.followUpQuestions = [];
  2207. return;
  2208. }
  2209. console.log("处理追问问题数据,总数:", this.followUpQuestions.length);
  2210. this.followUpQuestions = this.followUpQuestions.filter((q) => q.parent_question_id);
  2211. const parentQuestionIds = /* @__PURE__ */ new Set();
  2212. this.followUpQuestions.forEach((question) => {
  2213. if (question.parent_question_id) {
  2214. parentQuestionIds.add(question.parent_question_id);
  2215. }
  2216. });
  2217. console.log("有追问的父问题ID:", Array.from(parentQuestionIds));
  2218. this.hasPlayedFollowUp = {};
  2219. },
  2220. // 修改检查并播放追问问题的方法
  2221. checkAndPlayFollowUpQuestion(parentQuestionId) {
  2222. console.log("检查是否有追问问题,父问题ID:", parentQuestionId);
  2223. if (!parentQuestionId) {
  2224. console.warn("没有父问题ID,无法检查追问问题");
  2225. this.proceedToNextQuestion();
  2226. return;
  2227. }
  2228. if (this.hasPlayedFollowUp[parentQuestionId]) {
  2229. console.log("已经播放过此问题的追问,直接进入下一个问题");
  2230. this.retryCount = 0;
  2231. this.proceedToNextQuestion();
  2232. return;
  2233. }
  2234. const followUpQuestion = this.followUpQuestions.find(
  2235. (q) => q.parent_question_id === parentQuestionId && q.digital_human_video_url && q.question_form === 5
  2236. );
  2237. if (followUpQuestion) {
  2238. console.log("找到追问问题:", followUpQuestion);
  2239. const recordingDuration = this.getRecordingDuration();
  2240. const lowScoreDuration = 7;
  2241. if (recordingDuration < lowScoreDuration) {
  2242. console.log(`录制时间 ${recordingDuration} 秒,少于 ${lowScoreDuration} 秒,将播放低分提示视频`);
  2243. this.retryCount++;
  2244. this.needPlayLowScoreVideo = true;
  2245. this.playLowScoreVideo();
  2246. return;
  2247. }
  2248. this.retryCount = 0;
  2249. this.hasPlayedFollowUp[parentQuestionId] = true;
  2250. this.isFollowUpQuestion = true;
  2251. this.currentParentQuestionId = parentQuestionId;
  2252. this.currentFollowUpQuestion = followUpQuestion;
  2253. this.playFollowUpQuestionVideo(followUpQuestion);
  2254. } else {
  2255. console.log("没有找到对应的追问问题,继续下一个问题");
  2256. this.retryCount = 0;
  2257. this.proceedToNextQuestion();
  2258. }
  2259. },
  2260. // 修改播放追问问题视频的方法
  2261. playFollowUpQuestionVideo(followUpQuestion) {
  2262. console.log("播放追问问题视频:", followUpQuestion.digital_human_video_url);
  2263. this.parentQuestion = this.currentSubtitle;
  2264. this.videoUrl = followUpQuestion.digital_human_video_url;
  2265. this.videoPlaying = true;
  2266. this.isFollowUpQuestion = true;
  2267. this.currentFollowUpQuestion = followUpQuestion;
  2268. const followUpSubtitles = [{
  2269. startTime: 0,
  2270. endTime: 60,
  2271. // 延长显示时间到60秒
  2272. text: followUpQuestion.digital_human_video_subtitle || followUpQuestion.question
  2273. }];
  2274. const subtitleKey = `followUpSubtitles_${followUpQuestion.id}`;
  2275. this[subtitleKey] = followUpSubtitles;
  2276. this.$nextTick(() => {
  2277. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  2278. if (videoContext) {
  2279. videoContext.play();
  2280. this.currentSubtitle = followUpSubtitles[0].text;
  2281. }
  2282. });
  2283. }
  2284. },
  2285. computed: {
  2286. // 计算进度比例
  2287. progressRatio() {
  2288. return this.recordingTimerCount / this.maxRecordingTime;
  2289. },
  2290. // 右半圆旋转角度
  2291. half1Turn() {
  2292. if (this.progressRatio <= 0.5) {
  2293. return this.progressRatio * 2 * 180;
  2294. } else {
  2295. return 180;
  2296. }
  2297. },
  2298. // 左半圆旋转角度
  2299. half2Turn() {
  2300. if (this.progressRatio <= 0.5) {
  2301. return 0;
  2302. } else {
  2303. return (this.progressRatio - 0.5) * 2 * 180;
  2304. }
  2305. },
  2306. // 修改进度百分比的计算方式
  2307. progressPercent() {
  2308. return Math.min(Math.round(this.recordingTimerCount / this.maxRecordingTime * 100), 100);
  2309. },
  2310. // 添加总题数计算属性
  2311. totalQuestions() {
  2312. return this.questions.length || 5;
  2313. }
  2314. }
  2315. };
  2316. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  2317. return common_vendor.e({
  2318. a: $data.videoUrl,
  2319. b: common_vendor.o((...args) => $options.handleVideoError && $options.handleVideoError(...args)),
  2320. c: common_vendor.o((...args) => $options.handleVideoEnded && $options.handleVideoEnded(...args)),
  2321. d: common_vendor.o((...args) => $options.handleTimeUpdate && $options.handleTimeUpdate(...args)),
  2322. e: common_vendor.o((...args) => $options.preventVideoControl && $options.preventVideoControl(...args)),
  2323. f: common_vendor.o((...args) => $options.preventVideoControl && $options.preventVideoControl(...args)),
  2324. g: $data.showAnswerButton
  2325. }, $data.showAnswerButton ? {
  2326. h: common_vendor.o((...args) => $options.handleAnswerButtonClick && $options.handleAnswerButtonClick(...args))
  2327. } : {}, {
  2328. i: $data.currentSubtitle
  2329. }, $data.currentSubtitle ? common_vendor.e({
  2330. j: $data.currentVideoIndex > 0
  2331. }, $data.currentVideoIndex > 0 ? {
  2332. k: common_vendor.t($data.currentVideoIndex),
  2333. l: common_vendor.t($options.totalQuestions)
  2334. } : {}, {
  2335. m: !$data.isFollowUpQuestion
  2336. }, !$data.isFollowUpQuestion ? {
  2337. n: common_vendor.t($data.currentSubtitle)
  2338. } : {
  2339. o: common_vendor.t($data.parentQuestion),
  2340. p: common_vendor.t($data.currentSubtitle)
  2341. }) : {}, {
  2342. q: $data.useMiniProgramCameraComponent
  2343. }, $data.useMiniProgramCameraComponent ? {
  2344. r: common_vendor.o((...args) => $options.handleCameraError && $options.handleCameraError(...args))
  2345. } : {}, {
  2346. s: $data.loading
  2347. }, $data.loading ? {} : {}, {
  2348. t: $data.showDebugInfo
  2349. }, $data.showDebugInfo ? common_vendor.e({
  2350. v: $data.assistantResponse
  2351. }, $data.assistantResponse ? {
  2352. w: common_vendor.t($data.assistantResponse)
  2353. } : {}, {
  2354. x: $data.audioTranscript
  2355. }, $data.audioTranscript ? {
  2356. y: common_vendor.t($data.audioTranscript)
  2357. } : {}, {
  2358. z: common_vendor.f($data.processedResponses, (item, index, i0) => {
  2359. return common_vendor.e({
  2360. a: item.role
  2361. }, item.role ? {
  2362. b: common_vendor.t(item.role)
  2363. } : {}, {
  2364. c: item.transcript
  2365. }, item.transcript ? {
  2366. d: common_vendor.t(item.transcript)
  2367. } : {}, {
  2368. e: index
  2369. });
  2370. })
  2371. }) : {}, {
  2372. A: $data.showStopRecordingButton
  2373. }, $data.showStopRecordingButton ? {
  2374. B: common_vendor.o((...args) => $options.stopRecordingAnswer && $options.stopRecordingAnswer(...args))
  2375. } : {}, {
  2376. C: $data.isRecording
  2377. }, $data.isRecording ? {
  2378. D: common_vendor.t($data.recordingTimeDisplay),
  2379. E: `conic-gradient(${$data.progressColor} ${$options.progressPercent}%, ${$data.progressBgColor} 0%)`
  2380. } : {}, {
  2381. F: $data.showStartRecordingButton
  2382. }, $data.showStartRecordingButton ? {
  2383. G: common_vendor.o((...args) => $options.handleStartRecordingClick && $options.handleStartRecordingClick(...args))
  2384. } : {}, {
  2385. H: $data.showRetryButton
  2386. }, $data.showRetryButton ? {
  2387. I: common_vendor.o((...args) => $options.retryVideoUpload && $options.retryVideoUpload(...args))
  2388. } : {}, {
  2389. J: $data.showCountdown
  2390. }, $data.showCountdown ? {
  2391. K: common_vendor.t($data.countdownValue)
  2392. } : {}, {
  2393. L: $data.showRerecordButton
  2394. }, $data.showRerecordButton ? {
  2395. M: common_vendor.o((...args) => $options.handleRerecordButtonClick && $options.handleRerecordButtonClick(...args))
  2396. } : {});
  2397. }
  2398. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-464e78c6"]]);
  2399. wx.createPage(MiniProgramPage);