identity-verify.js 66 KB

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