identity-verify.js 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955
  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 = common_vendor.index.getStorageSync("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 = common_vendor.index.getStorageSync("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: common_vendor.index.getStorageSync("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 = common_vendor.index.getStorageSync("tenant_id") || "1";
  1734. common_vendor.index.request({
  1735. url: `${common_config.apiBaseUrl}/api/wechat/open_questions/?position_id=1&tenant_id=${tenant_id}&question_form=0`,
  1736. method: "GET",
  1737. success: (res) => {
  1738. if (res.data && res.data.code === 2e3 && res.data.data && res.data.data.items) {
  1739. console.log("获取问题数据成功:", res.data.data.items);
  1740. this.questions = res.data.data.items;
  1741. this.processQuestionData();
  1742. this.playIntroVideo();
  1743. } else {
  1744. console.error("获取问题数据失败:", res.data);
  1745. common_vendor.index.showToast({
  1746. title: "获取问题数据失败",
  1747. icon: "none"
  1748. });
  1749. }
  1750. },
  1751. fail: (err) => {
  1752. console.error("请求问题数据失败:", err);
  1753. common_vendor.index.showToast({
  1754. title: "网络错误,请检查网络连接",
  1755. icon: "none"
  1756. });
  1757. },
  1758. complete: () => {
  1759. this.loading = false;
  1760. }
  1761. });
  1762. },
  1763. // 处理问题数据,提取视频URL和字幕
  1764. processQuestionData() {
  1765. this.videoList = [];
  1766. this.videoList.push(this.introVideoUrl);
  1767. this.subtitles = [
  1768. {
  1769. startTime: 0,
  1770. endTime: 5,
  1771. text: "你好,我是本次面试的面试官,欢迎参加本公司的线上面试!"
  1772. },
  1773. {
  1774. startTime: 5,
  1775. endTime: 13,
  1776. text: "面试预计需要15分钟,请你提前安排在网络良好、光线亮度合适、且相对安静的环境参加这次面试"
  1777. },
  1778. {
  1779. startTime: 13,
  1780. endTime: 20,
  1781. text: "以免影响本次面试的结果。如果你在面试过程中遇到问题,请与我们的招聘人员联系。"
  1782. }
  1783. ];
  1784. const sortedQuestions = [...this.questions].sort((a, b) => a.sequence_number - b.sequence_number);
  1785. const questionsToUse = sortedQuestions.slice(0, 5);
  1786. questionsToUse.forEach((question) => {
  1787. if (question.digital_human_video_url) {
  1788. this.videoList.push(question.digital_human_video_url);
  1789. const subtitleArray = [{
  1790. startTime: 0,
  1791. endTime: 10,
  1792. // 默认10秒,可以根据实际情况调整
  1793. text: question.digital_human_video_subtitle || question.question
  1794. }];
  1795. const index = this.videoList.length - 1;
  1796. this[`question${index}Subtitles`] = subtitleArray;
  1797. }
  1798. });
  1799. if (this.videoList.length <= 1)
  1800. ;
  1801. else {
  1802. console.log("处理后的视频列表:", this.videoList);
  1803. console.log("处理后的字幕:", this.subtitles);
  1804. }
  1805. },
  1806. // 使用默认视频和字幕(作为备用)
  1807. useDefaultVideosAndSubtitles() {
  1808. console.log("使用默认视频和字幕");
  1809. this.subtitles = [
  1810. {
  1811. startTime: 0,
  1812. endTime: 5,
  1813. text: "你好,我是本次面试的面试官,欢迎参加本公司的线上面试!"
  1814. },
  1815. {
  1816. startTime: 5,
  1817. endTime: 13,
  1818. text: "面试预计需要15分钟,请你提前安排在网络良好、光线亮度合适、且相对安静的环境参加这次面试"
  1819. },
  1820. {
  1821. startTime: 13,
  1822. endTime: 20,
  1823. text: "以免影响本次面试的结果。如果你在面试过程中遇到问题,请与我们的招聘人员联系。"
  1824. }
  1825. ];
  1826. this.question1Subtitles = [{
  1827. startTime: 0,
  1828. endTime: 10,
  1829. text: "请结合您的基本信息与过往履历进行简单的自我介绍,并讲一讲您有哪些优势胜任本岗位:"
  1830. }];
  1831. this.question2Subtitles = [{
  1832. startTime: 0,
  1833. endTime: 4,
  1834. text: "在工作中,你如何确保个人防护装备的正确使用?"
  1835. }];
  1836. this.question3Subtitles = [{
  1837. startTime: 0,
  1838. endTime: 4,
  1839. text: "描述一次你与团队合作改善生产流程的经历。"
  1840. }];
  1841. this.question4Subtitles = [{
  1842. startTime: 0,
  1843. endTime: 6,
  1844. text: "你在团队合作中曾遇到过哪些挑战?如何解决团队内部的分歧?"
  1845. }];
  1846. this.question5Subtitles = [{
  1847. startTime: 0,
  1848. endTime: 5,
  1849. text: "您已完成本次面试全部题目,请问您对于这个岗位还有什么想要了解的吗?"
  1850. }];
  1851. },
  1852. // 播放介绍视频
  1853. playIntroVideo() {
  1854. this.videoUrl = this.videoList[0];
  1855. this.videoPlaying = true;
  1856. this.$nextTick(() => {
  1857. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  1858. if (videoContext) {
  1859. videoContext.play();
  1860. }
  1861. });
  1862. },
  1863. // 添加新方法:获取默认问题ID
  1864. getDefaultQuestionId(videoIndex) {
  1865. switch (videoIndex) {
  1866. case 1:
  1867. return 10;
  1868. case 2:
  1869. return 11;
  1870. case 3:
  1871. return 12;
  1872. case 4:
  1873. return 13;
  1874. default:
  1875. return 10;
  1876. }
  1877. },
  1878. // 添加新方法:根据索引获取当前问题
  1879. getCurrentQuestionByIndex(videoIndex) {
  1880. const questionIndex = videoIndex - 1;
  1881. const sortedQuestions = [...this.questions].sort((a, b) => a.sequence_number - b.sequence_number);
  1882. if (questionIndex >= 0 && questionIndex < sortedQuestions.length) {
  1883. return sortedQuestions[questionIndex];
  1884. }
  1885. return null;
  1886. }
  1887. }
  1888. };
  1889. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  1890. return common_vendor.e({
  1891. a: $data.videoUrl,
  1892. b: common_vendor.o((...args) => $options.handleVideoError && $options.handleVideoError(...args)),
  1893. c: common_vendor.o((...args) => $options.handleVideoEnded && $options.handleVideoEnded(...args)),
  1894. d: common_vendor.o((...args) => $options.handleTimeUpdate && $options.handleTimeUpdate(...args)),
  1895. e: $data.showAnswerButton
  1896. }, $data.showAnswerButton ? {
  1897. f: common_vendor.o((...args) => $options.handleAnswerButtonClick && $options.handleAnswerButtonClick(...args))
  1898. } : {}, {
  1899. g: $data.currentSubtitle
  1900. }, $data.currentSubtitle ? {
  1901. h: common_vendor.t($data.currentSubtitle)
  1902. } : {}, {
  1903. i: $data.useMiniProgramCameraComponent
  1904. }, $data.useMiniProgramCameraComponent ? {
  1905. j: common_vendor.o((...args) => $options.handleCameraError && $options.handleCameraError(...args))
  1906. } : {}, {
  1907. k: $data.loading
  1908. }, $data.loading ? {} : {}, {
  1909. l: $data.showDebugInfo
  1910. }, $data.showDebugInfo ? common_vendor.e({
  1911. m: $data.assistantResponse
  1912. }, $data.assistantResponse ? {
  1913. n: common_vendor.t($data.assistantResponse)
  1914. } : {}, {
  1915. o: $data.audioTranscript
  1916. }, $data.audioTranscript ? {
  1917. p: common_vendor.t($data.audioTranscript)
  1918. } : {}, {
  1919. q: common_vendor.f($data.processedResponses, (item, index, i0) => {
  1920. return common_vendor.e({
  1921. a: item.role
  1922. }, item.role ? {
  1923. b: common_vendor.t(item.role)
  1924. } : {}, {
  1925. c: item.transcript
  1926. }, item.transcript ? {
  1927. d: common_vendor.t(item.transcript)
  1928. } : {}, {
  1929. e: index
  1930. });
  1931. })
  1932. }) : {}, {
  1933. r: $data.showStopRecordingButton
  1934. }, $data.showStopRecordingButton ? {
  1935. s: common_vendor.o((...args) => $options.stopRecordingAnswer && $options.stopRecordingAnswer(...args))
  1936. } : {}, {
  1937. t: $data.isRecording
  1938. }, $data.isRecording ? {
  1939. v: common_vendor.t($data.recordingTimeDisplay || "00:00 / 05:00")
  1940. } : {}, {
  1941. w: $data.showStartRecordingButton
  1942. }, $data.showStartRecordingButton ? {
  1943. x: common_vendor.o((...args) => $options.handleStartRecordingClick && $options.handleStartRecordingClick(...args))
  1944. } : {}, {
  1945. y: $data.showRetryButton
  1946. }, $data.showRetryButton ? {
  1947. z: common_vendor.o((...args) => $options.retryVideoUpload && $options.retryVideoUpload(...args))
  1948. } : {}, {
  1949. A: $data.showCountdown
  1950. }, $data.showCountdown ? {
  1951. B: common_vendor.t($data.countdownValue)
  1952. } : {});
  1953. }
  1954. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-464e78c6"]]);
  1955. wx.createPage(MiniProgramPage);