identity-verify.js 89 KB

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