identity-verify.js 87 KB

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