identity-verify.js 70 KB

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