interview-question.js 66 KB

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