interview-question.js 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897
  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: "http://121.36.251.245:9000/minlong/tenant_1/general_uploads/abdaa6fda8494e3a8613304743ed0433.mp4",
  17. // 用于存储AI数字人视频URL
  18. showReplayButton: false,
  19. cameraStream: null,
  20. // 存储摄像头流
  21. cameraError: null,
  22. // 存储摄像头错误信息
  23. useMiniProgramCameraComponent: false,
  24. // 添加小程序相机组件标志
  25. cameraContext: null,
  26. // 添加相机上下文
  27. currentSubtitle: "",
  28. subtitles: [
  29. {
  30. startTime: 0,
  31. // 开始时间(秒)
  32. endTime: 6,
  33. // 结束时间(秒)
  34. text: "您已完成本次面试全部题目,请问您对于这个岗位还有什么想要了解的吗?"
  35. }
  36. ],
  37. // secondVideoSubtitles: [
  38. // {
  39. // startTime: 0,
  40. // endTime: 10,
  41. // text: '请结合您的基本信息与过往履历进行简单的自我介绍,并讲一讲您有哪些优势胜任本岗位:'
  42. // }
  43. // ],
  44. // thirdVideoSubtitles: [
  45. // {
  46. // startTime: 0,
  47. // endTime: 4,
  48. // text: '在工作中,你如何确保个人防护装备的正确使用?'
  49. // }
  50. // ],
  51. // fourthVideoSubtitles: [
  52. // {
  53. // startTime: 0,
  54. // endTime: 4,
  55. // text: '描述一次你与团队合作改善生产流程的经历。'
  56. // }
  57. // ],
  58. // fifthVideoSubtitles: [
  59. // {
  60. // startTime: 0,
  61. // endTime: 6,
  62. // text: '你在团队合作中曾遇到过哪些挑战?如何解决团队内部的分歧?'
  63. // }
  64. // ],
  65. // sixthVideoSubtitles: [
  66. // {
  67. // startTime: 0,
  68. // endTime: 5,
  69. // text: '您已完成本次面试全部题目,请问您对于这个岗位还有什么想要了解的吗?'
  70. // }
  71. // ],
  72. showAnswerButton: false,
  73. // 控制答题按钮显示
  74. currentVideoIndex: 0,
  75. // 当前播放的视频索引
  76. videoList: [
  77. "http://121.36.251.245:9000/minlong/tenant_1/general_uploads/abdaa6fda8494e3a8613304743ed0433.mp4"
  78. //结束
  79. ],
  80. isRecording: false,
  81. recordingTimer: null,
  82. showStopRecordingButton: false,
  83. mediaRecorder: null,
  84. recordedChunks: [],
  85. recorder: null,
  86. lastUploadedVideoUrl: "",
  87. showStartRecordingButton: false,
  88. showRetryButton: false,
  89. // 控制重试按钮显示
  90. lastVideoToRetry: null,
  91. // 存储上次失败的视频URL,用于重试
  92. recordingStartTime: null,
  93. // 录制开始时间
  94. recordingTimerCount: 0,
  95. // 录制计时器计数
  96. recordingTimeDisplay: "00:00",
  97. // 格式化的录制时间显示
  98. // 添加上传队列相关数据
  99. uploadQueue: [],
  100. // 存储待上传的视频
  101. isUploading: false,
  102. // 标记是否正在上传
  103. uploadProgress: {},
  104. // 存储每个视频的上传进度
  105. uploadStatus: {},
  106. // 存储每个视频的上传状态
  107. showUploadStatus: false,
  108. // 是否显示上传状态指示器
  109. uploadStatusText: "",
  110. // 上传状态文本
  111. mediaRecorderTimeout: null,
  112. // 用于存储MediaRecorder的超时机制
  113. maxRecordingTime: 300,
  114. // 最大录制时间(秒)- 从60秒改为300秒(5分钟)
  115. remainingTime: 300,
  116. // 剩余录制时间(秒)- 从60秒改为300秒
  117. // 修改初始视频索引,添加参数控制
  118. startFromLastVideo: false,
  119. // 是否从最后一个视频开始播放
  120. countdownValue: 10,
  121. // 倒计时数值
  122. showCountdown: false,
  123. // 是否显示倒计时蒙层
  124. countdownTimer: null,
  125. showGif: false,
  126. // 控制是否显示GIF
  127. gifUrl: ""
  128. // GIF图片的URL
  129. };
  130. },
  131. onLoad(options) {
  132. if (options && options.startFromLast === "true") {
  133. this.startFromLastVideo = true;
  134. this.currentVideoIndex = this.videoList.length - 1;
  135. }
  136. },
  137. mounted() {
  138. if (this.startFromLastVideo) {
  139. console.log("从最后一个视频开始播放");
  140. this.currentVideoIndex = this.videoList.length - 1;
  141. this.videoUrl = this.videoList[this.currentVideoIndex];
  142. }
  143. this.playDigitalHumanVideo();
  144. this.checkAudioPermission();
  145. this.initCamera();
  146. this.checkIOSCameraRecordPermission();
  147. this.checkAndFixRenderingIssues();
  148. setTimeout(() => {
  149. if (this.cameraStream && !this.useMiniProgramCameraComponent) {
  150. this.testAudioInput();
  151. }
  152. }, 3e3);
  153. common_vendor.index.setKeepScreenOn({
  154. keepScreenOn: true
  155. });
  156. },
  157. beforeDestroy() {
  158. this.stopUserCamera();
  159. },
  160. methods: {
  161. // 初始化相机
  162. async initCamera() {
  163. const systemInfo = common_vendor.index.getSystemInfoSync();
  164. const isMiniProgram = systemInfo.uniPlatform === "mp-weixin" || systemInfo.uniPlatform === "mp-alipay" || systemInfo.uniPlatform === "mp-baidu";
  165. if (isMiniProgram) {
  166. this.useMiniProgramCameraComponent = true;
  167. this.cameraContext = common_vendor.index.createCameraContext();
  168. common_vendor.index.getSetting({
  169. success: (res) => {
  170. if (!res.authSetting["scope.record"]) {
  171. common_vendor.index.authorize({
  172. scope: "scope.record",
  173. success: () => {
  174. console.log("录音权限已获取");
  175. },
  176. fail: (err) => {
  177. console.error("录音权限获取失败:", err);
  178. this.showPermissionDialog("录音");
  179. }
  180. });
  181. }
  182. if (!res.authSetting["scope.camera"]) {
  183. common_vendor.index.authorize({
  184. scope: "scope.camera",
  185. success: () => {
  186. console.log("相机权限已获取");
  187. },
  188. fail: (err) => {
  189. console.error("相机权限获取失败:", err);
  190. this.showPermissionDialog("相机");
  191. }
  192. });
  193. }
  194. const systemInfo2 = common_vendor.index.getSystemInfoSync();
  195. if (systemInfo2.platform === "ios") {
  196. if (!res.authSetting["scope.camera"] || !res.authSetting["scope.record"]) {
  197. console.log("iOS需要同时获取相机和录音权限");
  198. }
  199. }
  200. }
  201. });
  202. } else {
  203. try {
  204. const constraints = {
  205. audio: {
  206. echoCancellation: true,
  207. noiseSuppression: true,
  208. autoGainControl: true
  209. },
  210. video: {
  211. width: { ideal: 640, max: 1280 },
  212. // 控制视频宽度
  213. height: { ideal: 480, max: 720 },
  214. // 控制视频高度
  215. frameRate: { ideal: 15, max: 24 },
  216. // 控制帧率
  217. facingMode: "user"
  218. }
  219. };
  220. const stream = await navigator.mediaDevices.getUserMedia(constraints);
  221. this.cameraStream = stream;
  222. const audioTracks = stream.getAudioTracks();
  223. console.log("音频轨道数量:", audioTracks.length);
  224. if (audioTracks.length > 0) {
  225. console.log("音频轨道已获取:", audioTracks[0].label);
  226. audioTracks[0].enabled = true;
  227. } else {
  228. console.warn("未检测到音频轨道,尝试单独获取音频");
  229. this.tryGetAudioOnly();
  230. }
  231. const videoElement = this.$refs.userCameraVideo;
  232. if (videoElement) {
  233. videoElement.srcObject = stream;
  234. videoElement.muted = true;
  235. }
  236. } catch (error) {
  237. console.error("获取摄像头失败:", error);
  238. this.cameraError = error.message || "无法访问摄像头";
  239. common_vendor.index.showToast({
  240. title: "无法访问摄像头,请检查权限设置",
  241. icon: "none"
  242. });
  243. }
  244. }
  245. },
  246. // 停止用户摄像头
  247. stopUserCamera() {
  248. if (this.cameraStream) {
  249. this.cameraStream.getTracks().forEach((track) => {
  250. track.stop();
  251. });
  252. this.cameraStream = null;
  253. }
  254. },
  255. async fetchData() {
  256. this.loading = true;
  257. this.assistantResponse = "";
  258. this.audioTranscript = "";
  259. this.processedResponses = [];
  260. try {
  261. const requestTask = common_vendor.index.request({
  262. url: "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions",
  263. method: "POST",
  264. header: {
  265. "Content-Type": "application/json",
  266. "Authorization": "Bearer sk-9e1ec73a7d97493b8613c63f06b6110c"
  267. },
  268. data: {
  269. "model": "qwen-omni-turbo",
  270. "messages": [
  271. {
  272. "role": "user",
  273. "content": [
  274. {
  275. "type": "input_audio",
  276. "input_audio": {
  277. "data": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250211/tixcef/cherry.wav",
  278. "format": "wav"
  279. }
  280. },
  281. {
  282. "type": "text",
  283. "text": "这段音频在说什么"
  284. }
  285. ]
  286. }
  287. ],
  288. "stream": true,
  289. "stream_options": {
  290. "include_usage": true
  291. },
  292. "modalities": ["text", "audio"],
  293. "audio": { "voice": "Cherry", "format": "wav" }
  294. },
  295. success: (res) => {
  296. console.log("请求成功,响应数据:", res.data);
  297. if (typeof res.data === "string" && res.data.includes("data: {")) {
  298. const chunks = res.data.split("data: ").filter((chunk) => chunk.trim() !== "");
  299. chunks.forEach((chunk) => {
  300. this.handleStreamResponse(chunk);
  301. });
  302. } else {
  303. this.handleStreamResponse(res.data);
  304. }
  305. this.playDigitalHumanVideo();
  306. },
  307. fail: (err) => {
  308. console.error("请求失败:", err);
  309. },
  310. complete: () => {
  311. this.loading = false;
  312. }
  313. });
  314. } catch (error) {
  315. console.error("获取数据失败:", error);
  316. this.loading = false;
  317. }
  318. },
  319. handleStreamResponse(data) {
  320. if (typeof data === "string") {
  321. if (data === "[DONE]")
  322. return;
  323. try {
  324. const cleanData = data.trim();
  325. if (cleanData.startsWith("{") && cleanData.endsWith("}")) {
  326. const jsonData = JSON.parse(cleanData);
  327. this.processStreamChunk(jsonData);
  328. }
  329. } catch (e) {
  330. console.error("解析JSON失败:", e, "原始数据:", data);
  331. }
  332. } else {
  333. this.processStreamChunk(data);
  334. }
  335. },
  336. processStreamChunk(chunk) {
  337. if (chunk.choices && chunk.choices.length > 0) {
  338. const choice = chunk.choices[0];
  339. if (choice.delta && choice.delta.content) {
  340. this.assistantResponse += choice.delta.content;
  341. }
  342. if (choice.delta && choice.delta.audio && choice.delta.audio.transcript) {
  343. this.audioTranscript += choice.delta.audio.transcript;
  344. }
  345. if (choice.delta) {
  346. const result = {};
  347. if (choice.delta.role) {
  348. result.role = choice.delta.role;
  349. }
  350. if (choice.delta.audio && choice.delta.audio.transcript) {
  351. result.transcript = choice.delta.audio.transcript;
  352. }
  353. if (Object.keys(result).length > 0) {
  354. this.processedResponses.push(result);
  355. }
  356. }
  357. }
  358. },
  359. processResponseData() {
  360. this.processedResponses = this.responses.map((item) => {
  361. const result = {};
  362. if (item.delta && item.delta.role) {
  363. result.role = item.delta.role;
  364. }
  365. if (item.delta && item.delta.audio && item.delta.audio.transcript) {
  366. result.transcript = item.delta.audio.transcript;
  367. }
  368. return result;
  369. }).filter((item) => Object.keys(item).length > 0);
  370. },
  371. // 播放数字人视频
  372. playDigitalHumanVideo() {
  373. this.videoUrl = this.videoList[this.currentVideoIndex];
  374. this.videoPlaying = true;
  375. console.log(`播放视频 ${this.currentVideoIndex + 1}/${this.videoList.length}: ${this.videoUrl}`);
  376. this.$nextTick(() => {
  377. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  378. if (videoContext) {
  379. videoContext.play();
  380. setTimeout(() => {
  381. if (this.videoPlaying && this.$refs.videoPlayer) {
  382. console.log("视频应该正在播放");
  383. } else {
  384. console.log("视频可能未成功播放,尝试替代方案");
  385. this.tryAlternativeVideoPath();
  386. }
  387. }, 1e3);
  388. } else {
  389. console.error("无法创建视频上下文");
  390. this.tryAlternativeVideoPath();
  391. }
  392. });
  393. },
  394. // 修改 tryAlternativeVideoPath 方法
  395. tryAlternativeVideoPath() {
  396. console.log("尝试使用替代路径");
  397. const alternativePaths = [
  398. "./static/demo.mp4",
  399. "../static/demo.mp4",
  400. "static/demo.mp4",
  401. "/static/demo.mp4",
  402. // 添加绝对路径
  403. `${window.location.origin}/static/demo.mp4`
  404. ];
  405. const currentPathIndex = alternativePaths.indexOf(this.videoUrl);
  406. const nextPathIndex = (currentPathIndex + 1) % alternativePaths.length;
  407. this.videoUrl = alternativePaths[nextPathIndex];
  408. console.log("尝试新路径:", this.videoUrl);
  409. this.$nextTick(() => {
  410. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  411. if (videoContext) {
  412. videoContext.stop();
  413. videoContext.play();
  414. setTimeout(() => {
  415. if (nextPathIndex === alternativePaths.length - 1 && !this.videoPlaying) {
  416. console.log("所有路径均失败,尝试使用uni.getVideoInfo检查视频");
  417. this.checkVideoWithAPI();
  418. }
  419. }, 1e3);
  420. }
  421. });
  422. },
  423. // 添加新方法:使用uni API检查视频
  424. checkVideoWithAPI() {
  425. common_vendor.index.getVideoInfo({
  426. src: "/static/demo.mp4",
  427. success: (res) => {
  428. console.log("视频信息获取成功:", res);
  429. this.videoUrl = "/static/demo.mp4";
  430. this.$nextTick(() => {
  431. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  432. if (videoContext) {
  433. videoContext.play();
  434. }
  435. });
  436. },
  437. fail: (err) => {
  438. console.error("视频信息获取失败:", err);
  439. this.fallbackToLocalVideo();
  440. }
  441. });
  442. },
  443. // 添加新方法:回退到本地视频
  444. fallbackToLocalVideo() {
  445. console.log("尝试使用本地视频资源");
  446. const platform = common_vendor.index.getSystemInfoSync().platform;
  447. if (platform === "android" || platform === "ios") {
  448. this.videoUrl = platform === "android" ? "android.resource://package_name/raw/demo" : "file:///assets/demo.mp4";
  449. this.$nextTick(() => {
  450. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  451. if (videoContext) {
  452. videoContext.play();
  453. }
  454. });
  455. } else {
  456. this.videoPlaying = false;
  457. common_vendor.index.showToast({
  458. title: "视频加载失败,显示静态图片",
  459. icon: "none"
  460. });
  461. }
  462. },
  463. // 修改 handleVideoError 方法
  464. handleVideoError(e) {
  465. console.error("视频加载错误:", e);
  466. if (e && e.detail) {
  467. console.error("详细错误信息:", e.detail);
  468. }
  469. common_vendor.index.getFileInfo({
  470. filePath: this.videoUrl.startsWith("/") ? this.videoUrl.substring(1) : this.videoUrl,
  471. success: (res) => {
  472. console.log("文件存在,大小:", res.size);
  473. this.tryDifferentFormat();
  474. },
  475. fail: (err) => {
  476. console.error("文件不存在或无法访问:", err);
  477. this.tryAlternativeVideoPath();
  478. }
  479. });
  480. common_vendor.index.showToast({
  481. title: "视频加载失败,请检查文件是否存在",
  482. icon: "none",
  483. duration: 2e3
  484. });
  485. },
  486. // 添加新方法:尝试不同格式
  487. tryDifferentFormat() {
  488. console.log("尝试不同的视频格式");
  489. const formats = [
  490. { ext: "mp4", mime: "video/mp4" },
  491. { ext: "webm", mime: "video/webm" },
  492. { ext: "ogg", mime: "video/ogg" },
  493. { ext: "mov", mime: "video/quicktime" }
  494. ];
  495. const currentPath = this.videoUrl;
  496. const basePath = currentPath.substring(0, currentPath.lastIndexOf(".")) || "/static/demo";
  497. let nextFormat = formats.find((f) => !currentPath.endsWith(f.ext));
  498. if (nextFormat) {
  499. this.videoUrl = `${basePath}.${nextFormat.ext}`;
  500. console.log("尝试新格式:", this.videoUrl);
  501. this.$nextTick(() => {
  502. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  503. if (videoContext) {
  504. videoContext.stop();
  505. videoContext.play();
  506. }
  507. });
  508. } else {
  509. this.useBuiltInResource();
  510. }
  511. },
  512. // 添加新方法:使用内置资源
  513. useBuiltInResource() {
  514. console.log("尝试使用内置资源");
  515. const platform = common_vendor.index.getSystemInfoSync().platform;
  516. if (platform === "windows") {
  517. process.env.UNI_INPUT_DIR || "";
  518. this.videoUrl = `./static/demo.mp4`;
  519. console.log("Windows平台尝试路径:", this.videoUrl);
  520. } else if (platform === "android" || platform === "ios") {
  521. this.useNativeVideo();
  522. } else {
  523. const baseUrl = window.location.origin;
  524. this.videoUrl = `${baseUrl}/static/demo.mp4`;
  525. console.log("Web平台尝试URL:", this.videoUrl);
  526. }
  527. this.$nextTick(() => {
  528. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  529. if (videoContext) {
  530. videoContext.play();
  531. }
  532. });
  533. },
  534. // 添加新方法:使用原生视频能力
  535. useNativeVideo() {
  536. console.log("尝试使用原生视频能力");
  537. common_vendor.index.chooseVideo({
  538. sourceType: ["album"],
  539. success: (res) => {
  540. this.videoUrl = res.tempFilePath;
  541. this.$nextTick(() => {
  542. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  543. if (videoContext) {
  544. videoContext.play();
  545. }
  546. });
  547. },
  548. fail: () => {
  549. this.videoPlaying = false;
  550. common_vendor.index.showToast({
  551. title: "无法加载视频,显示静态图片",
  552. icon: "none"
  553. });
  554. }
  555. });
  556. },
  557. // 处理视频结束事件
  558. handleVideoEnded() {
  559. console.log("视频播放结束,当前视频索引:", this.currentVideoIndex);
  560. this.videoPlaying = false;
  561. this.gifUrl = "http://121.36.251.245:9000/minlong/cae2da8f92ce4af278d3929ab8c5973f.mp4";
  562. this.showGif = true;
  563. this.showStartRecordingButton = true;
  564. this.startCountdown();
  565. this.showAnswerButton = false;
  566. },
  567. // 添加新方法:开始倒计时
  568. startCountdown() {
  569. this.showCountdown = true;
  570. this.countdownValue = 10;
  571. this.countdownTimer = setInterval(() => {
  572. this.countdownValue--;
  573. if (this.countdownValue <= 0) {
  574. this.clearCountdown();
  575. this.showStartRecordingButton = false;
  576. this.startRecordingAnswer();
  577. }
  578. }, 1e3);
  579. },
  580. // 添加新方法:清除倒计时
  581. clearCountdown() {
  582. if (this.countdownTimer) {
  583. clearInterval(this.countdownTimer);
  584. this.countdownTimer = null;
  585. }
  586. this.showCountdown = false;
  587. },
  588. // 修改 handleStartRecordingClick 方法,使其可以终止倒计时
  589. handleStartRecordingClick() {
  590. this.showStartRecordingButton = false;
  591. this.clearCountdown();
  592. this.startRecordingAnswer();
  593. },
  594. // 修改 stopRecordingAnswer 方法,确保清除倒计时
  595. stopRecordingAnswer() {
  596. this.clearCountdown();
  597. const recordingDuration = this.getRecordingDuration();
  598. const minimumDuration = 5;
  599. if (recordingDuration < minimumDuration) {
  600. common_vendor.index.showToast({
  601. title: "录制时间过短,请至少录制5秒",
  602. icon: "none",
  603. duration: 2e3
  604. });
  605. return;
  606. }
  607. this.completeRecordingStop();
  608. },
  609. // 添加新方法:开始录制用户回答
  610. startRecordingAnswer() {
  611. console.log("开始录制用户回答");
  612. this.isRecording = true;
  613. this.recordingStartTime = Date.now();
  614. this.recordingTimerCount = 0;
  615. this.remainingTime = this.maxRecordingTime;
  616. this.recordingTimer = setInterval(() => {
  617. this.recordingTimerCount++;
  618. this.remainingTime = Math.max(0, this.maxRecordingTime - this.recordingTimerCount);
  619. this.recordingTimeDisplay = this.formatTime(this.recordingTimerCount) + " / " + this.formatTime(this.maxRecordingTime);
  620. if (this.recordingTimerCount >= this.maxRecordingTime) {
  621. console.log("已达到最大录制时间(60秒),自动停止录制");
  622. this.stopRecordingAnswer();
  623. }
  624. }, 1e3);
  625. const systemInfo = common_vendor.index.getSystemInfoSync();
  626. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
  627. if (isMiniProgram) {
  628. this.startMiniProgramRecording();
  629. } else {
  630. this.startBrowserRecording();
  631. }
  632. this.showStopRecordingButton = true;
  633. },
  634. // 添加一个新方法:重置相机组件
  635. resetCamera() {
  636. console.log("重置相机组件");
  637. this.useMiniProgramCameraComponent = false;
  638. if (this.cameraContext) {
  639. this.cameraContext = null;
  640. }
  641. setTimeout(() => {
  642. this.useMiniProgramCameraComponent = true;
  643. setTimeout(() => {
  644. this.cameraContext = common_vendor.index.createCameraContext();
  645. console.log("相机组件已重置");
  646. }, 500);
  647. }, 500);
  648. },
  649. // 修改 startMiniProgramRecording 方法
  650. startMiniProgramRecording() {
  651. console.log("开始小程序录制方法");
  652. const systemInfo = common_vendor.index.getSystemInfoSync();
  653. const isIOS = systemInfo.platform === "ios";
  654. if (isIOS) {
  655. this.resetCamera();
  656. setTimeout(() => {
  657. this.actualStartRecording(isIOS);
  658. }, 1e3);
  659. } else {
  660. this.actualStartRecording(isIOS);
  661. }
  662. },
  663. // 添加新方法:实际开始录制
  664. actualStartRecording(isIOS) {
  665. if (!this.cameraContext) {
  666. this.cameraContext = common_vendor.index.createCameraContext();
  667. console.log("创建新的相机上下文");
  668. }
  669. common_vendor.index.getSetting({
  670. success: (res) => {
  671. const hasRecordAuth = res.authSetting["scope.record"];
  672. const hasCameraAuth = res.authSetting["scope.camera"];
  673. if (!hasRecordAuth || !hasCameraAuth) {
  674. console.warn("缺少必要权限,请求权限");
  675. this.requestMiniProgramPermissions();
  676. return;
  677. }
  678. if (isIOS) {
  679. console.log("iOS: 检查相机状态");
  680. const options = {
  681. timeout: 3e5,
  682. // 300秒超时 (5分钟)
  683. quality: "low",
  684. // 降低质量
  685. compressed: true,
  686. success: () => {
  687. console.log("iOS录制开始成功");
  688. },
  689. fail: (err) => {
  690. console.error("iOS录制失败:", err);
  691. this.useAlternativeRecordingMethod();
  692. }
  693. };
  694. try {
  695. console.log("尝试开始录制");
  696. this.recorder = this.cameraContext.startRecord(options);
  697. } catch (e) {
  698. console.error("开始录制异常:", e);
  699. this.useAlternativeRecordingMethod();
  700. }
  701. } else {
  702. const options = {
  703. timeout: 3e5,
  704. // 300秒超时 (5分钟)
  705. quality: "medium",
  706. compressed: true,
  707. success: () => {
  708. console.log("Android录制开始成功");
  709. },
  710. fail: (err) => {
  711. console.error("Android录制失败:", err);
  712. common_vendor.index.showToast({
  713. title: "录制失败,请检查相机权限",
  714. icon: "none"
  715. });
  716. this.proceedToNextQuestion();
  717. }
  718. };
  719. this.recorder = this.cameraContext.startRecord(options);
  720. }
  721. }
  722. });
  723. },
  724. // 添加新方法:使用替代录制方法
  725. useAlternativeRecordingMethod() {
  726. console.log("使用替代录制方法");
  727. common_vendor.index.showActionSheet({
  728. itemList: ["使用相册中的视频", "跳过此问题"],
  729. success: (res) => {
  730. if (res.tapIndex === 0) {
  731. common_vendor.index.chooseVideo({
  732. sourceType: ["album"],
  733. maxDuration: 300,
  734. // 从60秒改为300秒
  735. camera: "front",
  736. success: (res2) => {
  737. console.log("选择视频成功:", res2.tempFilePath);
  738. this.isRecording = false;
  739. this.showStopRecordingButton = false;
  740. this.uploadRecordedVideo(res2.tempFilePath);
  741. },
  742. fail: () => {
  743. console.log("用户取消选择视频");
  744. this.proceedToNextQuestion();
  745. }
  746. });
  747. } else {
  748. console.log("用户选择跳过问题");
  749. this.proceedToNextQuestion();
  750. }
  751. },
  752. fail: () => {
  753. console.log("操作取消");
  754. this.proceedToNextQuestion();
  755. }
  756. });
  757. },
  758. // 添加新方法:请求小程序权限
  759. requestMiniProgramPermissions() {
  760. common_vendor.index.authorize({
  761. scope: "scope.record",
  762. success: () => {
  763. console.log("录音权限已获取");
  764. common_vendor.index.authorize({
  765. scope: "scope.camera",
  766. success: () => {
  767. console.log("相机权限已获取");
  768. this.startMiniProgramRecording();
  769. },
  770. fail: (err) => {
  771. console.error("相机权限获取失败:", err);
  772. this.showPermissionDialog("相机");
  773. }
  774. });
  775. },
  776. fail: (err) => {
  777. console.error("录音权限获取失败:", err);
  778. this.showPermissionDialog("录音");
  779. }
  780. });
  781. },
  782. // 修改浏览器环境下的录制方法
  783. startBrowserRecording() {
  784. if (!this.cameraStream) {
  785. console.error("没有可用的摄像头流");
  786. common_vendor.index.showToast({
  787. title: "录制失败,摄像头未就绪",
  788. icon: "none"
  789. });
  790. this.proceedToNextQuestion();
  791. return;
  792. }
  793. try {
  794. const hasAudio = this.cameraStream.getAudioTracks().length > 0;
  795. if (!hasAudio) {
  796. console.warn("警告:媒体流中没有音频轨道,尝试重新获取带音频的媒体流");
  797. navigator.mediaDevices.getUserMedia({
  798. audio: {
  799. echoCancellation: true,
  800. noiseSuppression: true,
  801. autoGainControl: true
  802. },
  803. video: true
  804. }).then((newStream) => {
  805. const audioTracks = newStream.getAudioTracks();
  806. if (audioTracks.length > 0) {
  807. console.log("成功获取音频轨道:", audioTracks[0].label);
  808. const videoTrack = this.cameraStream.getVideoTracks()[0];
  809. const audioTrack = newStream.getAudioTracks()[0];
  810. const combinedStream = new MediaStream();
  811. if (videoTrack)
  812. combinedStream.addTrack(videoTrack);
  813. if (audioTrack)
  814. combinedStream.addTrack(audioTrack);
  815. this.cameraStream = combinedStream;
  816. const videoElement = this.$refs.userCameraVideo;
  817. if (videoElement) {
  818. videoElement.srcObject = combinedStream;
  819. videoElement.muted = true;
  820. }
  821. this.setupMediaRecorder(combinedStream);
  822. } else {
  823. console.warn("仍然无法获取音频轨道");
  824. this.setupMediaRecorder(this.cameraStream);
  825. }
  826. }).catch((err) => {
  827. console.error("获取音频失败:", err);
  828. this.setupMediaRecorder(this.cameraStream);
  829. });
  830. } else {
  831. console.log("检测到音频轨道,直接使用");
  832. this.setupMediaRecorder(this.cameraStream);
  833. }
  834. } catch (error) {
  835. console.error("浏览器录制失败:", error);
  836. common_vendor.index.showToast({
  837. title: "录制失败,浏览器可能不支持此功能",
  838. icon: "none"
  839. });
  840. this.proceedToNextQuestion();
  841. }
  842. },
  843. // 修改 setupMediaRecorder 方法
  844. setupMediaRecorder(stream) {
  845. const videoTracks = stream.getVideoTracks();
  846. const audioTracks = stream.getAudioTracks();
  847. console.log("设置MediaRecorder - 视频轨道:", videoTracks.length, "音频轨道:", audioTracks.length);
  848. let mimeType = "";
  849. const supportedTypes = [
  850. "video/webm;codecs=vp9,opus",
  851. "video/webm;codecs=vp8,opus",
  852. "video/webm;codecs=h264,opus",
  853. "video/mp4;codecs=h264,aac",
  854. "video/webm",
  855. "video/mp4"
  856. ];
  857. for (const type of supportedTypes) {
  858. if (MediaRecorder.isTypeSupported(type)) {
  859. mimeType = type;
  860. console.log("使用支持的MIME类型:", mimeType);
  861. break;
  862. }
  863. }
  864. const options = {
  865. mimeType: mimeType || "",
  866. audioBitsPerSecond: 64e3,
  867. // 降低音频比特率
  868. videoBitsPerSecond: 1e6
  869. // 降低视频比特率到1Mbps
  870. };
  871. try {
  872. this.mediaRecorder = new MediaRecorder(stream, options);
  873. console.log("MediaRecorder创建成功,使用选项:", options);
  874. } catch (e) {
  875. console.warn("使用指定选项创建MediaRecorder失败,尝试使用默认选项");
  876. this.mediaRecorder = new MediaRecorder(stream);
  877. }
  878. this.recordedChunks = [];
  879. this.mediaRecorder.ondataavailable = (event) => {
  880. if (event.data && event.data.size > 0) {
  881. this.recordedChunks.push(event.data);
  882. console.log(`收到数据块: ${event.data.size} 字节`);
  883. }
  884. };
  885. this.mediaRecorder.onstop = async () => {
  886. console.log("MediaRecorder停止,数据块数量:", this.recordedChunks.length);
  887. if (this.recordedChunks.length === 0) {
  888. console.error("没有录制到数据");
  889. common_vendor.index.showToast({
  890. title: "录制失败,未捕获到数据",
  891. icon: "none"
  892. });
  893. this.proceedToNextQuestion();
  894. return;
  895. }
  896. const mimeType2 = this.mediaRecorder.mimeType || "video/webm";
  897. const blob = new Blob(this.recordedChunks, { type: mimeType2 });
  898. console.log("创建Blob,原始大小:", blob.size, "类型:", mimeType2);
  899. common_vendor.index.showLoading({
  900. title: "正在处理视频...",
  901. mask: true
  902. });
  903. try {
  904. const compressedBlob = await this.compressVideo(blob);
  905. const fileName = `answer_${this.currentVideoIndex}_${Date.now()}.webm`;
  906. const file = new File([compressedBlob], fileName, { type: mimeType2 });
  907. common_vendor.index.hideLoading();
  908. this.uploadRecordedVideo(file);
  909. } catch (error) {
  910. console.error("视频处理失败:", error);
  911. common_vendor.index.hideLoading();
  912. const fileName = `answer_${this.currentVideoIndex}_${Date.now()}.webm`;
  913. const file = new File([blob], fileName, { type: mimeType2 });
  914. this.uploadRecordedVideo(file);
  915. }
  916. };
  917. this.mediaRecorder.onerror = (event) => {
  918. console.error("MediaRecorder错误:", event.error);
  919. };
  920. try {
  921. this.mediaRecorder.start(1e3);
  922. console.log("MediaRecorder开始录制");
  923. this.mediaRecorderTimeout = setTimeout(() => {
  924. if (this.mediaRecorder && this.mediaRecorder.state === "recording") {
  925. console.log("MediaRecorder备份超时机制触发,停止录制");
  926. this.mediaRecorder.stop();
  927. }
  928. }, 3e5);
  929. } catch (e) {
  930. console.error("开始录制失败:", e);
  931. }
  932. },
  933. // 添加新方法:停止录制用户回答
  934. stopRecordingAnswer() {
  935. console.log("停止录制用户回答");
  936. if (this.countdownTimer) {
  937. clearInterval(this.countdownTimer);
  938. this.countdownTimer = null;
  939. this.showCountdown = false;
  940. }
  941. const recordingDuration = this.getRecordingDuration();
  942. const minimumDuration = 5;
  943. if (recordingDuration < minimumDuration) {
  944. common_vendor.index.showToast({
  945. title: "录制时间过短,请至少录制5秒",
  946. icon: "none",
  947. duration: 2e3
  948. });
  949. return;
  950. }
  951. this.completeRecordingStop();
  952. },
  953. // 添加新方法:获取录制时长
  954. getRecordingDuration() {
  955. if (this.recordingStartTime) {
  956. return (Date.now() - this.recordingStartTime) / 1e3;
  957. }
  958. if (this.mediaRecorder && this.$refs.userCameraVideo) {
  959. return this.$refs.userCameraVideo.currentTime || 0;
  960. }
  961. if (this.recordingTimerCount) {
  962. return this.recordingTimerCount;
  963. }
  964. return 0;
  965. },
  966. // 添加新方法:重置录制
  967. resetRecording() {
  968. if (this.recordingTimer) {
  969. clearTimeout(this.recordingTimer);
  970. }
  971. this.recordingStartTime = Date.now();
  972. this.recordingTimerCount = 0;
  973. if (this.mediaRecorder && this.mediaRecorder.state !== "inactive") {
  974. this.mediaRecorder.stop();
  975. this.recordedChunks = [];
  976. setTimeout(() => {
  977. this.startBrowserRecording();
  978. }, 500);
  979. } else if (this.cameraContext) {
  980. this.cameraContext.stopRecord({
  981. success: () => {
  982. console.log("重置录制:停止当前录制成功");
  983. setTimeout(() => {
  984. this.startMiniProgramRecording();
  985. }, 500);
  986. },
  987. fail: (err) => {
  988. console.error("重置录制:停止当前录制失败", err);
  989. this.startMiniProgramRecording();
  990. }
  991. });
  992. }
  993. common_vendor.index.showToast({
  994. title: "请重新开始回答",
  995. icon: "none",
  996. duration: 2e3
  997. });
  998. },
  999. // 添加新方法:完成录制停止流程
  1000. completeRecordingStop() {
  1001. this.isRecording = false;
  1002. if (this.recordingTimer) {
  1003. clearInterval(this.recordingTimer);
  1004. this.recordingTimer = null;
  1005. }
  1006. if (this.mediaRecorderTimeout) {
  1007. clearTimeout(this.mediaRecorderTimeout);
  1008. this.mediaRecorderTimeout = null;
  1009. }
  1010. common_vendor.index.hideLoading();
  1011. this.showStopRecordingButton = false;
  1012. const systemInfo = common_vendor.index.getSystemInfoSync();
  1013. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
  1014. if (isMiniProgram) {
  1015. this.stopMiniProgramRecording();
  1016. } else {
  1017. this.stopBrowserRecording();
  1018. }
  1019. },
  1020. // 修改 stopMiniProgramRecording 方法
  1021. stopMiniProgramRecording() {
  1022. if (!this.cameraContext) {
  1023. console.error("相机上下文不存在");
  1024. this.proceedToNextQuestion();
  1025. return;
  1026. }
  1027. const systemInfo = common_vendor.index.getSystemInfoSync();
  1028. const isIOS = systemInfo.platform === "ios";
  1029. const stopOptions = {
  1030. success: (res) => {
  1031. console.log("小程序录像停止成功:", res);
  1032. const tempFilePath = res.tempVideoPath;
  1033. if (!tempFilePath) {
  1034. console.error("未获取到视频文件路径");
  1035. common_vendor.index.showToast({
  1036. title: "录制失败,未获取到视频文件",
  1037. icon: "none"
  1038. });
  1039. this.proceedToNextQuestion();
  1040. return;
  1041. }
  1042. if (isIOS) {
  1043. common_vendor.index.getFileInfo({
  1044. filePath: tempFilePath,
  1045. success: () => {
  1046. this.uploadRecordedVideo(tempFilePath);
  1047. },
  1048. fail: (err) => {
  1049. console.error("视频文件不存在:", err);
  1050. common_vendor.index.showToast({
  1051. title: "录制失败,视频文件不存在",
  1052. icon: "none"
  1053. });
  1054. this.proceedToNextQuestion();
  1055. }
  1056. });
  1057. } else {
  1058. this.uploadRecordedVideo(tempFilePath);
  1059. }
  1060. },
  1061. fail: (err) => {
  1062. console.error("小程序录像停止失败:", err);
  1063. common_vendor.index.showToast({
  1064. title: "录制失败",
  1065. icon: "none"
  1066. });
  1067. this.proceedToNextQuestion();
  1068. }
  1069. };
  1070. this.cameraContext.stopRecord(stopOptions);
  1071. },
  1072. // 添加新方法:停止浏览器录制
  1073. stopBrowserRecording() {
  1074. if (this.mediaRecorder && this.mediaRecorder.state !== "inactive") {
  1075. this.mediaRecorder.stop();
  1076. console.log("浏览器录制停止成功");
  1077. } else {
  1078. console.error("MediaRecorder不存在或已经停止");
  1079. this.proceedToNextQuestion();
  1080. }
  1081. },
  1082. // 修改上传录制的视频方法
  1083. uploadRecordedVideo(fileOrPath) {
  1084. console.log("准备上传视频:", typeof fileOrPath === "string" ? fileOrPath : fileOrPath.name);
  1085. let questionId = 10;
  1086. const uploadTask = {
  1087. id: Date.now().toString(),
  1088. // 生成唯一ID
  1089. file: fileOrPath,
  1090. questionId,
  1091. attempts: 0,
  1092. // 上传尝试次数
  1093. maxAttempts: 3
  1094. // 最大尝试次数
  1095. };
  1096. this.uploadQueue.push(uploadTask);
  1097. this.uploadProgress[uploadTask.id] = 0;
  1098. this.uploadStatus[uploadTask.id] = "pending";
  1099. common_vendor.index.showToast({
  1100. title: "已完成回答",
  1101. icon: "none",
  1102. duration: 1500
  1103. });
  1104. this.updateUploadStatusText();
  1105. if (!this.isUploading) {
  1106. this.processUploadQueue();
  1107. }
  1108. this.proceedToNextQuestion();
  1109. },
  1110. // 修改 processUploadQueue 方法,添加后台上传支持
  1111. processUploadQueue() {
  1112. if (this.uploadQueue.length === 0) {
  1113. this.isUploading = false;
  1114. this.showUploadStatus = false;
  1115. try {
  1116. common_vendor.index.removeStorageSync("videoUploadStatus");
  1117. } catch (e) {
  1118. console.error("清除上传状态失败:", e);
  1119. }
  1120. this.notifyUploadComplete();
  1121. return;
  1122. }
  1123. this.isUploading = true;
  1124. this.showUploadStatus = true;
  1125. const task = this.uploadQueue[0];
  1126. this.uploadStatus[task.id] = "uploading";
  1127. this.updateUploadStatusText();
  1128. task.attempts++;
  1129. if (typeof task.file !== "string") {
  1130. this.uploadFileWithXHR(task);
  1131. } else {
  1132. this.uploadFileWithUni(task);
  1133. }
  1134. this.saveUploadStatus();
  1135. },
  1136. // 添加新方法:发送上传完成通知
  1137. notifyUploadComplete() {
  1138. try {
  1139. common_vendor.index.$emit("videoUploadComplete", {
  1140. timestamp: Date.now()
  1141. });
  1142. console.log("发送上传完成通知");
  1143. } catch (e) {
  1144. console.error("发送上传完成通知失败:", e);
  1145. }
  1146. const systemInfo = common_vendor.index.getSystemInfoSync();
  1147. if (systemInfo.platform === "android" || systemInfo.platform === "ios") {
  1148. if (plus && plus.push) {
  1149. plus.push.createMessage("视频上传完成", "您的面试视频已成功上传", {});
  1150. }
  1151. }
  1152. },
  1153. // 添加新方法:使用XMLHttpRequest上传文件
  1154. uploadFileWithXHR(task) {
  1155. const userInfo = common_vendor.index.getStorageSync("userInfo");
  1156. const openid = userInfo ? JSON.parse(userInfo).openid || "" : "";
  1157. const tenant_id = common_vendor.index.getStorageSync("tenant_id") || "1";
  1158. const formData = new FormData();
  1159. formData.append("file", task.file);
  1160. formData.append("openid", openid);
  1161. formData.append("tenant_id", tenant_id);
  1162. formData.append("application_id", common_vendor.index.getStorageSync("appId"));
  1163. formData.append("question_id", task.questionId);
  1164. formData.append("video_duration", 0);
  1165. formData.append("has_audio", "true");
  1166. const xhr = new XMLHttpRequest();
  1167. xhr.open("POST", `${common_config.apiBaseUrl}/api/upload/`, true);
  1168. xhr.timeout = 12e4;
  1169. xhr.upload.onprogress = (event) => {
  1170. if (event.lengthComputable) {
  1171. const percentComplete = Math.round(event.loaded / event.total * 100);
  1172. this.uploadProgress[task.id] = percentComplete;
  1173. this.updateUploadStatusText();
  1174. }
  1175. };
  1176. xhr.onload = () => {
  1177. if (xhr.status === 200) {
  1178. try {
  1179. const res = JSON.parse(xhr.responseText);
  1180. console.log("上传响应:", res);
  1181. if (res.code === 2e3) {
  1182. const videoUrl = res.data.url || res.data.photoUrl || "";
  1183. if (videoUrl) {
  1184. this.uploadStatus[task.id] = "success";
  1185. this.updateUploadStatusText();
  1186. this.submitVideoToInterview(videoUrl, task);
  1187. } else {
  1188. this.handleUploadFailure(task, "视频URL获取失败");
  1189. }
  1190. } else {
  1191. this.handleUploadFailure(task, res.msg || "上传失败");
  1192. }
  1193. } catch (e) {
  1194. this.handleUploadFailure(task, "解析响应失败");
  1195. }
  1196. } else {
  1197. this.handleUploadFailure(task, "HTTP状态: " + xhr.status);
  1198. }
  1199. };
  1200. xhr.onerror = () => {
  1201. this.handleUploadFailure(task, "网络错误");
  1202. };
  1203. xhr.ontimeout = () => {
  1204. this.handleUploadFailure(task, "上传超时");
  1205. };
  1206. xhr.send(formData);
  1207. },
  1208. // 添加新方法:使用uni.uploadFile上传文件
  1209. uploadFileWithUni(task) {
  1210. const userInfo = common_vendor.index.getStorageSync("userInfo");
  1211. const openid = userInfo ? JSON.parse(userInfo).openid || "" : "";
  1212. const tenant_id = common_vendor.index.getStorageSync("tenant_id") || "1";
  1213. const uploadTask = common_vendor.index.uploadFile({
  1214. url: `${common_config.apiBaseUrl}/api/upload/`,
  1215. filePath: task.file,
  1216. name: "file",
  1217. formData: {
  1218. openid,
  1219. tenant_id,
  1220. application_id: common_vendor.index.getStorageSync("appId"),
  1221. question_id: task.questionId,
  1222. video_duration: 0,
  1223. has_audio: "true"
  1224. },
  1225. success: (uploadRes) => {
  1226. try {
  1227. const res = JSON.parse(uploadRes.data);
  1228. console.log("上传响应:", res);
  1229. if (res.code === 2e3) {
  1230. const videoUrl = res.data.permanent_link || res.data.url || "";
  1231. if (videoUrl) {
  1232. this.uploadStatus[task.id] = "success";
  1233. this.updateUploadStatusText();
  1234. this.submitVideoToInterview(videoUrl, task);
  1235. } else {
  1236. this.handleUploadFailure(task, "视频URL获取失败");
  1237. }
  1238. } else {
  1239. this.handleUploadFailure(task, res.msg || "上传失败");
  1240. }
  1241. } catch (e) {
  1242. this.handleUploadFailure(task, "解析响应失败");
  1243. }
  1244. },
  1245. fail: (err) => {
  1246. this.handleUploadFailure(task, err.errMsg || "上传失败");
  1247. }
  1248. });
  1249. uploadTask.onProgressUpdate((res) => {
  1250. this.uploadProgress[task.id] = res.progress;
  1251. this.updateUploadStatusText();
  1252. });
  1253. },
  1254. // 添加新方法:处理上传失败
  1255. handleUploadFailure(task, errorMsg) {
  1256. console.error("上传失败:", errorMsg);
  1257. this.uploadStatus[task.id] = "failed";
  1258. this.updateUploadStatusText();
  1259. if (task.attempts < task.maxAttempts) {
  1260. console.log(`将在5秒后重试上传,当前尝试次数: ${task.attempts}/${task.maxAttempts}`);
  1261. setTimeout(() => {
  1262. this.uploadProgress[task.id] = 0;
  1263. if (typeof task.file !== "string") {
  1264. this.uploadFileWithXHR(task);
  1265. } else {
  1266. this.uploadFileWithUni(task);
  1267. }
  1268. }, 5e3);
  1269. } else {
  1270. console.log("超过最大重试次数,放弃上传");
  1271. common_vendor.index.showToast({
  1272. title: "视频上传失败,请稍后重试",
  1273. icon: "none",
  1274. duration: 2e3
  1275. });
  1276. this.uploadQueue.shift();
  1277. this.processUploadQueue();
  1278. }
  1279. },
  1280. // 修改 submitVideoToInterview 方法
  1281. submitVideoToInterview(videoUrl, task = null) {
  1282. console.log("提交视频URL到面试接口:", videoUrl);
  1283. let questionId;
  1284. if (task) {
  1285. questionId = task.questionId;
  1286. } else {
  1287. switch (this.currentVideoIndex) {
  1288. case 1:
  1289. questionId = 36;
  1290. break;
  1291. case 2:
  1292. questionId = 11;
  1293. break;
  1294. case 3:
  1295. questionId = 12;
  1296. break;
  1297. case 4:
  1298. questionId = 13;
  1299. break;
  1300. default:
  1301. questionId = 10;
  1302. }
  1303. }
  1304. const requestData = {
  1305. application_id: common_vendor.index.getStorageSync("appId"),
  1306. question_id: questionId,
  1307. video_url: videoUrl,
  1308. tenant_id: common_vendor.index.getStorageSync("tenant_id") || "1"
  1309. };
  1310. common_vendor.index.request({
  1311. url: `${common_config.apiBaseUrl}/api/job/upload_video`,
  1312. method: "POST",
  1313. data: requestData,
  1314. header: {
  1315. "content-type": "application/x-www-form-urlencoded"
  1316. },
  1317. success: (res) => {
  1318. console.log("面试接口提交成功:", res);
  1319. if (res.data.code === 0 || res.data.code === 2e3) {
  1320. if (task) {
  1321. this.uploadQueue.shift();
  1322. this.processUploadQueue();
  1323. } else {
  1324. common_vendor.index.showToast({
  1325. title: "回答已提交",
  1326. icon: "success"
  1327. });
  1328. this.lastUploadedVideoUrl = videoUrl;
  1329. this.showRetryButton = false;
  1330. this.lastVideoToRetry = null;
  1331. }
  1332. } else {
  1333. if (task) {
  1334. this.handleSubmitFailure(task, res.data.msg || "提交失败");
  1335. } else {
  1336. common_vendor.index.showToast({
  1337. title: res.data.msg || "提交失败,请重试",
  1338. icon: "none"
  1339. });
  1340. this.lastVideoToRetry = videoUrl;
  1341. this.showRetryButton = true;
  1342. }
  1343. }
  1344. },
  1345. fail: (err) => {
  1346. console.error("面试接口提交失败:", err);
  1347. if (task) {
  1348. this.handleSubmitFailure(task, err.errMsg || "网络错误");
  1349. } else {
  1350. common_vendor.index.hideLoading();
  1351. common_vendor.index.showToast({
  1352. title: "网络错误,请重试",
  1353. icon: "none"
  1354. });
  1355. this.lastVideoToRetry = videoUrl;
  1356. this.showRetryButton = true;
  1357. }
  1358. }
  1359. });
  1360. },
  1361. // 添加新方法:处理提交失败
  1362. handleSubmitFailure(task, errorMsg) {
  1363. console.error("提交失败:", errorMsg);
  1364. this.uploadStatus[task.id] = "failed";
  1365. this.updateUploadStatusText();
  1366. if (task.attempts < task.maxAttempts) {
  1367. console.log(`将在5秒后重试提交,当前尝试次数: ${task.attempts}/${task.maxAttempts}`);
  1368. setTimeout(() => {
  1369. this.submitVideoToInterview(task.videoUrl, task);
  1370. }, 5e3);
  1371. } else {
  1372. console.log("超过最大重试次数,放弃提交");
  1373. common_vendor.index.showToast({
  1374. title: "视频提交失败,请稍后重试",
  1375. icon: "none",
  1376. duration: 2e3
  1377. });
  1378. this.uploadQueue.shift();
  1379. this.processUploadQueue();
  1380. }
  1381. },
  1382. // 添加新方法:更新上传状态文本
  1383. updateUploadStatusText() {
  1384. if (this.uploadQueue.length === 0) {
  1385. this.uploadStatusText = "";
  1386. return;
  1387. }
  1388. const currentTask = this.uploadQueue[0];
  1389. const progress = this.uploadProgress[currentTask.id] || 0;
  1390. const status = this.uploadStatus[currentTask.id] || "pending";
  1391. let statusText = "";
  1392. switch (status) {
  1393. case "pending":
  1394. statusText = "等待上传";
  1395. break;
  1396. case "uploading":
  1397. statusText = `上传中 ${progress}%`;
  1398. break;
  1399. case "success":
  1400. statusText = "上传成功,提交中...";
  1401. break;
  1402. case "failed":
  1403. statusText = `上传失败,${currentTask.attempts < currentTask.maxAttempts ? "即将重试" : "已放弃"}`;
  1404. break;
  1405. }
  1406. this.uploadStatusText = `问题${currentTask.questionId - 9}:${statusText}`;
  1407. if (this.uploadQueue.length > 1) {
  1408. this.uploadStatusText += ` (${this.uploadQueue.length}个视频待处理)`;
  1409. }
  1410. },
  1411. // 修改 proceedToNextQuestion 方法
  1412. proceedToNextQuestion() {
  1413. console.log("准备跳转到下一页面");
  1414. this.navigateToNextPage();
  1415. if (this.uploadQueue.length > 0) {
  1416. console.log("上传队列将在后台继续处理...");
  1417. this.saveUploadStatus();
  1418. }
  1419. },
  1420. // 修改 navigateToNextPage 方法
  1421. navigateToNextPage() {
  1422. console.log("导航到下一个页面");
  1423. common_vendor.index.navigateTo({
  1424. url: "/pages/interview-result/interview-result?uploading=" + (this.uploadQueue.length > 0 ? "true" : "false"),
  1425. success: () => {
  1426. console.log("成功跳转到结果页面");
  1427. },
  1428. fail: (err) => {
  1429. console.error("跳转失败:", err);
  1430. common_vendor.index.navigateTo({
  1431. url: "/pages/interview/interview",
  1432. fail: (err2) => {
  1433. console.error("备用跳转也失败:", err2);
  1434. common_vendor.index.navigateBack({
  1435. delta: 1
  1436. });
  1437. }
  1438. });
  1439. }
  1440. });
  1441. },
  1442. // 修改 handleAnswerButtonClick 方法
  1443. handleAnswerButtonClick() {
  1444. this.showAnswerButton = false;
  1445. this.showGif = false;
  1446. this.gifUrl = "";
  1447. common_vendor.index.showToast({
  1448. title: "面试完成",
  1449. icon: "success",
  1450. duration: 500
  1451. // 只显示0.5秒
  1452. });
  1453. setTimeout(() => {
  1454. this.navigateToNextPage();
  1455. }, 500);
  1456. },
  1457. // 处理相机错误
  1458. handleCameraError(e) {
  1459. console.error("相机错误:", e);
  1460. const systemInfo = common_vendor.index.getSystemInfoSync();
  1461. const isIOS = systemInfo.platform === "ios";
  1462. if (isIOS) {
  1463. console.log("iOS相机错误,尝试重新初始化");
  1464. common_vendor.index.showToast({
  1465. title: "相机初始化中...",
  1466. icon: "loading",
  1467. duration: 2e3
  1468. });
  1469. this.resetCamera();
  1470. if (this.isRecording) {
  1471. this.isRecording = false;
  1472. this.showStopRecordingButton = false;
  1473. setTimeout(() => {
  1474. this.useAlternativeRecordingMethod();
  1475. }, 1e3);
  1476. }
  1477. } else {
  1478. common_vendor.index.showToast({
  1479. title: "相机初始化失败,请检查权限设置",
  1480. icon: "none"
  1481. });
  1482. this.tryFallbackOptions();
  1483. }
  1484. },
  1485. // 添加新方法:尝试备用选项
  1486. tryFallbackOptions() {
  1487. const systemInfo = common_vendor.index.getSystemInfoSync();
  1488. if (systemInfo.uniPlatform === "mp-weixin" || systemInfo.uniPlatform === "mp-alipay") {
  1489. this.useMiniProgramCamera();
  1490. } else {
  1491. this.showStaticCameraPlaceholder();
  1492. }
  1493. },
  1494. // 添加新方法:使用小程序相机API
  1495. useMiniProgramCamera() {
  1496. console.log("尝试使用小程序相机组件");
  1497. this.useMiniProgramCameraComponent = true;
  1498. },
  1499. // 添加新方法:显示静态图像
  1500. showStaticCameraPlaceholder() {
  1501. console.log("显示静态摄像头占位图");
  1502. const img = document.createElement("img");
  1503. img.src = "/static/images/camera-placeholder.png";
  1504. img.className = "static-camera-image";
  1505. img.style.width = "100%";
  1506. img.style.height = "100%";
  1507. img.style.objectFit = "cover";
  1508. const container = this.$refs.userCameraVideo.parentNode;
  1509. container.appendChild(img);
  1510. },
  1511. // 处理视频时间更新事件
  1512. handleTimeUpdate(e) {
  1513. const currentTime = e.target.currentTime;
  1514. if (this.isRecording && this.recordingTimerCount) {
  1515. this.recordingTimeDisplay = this.formatTime(this.recordingTimerCount);
  1516. }
  1517. let currentSubtitles;
  1518. if (this.currentVideoIndex === 0) {
  1519. currentSubtitles = this.subtitles;
  1520. } else if (this.currentVideoIndex === 1) {
  1521. currentSubtitles = this.secondVideoSubtitles;
  1522. } else if (this.currentVideoIndex === 2) {
  1523. currentSubtitles = this.thirdVideoSubtitles;
  1524. } else if (this.currentVideoIndex === 3) {
  1525. currentSubtitles = this.fourthVideoSubtitles;
  1526. } else if (this.currentVideoIndex === 4) {
  1527. currentSubtitles = this.fifthVideoSubtitles;
  1528. } else if (this.currentVideoIndex === 5) {
  1529. currentSubtitles = this.sixthVideoSubtitles;
  1530. } else {
  1531. currentSubtitles = [];
  1532. }
  1533. const subtitle = currentSubtitles.find(
  1534. (sub) => currentTime >= sub.startTime && currentTime < sub.endTime
  1535. );
  1536. this.currentSubtitle = subtitle ? subtitle.text : "";
  1537. },
  1538. // Add a new method to handle the "Start Recording" button click
  1539. handleStartRecordingClick() {
  1540. this.showStartRecordingButton = false;
  1541. this.clearCountdown();
  1542. this.startRecordingAnswer();
  1543. },
  1544. // 修改 checkAudioPermission 方法,确保在录制前获取音频权限
  1545. checkAudioPermission() {
  1546. const systemInfo = common_vendor.index.getSystemInfoSync();
  1547. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
  1548. if (isMiniProgram) {
  1549. common_vendor.index.getSetting({
  1550. success: (res) => {
  1551. if (!res.authSetting["scope.record"]) {
  1552. common_vendor.index.authorize({
  1553. scope: "scope.record",
  1554. success: () => {
  1555. console.log("录音权限已获取");
  1556. },
  1557. fail: (err) => {
  1558. console.error("录音权限获取失败:", err);
  1559. this.showPermissionDialog("录音");
  1560. }
  1561. });
  1562. }
  1563. if (!res.authSetting["scope.camera"]) {
  1564. common_vendor.index.authorize({
  1565. scope: "scope.camera",
  1566. success: () => {
  1567. console.log("相机权限已获取");
  1568. },
  1569. fail: (err) => {
  1570. console.error("相机权限获取失败:", err);
  1571. this.showPermissionDialog("相机");
  1572. }
  1573. });
  1574. }
  1575. }
  1576. });
  1577. }
  1578. },
  1579. // 添加新方法:测试音频输入
  1580. testAudioInput() {
  1581. if (!this.cameraStream) {
  1582. console.warn("没有可用的媒体流,无法测试音频");
  1583. return;
  1584. }
  1585. const audioTracks = this.cameraStream.getAudioTracks();
  1586. if (audioTracks.length === 0) {
  1587. console.warn("没有检测到音频轨道,尝试重新获取");
  1588. this.tryGetAudioOnly();
  1589. return;
  1590. }
  1591. console.log("音频轨道信息:", audioTracks[0].getSettings());
  1592. try {
  1593. const AudioContext = window.AudioContext || window.webkitAudioContext;
  1594. if (!AudioContext) {
  1595. console.warn("浏览器不支持AudioContext");
  1596. return;
  1597. }
  1598. const audioContext = new AudioContext();
  1599. const analyser = audioContext.createAnalyser();
  1600. const microphone = audioContext.createMediaStreamSource(this.cameraStream);
  1601. microphone.connect(analyser);
  1602. analyser.fftSize = 256;
  1603. const bufferLength = analyser.frequencyBinCount;
  1604. const dataArray = new Uint8Array(bufferLength);
  1605. let silenceCounter = 0;
  1606. const checkAudio = () => {
  1607. if (this.isRecording)
  1608. return;
  1609. analyser.getByteFrequencyData(dataArray);
  1610. let sum = 0;
  1611. for (let i = 0; i < bufferLength; i++) {
  1612. sum += dataArray[i];
  1613. }
  1614. const average = sum / bufferLength;
  1615. if (average > 10) {
  1616. console.log("检测到音频输入,音量:", average);
  1617. silenceCounter = 0;
  1618. } else {
  1619. silenceCounter++;
  1620. if (silenceCounter > 10) {
  1621. console.warn("持续检测不到音频输入,可能麦克风未正常工作");
  1622. silenceCounter = 0;
  1623. }
  1624. }
  1625. requestAnimationFrame(checkAudio);
  1626. };
  1627. checkAudio();
  1628. } catch (e) {
  1629. console.error("音频测试失败:", e);
  1630. }
  1631. },
  1632. // 添加新方法:尝试单独获取音频
  1633. tryGetAudioOnly() {
  1634. navigator.mediaDevices.getUserMedia({ audio: true }).then((audioStream) => {
  1635. if (this.cameraStream) {
  1636. const videoTrack = this.cameraStream.getVideoTracks()[0];
  1637. const audioTrack = audioStream.getAudioTracks()[0];
  1638. const combinedStream = new MediaStream();
  1639. if (videoTrack)
  1640. combinedStream.addTrack(videoTrack);
  1641. if (audioTrack)
  1642. combinedStream.addTrack(audioTrack);
  1643. this.cameraStream = combinedStream;
  1644. const videoElement = this.$refs.userCameraVideo;
  1645. if (videoElement) {
  1646. videoElement.srcObject = combinedStream;
  1647. videoElement.muted = true;
  1648. }
  1649. console.log("成功合并音频和视频轨道");
  1650. } else {
  1651. console.warn("没有视频流可合并");
  1652. }
  1653. }).catch((err) => {
  1654. console.error("单独获取音频失败:", err);
  1655. });
  1656. },
  1657. // 添加新方法:显示权限对话框
  1658. showPermissionDialog(permissionType) {
  1659. common_vendor.index.showModal({
  1660. title: "需要权限",
  1661. content: `请允许使用${permissionType}权限,否则可能影响面试功能`,
  1662. confirmText: "去设置",
  1663. success: (res) => {
  1664. if (res.confirm) {
  1665. common_vendor.index.openSetting({
  1666. success: (settingRes) => {
  1667. console.log("设置页面打开成功", settingRes);
  1668. }
  1669. });
  1670. }
  1671. }
  1672. });
  1673. },
  1674. // 添加重试上传方法
  1675. retryVideoUpload() {
  1676. if (this.lastVideoToRetry) {
  1677. this.showRetryButton = false;
  1678. common_vendor.index.showLoading({
  1679. title: "正在重新提交...",
  1680. mask: true
  1681. });
  1682. this.submitVideoToInterview(this.lastVideoToRetry);
  1683. } else {
  1684. common_vendor.index.showToast({
  1685. title: "没有可重试的视频",
  1686. icon: "none"
  1687. });
  1688. }
  1689. },
  1690. // 添加一个新方法用于压缩视频
  1691. async compressVideo(videoBlob) {
  1692. if (videoBlob.size < 5 * 1024 * 1024) {
  1693. return videoBlob;
  1694. }
  1695. console.log("开始压缩视频,原始大小:", videoBlob.size);
  1696. const videoElement = document.createElement("video");
  1697. videoElement.muted = true;
  1698. videoElement.autoplay = false;
  1699. const canvas = document.createElement("canvas");
  1700. const ctx = canvas.getContext("2d");
  1701. videoElement.src = URL.createObjectURL(videoBlob);
  1702. return new Promise((resolve) => {
  1703. videoElement.onloadedmetadata = () => {
  1704. const width = Math.floor(videoElement.videoWidth / 2);
  1705. const height = Math.floor(videoElement.videoHeight / 2);
  1706. canvas.width = width;
  1707. canvas.height = height;
  1708. const stream = canvas.captureStream(15);
  1709. if (videoElement.captureStream) {
  1710. const originalStream = videoElement.captureStream();
  1711. const audioTracks = originalStream.getAudioTracks();
  1712. if (audioTracks.length > 0) {
  1713. stream.addTrack(audioTracks[0]);
  1714. }
  1715. }
  1716. const options = {
  1717. mimeType: "video/webm;codecs=vp8,opus",
  1718. audioBitsPerSecond: 64e3,
  1719. videoBitsPerSecond: 8e5
  1720. // 800kbps
  1721. };
  1722. const mediaRecorder = new MediaRecorder(stream, options);
  1723. const chunks = [];
  1724. mediaRecorder.ondataavailable = (e) => {
  1725. if (e.data.size > 0) {
  1726. chunks.push(e.data);
  1727. }
  1728. };
  1729. mediaRecorder.onstop = () => {
  1730. const compressedBlob = new Blob(chunks, { type: "video/webm" });
  1731. console.log("视频压缩完成,压缩后大小:", compressedBlob.size);
  1732. resolve(compressedBlob);
  1733. };
  1734. videoElement.onplay = () => {
  1735. mediaRecorder.start(100);
  1736. const drawFrame = () => {
  1737. if (videoElement.paused || videoElement.ended) {
  1738. mediaRecorder.stop();
  1739. return;
  1740. }
  1741. ctx.drawImage(videoElement, 0, 0, width, height);
  1742. requestAnimationFrame(drawFrame);
  1743. };
  1744. drawFrame();
  1745. };
  1746. videoElement.play();
  1747. };
  1748. });
  1749. },
  1750. // 修改 checkIOSCameraRecordPermission 方法
  1751. checkIOSCameraRecordPermission() {
  1752. const systemInfo = common_vendor.index.getSystemInfoSync();
  1753. if (systemInfo.platform !== "ios")
  1754. return;
  1755. common_vendor.index.getSetting({
  1756. success: (res) => {
  1757. if (!res.authSetting["scope.camera"]) {
  1758. common_vendor.index.authorize({
  1759. scope: "scope.camera",
  1760. success: () => {
  1761. console.log("iOS相机权限已获取");
  1762. },
  1763. fail: (err) => {
  1764. console.error("iOS相机权限获取失败:", err);
  1765. this.showPermissionDialog("相机");
  1766. }
  1767. });
  1768. }
  1769. if (!res.authSetting["scope.record"]) {
  1770. common_vendor.index.authorize({
  1771. scope: "scope.record",
  1772. success: () => {
  1773. console.log("iOS录音权限已获取");
  1774. },
  1775. fail: (err) => {
  1776. console.error("iOS录音权限获取失败:", err);
  1777. this.showPermissionDialog("录音");
  1778. }
  1779. });
  1780. }
  1781. }
  1782. });
  1783. },
  1784. // 添加新方法:检查并修复渲染问题
  1785. checkAndFixRenderingIssues() {
  1786. try {
  1787. if (typeof u !== "undefined" && u) {
  1788. if (!u.currentQuestion) {
  1789. console.log("修复: 创建缺失的currentQuestion对象");
  1790. u.currentQuestion = {};
  1791. }
  1792. if (u.currentQuestion && typeof u.currentQuestion.isImportant === "undefined") {
  1793. console.log("修复: 设置缺失的isImportant属性");
  1794. u.currentQuestion.isImportant = false;
  1795. }
  1796. }
  1797. } catch (e) {
  1798. console.log("防御性检查异常:", e);
  1799. }
  1800. },
  1801. // 添加格式化时间的辅助方法
  1802. formatTime(seconds) {
  1803. if (!seconds && seconds !== 0)
  1804. return "03:30";
  1805. const minutes = Math.floor(seconds / 60);
  1806. const remainingSeconds = seconds % 60;
  1807. return `${minutes.toString().padStart(2, "0")}:${remainingSeconds.toString().padStart(2, "0")}`;
  1808. },
  1809. // 添加新方法:保存上传状态到本地存储
  1810. saveUploadStatus() {
  1811. const uploadStatus = {
  1812. isUploading: this.isUploading,
  1813. uploadQueue: this.uploadQueue.length,
  1814. timestamp: Date.now()
  1815. };
  1816. try {
  1817. common_vendor.index.setStorageSync("videoUploadStatus", JSON.stringify(uploadStatus));
  1818. } catch (e) {
  1819. console.error("保存上传状态失败:", e);
  1820. }
  1821. }
  1822. }
  1823. };
  1824. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  1825. return common_vendor.e({
  1826. a: $data.showGif && $data.gifUrl
  1827. }, $data.showGif && $data.gifUrl ? {
  1828. b: $data.gifUrl
  1829. } : {}, {
  1830. c: !$data.showGif
  1831. }, !$data.showGif ? {
  1832. d: $data.videoUrl,
  1833. e: common_vendor.o((...args) => $options.handleVideoError && $options.handleVideoError(...args)),
  1834. f: common_vendor.o((...args) => $options.handleVideoEnded && $options.handleVideoEnded(...args)),
  1835. g: common_vendor.o((...args) => $options.handleTimeUpdate && $options.handleTimeUpdate(...args))
  1836. } : {}, {
  1837. h: $data.showAnswerButton
  1838. }, $data.showAnswerButton ? {
  1839. i: common_vendor.o((...args) => $options.handleAnswerButtonClick && $options.handleAnswerButtonClick(...args))
  1840. } : {}, {
  1841. j: $data.currentSubtitle
  1842. }, $data.currentSubtitle ? {
  1843. k: common_vendor.t($data.currentSubtitle)
  1844. } : {}, {
  1845. l: $data.useMiniProgramCameraComponent
  1846. }, $data.useMiniProgramCameraComponent ? {
  1847. m: common_vendor.o((...args) => $options.handleCameraError && $options.handleCameraError(...args))
  1848. } : {}, {
  1849. n: $data.loading
  1850. }, $data.loading ? {} : {}, {
  1851. o: $data.showDebugInfo
  1852. }, $data.showDebugInfo ? common_vendor.e({
  1853. p: $data.assistantResponse
  1854. }, $data.assistantResponse ? {
  1855. q: common_vendor.t($data.assistantResponse)
  1856. } : {}, {
  1857. r: $data.audioTranscript
  1858. }, $data.audioTranscript ? {
  1859. s: common_vendor.t($data.audioTranscript)
  1860. } : {}, {
  1861. t: common_vendor.f($data.processedResponses, (item, index, i0) => {
  1862. return common_vendor.e({
  1863. a: item.role
  1864. }, item.role ? {
  1865. b: common_vendor.t(item.role)
  1866. } : {}, {
  1867. c: item.transcript
  1868. }, item.transcript ? {
  1869. d: common_vendor.t(item.transcript)
  1870. } : {}, {
  1871. e: index
  1872. });
  1873. })
  1874. }) : {}, {
  1875. v: $data.showStopRecordingButton
  1876. }, $data.showStopRecordingButton ? {
  1877. w: common_vendor.o((...args) => $options.stopRecordingAnswer && $options.stopRecordingAnswer(...args))
  1878. } : {}, {
  1879. x: $data.isRecording
  1880. }, $data.isRecording ? {
  1881. y: common_vendor.t($data.recordingTimeDisplay || "00:00 / 05:00")
  1882. } : {}, {
  1883. z: $data.showStartRecordingButton
  1884. }, $data.showStartRecordingButton ? {
  1885. A: common_vendor.o((...args) => $options.handleStartRecordingClick && $options.handleStartRecordingClick(...args))
  1886. } : {}, {
  1887. B: $data.showRetryButton
  1888. }, $data.showRetryButton ? {
  1889. C: common_vendor.o((...args) => $options.retryVideoUpload && $options.retryVideoUpload(...args))
  1890. } : {}, {
  1891. D: $data.showCountdown
  1892. }, $data.showCountdown ? {
  1893. E: common_vendor.t($data.countdownValue)
  1894. } : {});
  1895. }
  1896. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-2a02c54e"]]);
  1897. wx.createPage(MiniProgramPage);