interview-question.js 126 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532
  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: "https://data.qicai321.com/minlong/1809457d-30c5-40bb-b6d8-a8c2e8e1e9e2.mp4",
  17. //'http://121.36.251.245:9000/minlong/tenant_1/general_uploads/abdaa6fda8494e3a8613304743ed0433.mp4', // 用于存储AI数字人视频URL
  18. showReplayButton: false,
  19. cameraStream: null,
  20. // 存储摄像头流
  21. cameraError: null,
  22. // 存储摄像头错误信息
  23. useMiniProgramCameraComponent: false,
  24. // 添加小程序相机组件标志
  25. cameraContext: null,
  26. // 添加相机上下文
  27. currentSubtitle: "",
  28. subtitles: [
  29. {
  30. startTime: 0,
  31. // 开始时间(秒)
  32. endTime: 6,
  33. // 结束时间(秒)
  34. text: "您已完成本次面试全部题目,请问您对于这个岗位还有什么想要了解的吗?"
  35. }
  36. ],
  37. // secondVideoSubtitles: [
  38. // {
  39. // startTime: 0,
  40. // endTime: 10,
  41. // text: '请结合您的基本信息与过往履历进行简单的自我介绍,并讲一讲您有哪些优势胜任本岗位:'
  42. // }
  43. // ],
  44. // thirdVideoSubtitles: [
  45. // {
  46. // startTime: 0,
  47. // endTime: 4,
  48. // text: '在工作中,你如何确保个人防护装备的正确使用?'
  49. // }
  50. // ],
  51. // fourthVideoSubtitles: [
  52. // {
  53. // startTime: 0,
  54. // endTime: 4,
  55. // text: '描述一次你与团队合作改善生产流程的经历。'
  56. // }
  57. // ],
  58. // fifthVideoSubtitles: [
  59. // {
  60. // startTime: 0,
  61. // endTime: 6,
  62. // text: '你在团队合作中曾遇到过哪些挑战?如何解决团队内部的分歧?'
  63. // }
  64. // ],
  65. // sixthVideoSubtitles: [
  66. // {
  67. // startTime: 0,
  68. // endTime: 5,
  69. // text: '您已完成本次面试全部题目,请问您对于这个岗位还有什么想要了解的吗?'
  70. // }
  71. // ],
  72. showAnswerButton: false,
  73. // 控制答题按钮显示
  74. currentVideoIndex: 0,
  75. // 当前播放的视频索引
  76. videoList: [
  77. "https://data.qicai321.com/minlong/1809457d-30c5-40bb-b6d8-a8c2e8e1e9e2.mp4"
  78. //结束
  79. ],
  80. isRecording: false,
  81. recordingTimer: null,
  82. showStopRecordingButton: false,
  83. mediaRecorder: null,
  84. recordedChunks: [],
  85. recorder: null,
  86. lastUploadedVideoUrl: "",
  87. showStartRecordingButton: false,
  88. showRetryButton: false,
  89. // 控制重试按钮显示
  90. lastVideoToRetry: null,
  91. // 存储上次失败的视频URL,用于重试
  92. recordingStartTime: null,
  93. // 录制开始时间
  94. recordingTimerCount: 0,
  95. // 录制计时器计数
  96. recordingTimeDisplay: "00:00",
  97. // 格式化的录制时间显示
  98. // 添加上传队列相关数据
  99. uploadQueue: [],
  100. // 存储待上传的视频
  101. isUploading: false,
  102. // 标记是否正在上传
  103. uploadProgress: {},
  104. // 存储每个视频的上传进度
  105. uploadStatus: {},
  106. // 存储每个视频的上传状态
  107. showUploadStatus: false,
  108. // 是否显示上传状态指示器
  109. uploadStatusText: "",
  110. // 上传状态文本
  111. mediaRecorderTimeout: null,
  112. // 用于存储MediaRecorder的超时机制
  113. maxRecordingTime: 300,
  114. // 最大录制时间(秒)- 从60秒改为300秒(5分钟)
  115. remainingTime: 300,
  116. // 剩余录制时间(秒)- 从60秒改为300秒
  117. // 修改初始视频索引,添加参数控制
  118. startFromLastVideo: false,
  119. // 是否从最后一个视频开始播放
  120. countdownValue: 10,
  121. // 倒计时数值
  122. showCountdown: false,
  123. // 是否显示倒计时蒙层
  124. countdownTimer: null,
  125. showGif: false,
  126. // 控制是否显示GIF
  127. gifUrl: "",
  128. // GIF图片的URL
  129. // 添加AI语音交互相关属性
  130. aiVoiceUrl: "",
  131. // AI语音URL
  132. aiText: "",
  133. // AI回复文本
  134. transcribedText: "",
  135. // 转写文本
  136. isPlayingAiVoice: false,
  137. // 是否正在播放AI语音
  138. aiAudioPlayer: null,
  139. // AI语音播放器
  140. // 添加新的状态变量
  141. showContinueQuestionButton: false,
  142. // 控制"继续提问"按钮显示
  143. showEndInterviewButton: false,
  144. // 控制"结束面试"按钮显示
  145. questionRound: 0,
  146. // 当前提问轮次
  147. maxQuestionRounds: 1,
  148. // 最大提问轮次(可配置)
  149. conversationHistory: [],
  150. // 对话历史记录
  151. pendingAutoNavigation: false,
  152. // 标记是否有待处理的自动跳转
  153. hasTriedFallbackMethod: false,
  154. // 标记是否尝试过备选方法播放音频
  155. hasShownTextFallbackToast: false,
  156. // 标记是否已显示文本回退提示
  157. showNextButton: false,
  158. // 添加一个变量控制按钮显示
  159. isSubtitleExpanded: false,
  160. // 控制字幕是否展开
  161. subtitleHeight: 0
  162. // 记录字幕内容高度
  163. };
  164. },
  165. onLoad(options) {
  166. if (options && options.startFromLast === "true") {
  167. this.startFromLastVideo = true;
  168. this.currentVideoIndex = this.videoList.length - 1;
  169. }
  170. },
  171. mounted() {
  172. if (this.startFromLastVideo) {
  173. console.log("从最后一个视频开始播放");
  174. this.currentVideoIndex = this.videoList.length - 1;
  175. this.videoUrl = this.videoList[this.currentVideoIndex];
  176. }
  177. this.playDigitalHumanVideo();
  178. this.checkAudioPermission();
  179. this.initCamera();
  180. this.checkIOSCameraRecordPermission();
  181. this.checkAndFixRenderingIssues();
  182. setTimeout(() => {
  183. if (this.cameraStream && !this.useMiniProgramCameraComponent) {
  184. this.testAudioInput();
  185. }
  186. }, 3e3);
  187. common_vendor.index.setKeepScreenOn({
  188. keepScreenOn: true
  189. });
  190. },
  191. beforeDestroy() {
  192. this.stopUserCamera();
  193. if (this.aiAudioPlayer) {
  194. try {
  195. this.aiAudioPlayer.destroy();
  196. } catch (e) {
  197. console.error("销毁音频播放器失败:", e);
  198. }
  199. this.aiAudioPlayer = null;
  200. }
  201. if (this.recordingTimer) {
  202. clearInterval(this.recordingTimer);
  203. this.recordingTimer = null;
  204. }
  205. if (this.countdownTimer) {
  206. clearInterval(this.countdownTimer);
  207. this.countdownTimer = null;
  208. }
  209. if (this.mediaRecorderTimeout) {
  210. clearTimeout(this.mediaRecorderTimeout);
  211. this.mediaRecorderTimeout = null;
  212. }
  213. if (this.mediaRecorder && this.mediaRecorder.state === "recording") {
  214. try {
  215. this.mediaRecorder.stop();
  216. } catch (e) {
  217. console.error("停止MediaRecorder失败:", e);
  218. }
  219. }
  220. if (this.recorder) {
  221. try {
  222. this.cameraContext.stopRecord();
  223. } catch (e) {
  224. console.error("停止小程序录制失败:", e);
  225. }
  226. }
  227. common_vendor.index.setKeepScreenOn({
  228. keepScreenOn: false
  229. });
  230. },
  231. methods: {
  232. // 初始化相机
  233. async initCamera() {
  234. const systemInfo = common_vendor.index.getSystemInfoSync();
  235. const isMiniProgram = systemInfo.uniPlatform === "mp-weixin" || systemInfo.uniPlatform === "mp-alipay" || systemInfo.uniPlatform === "mp-baidu";
  236. if (isMiniProgram) {
  237. this.useMiniProgramCameraComponent = true;
  238. this.cameraContext = common_vendor.index.createCameraContext();
  239. common_vendor.index.getSetting({
  240. success: (res) => {
  241. if (!res.authSetting["scope.record"]) {
  242. common_vendor.index.authorize({
  243. scope: "scope.record",
  244. success: () => {
  245. console.log("录音权限已获取");
  246. },
  247. fail: (err) => {
  248. console.error("录音权限获取失败:", err);
  249. this.showPermissionDialog("录音");
  250. }
  251. });
  252. }
  253. if (!res.authSetting["scope.camera"]) {
  254. common_vendor.index.authorize({
  255. scope: "scope.camera",
  256. success: () => {
  257. console.log("相机权限已获取");
  258. },
  259. fail: (err) => {
  260. console.error("相机权限获取失败:", err);
  261. this.showPermissionDialog("相机");
  262. }
  263. });
  264. }
  265. const systemInfo2 = common_vendor.index.getSystemInfoSync();
  266. if (systemInfo2.platform === "ios") {
  267. if (!res.authSetting["scope.camera"] || !res.authSetting["scope.record"]) {
  268. console.log("iOS需要同时获取相机和录音权限");
  269. }
  270. }
  271. }
  272. });
  273. } else {
  274. try {
  275. const constraints = {
  276. audio: {
  277. echoCancellation: true,
  278. noiseSuppression: true,
  279. autoGainControl: true
  280. },
  281. video: {
  282. width: { ideal: 640, max: 1280 },
  283. // 控制视频宽度
  284. height: { ideal: 480, max: 720 },
  285. // 控制视频高度
  286. frameRate: { ideal: 15, max: 24 },
  287. // 控制帧率
  288. facingMode: "user"
  289. }
  290. };
  291. const stream = await navigator.mediaDevices.getUserMedia(constraints);
  292. this.cameraStream = stream;
  293. const audioTracks = stream.getAudioTracks();
  294. console.log("音频轨道数量:", audioTracks.length);
  295. if (audioTracks.length > 0) {
  296. console.log("音频轨道已获取:", audioTracks[0].label);
  297. audioTracks[0].enabled = true;
  298. } else {
  299. console.warn("未检测到音频轨道,尝试单独获取音频");
  300. this.tryGetAudioOnly();
  301. }
  302. const videoElement = this.$refs.userCameraVideo;
  303. if (videoElement) {
  304. videoElement.srcObject = stream;
  305. videoElement.muted = true;
  306. }
  307. } catch (error) {
  308. console.error("获取摄像头失败:", error);
  309. this.cameraError = error.message || "无法访问摄像头";
  310. common_vendor.index.showToast({
  311. title: "无法访问摄像头,请检查权限设置",
  312. icon: "none"
  313. });
  314. }
  315. }
  316. },
  317. // 停止用户摄像头
  318. stopUserCamera() {
  319. if (this.cameraStream) {
  320. this.cameraStream.getTracks().forEach((track) => {
  321. track.stop();
  322. });
  323. this.cameraStream = null;
  324. }
  325. },
  326. async fetchData() {
  327. this.loading = true;
  328. this.assistantResponse = "";
  329. this.audioTranscript = "";
  330. this.processedResponses = [];
  331. try {
  332. const requestTask = common_vendor.index.request({
  333. url: "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions",
  334. method: "POST",
  335. header: {
  336. "Content-Type": "application/json",
  337. "Authorization": "Bearer sk-9e1ec73a7d97493b8613c63f06b6110c"
  338. },
  339. data: {
  340. "model": "qwen-omni-turbo",
  341. "messages": [
  342. {
  343. "role": "user",
  344. "content": [
  345. {
  346. "type": "input_audio",
  347. "input_audio": {
  348. "data": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250211/tixcef/cherry.wav",
  349. "format": "wav"
  350. }
  351. },
  352. {
  353. "type": "text",
  354. "text": "这段音频在说什么"
  355. }
  356. ]
  357. }
  358. ],
  359. "stream": true,
  360. "stream_options": {
  361. "include_usage": true
  362. },
  363. "modalities": ["text", "audio"],
  364. "audio": { "voice": "Cherry", "format": "wav" }
  365. },
  366. success: (res) => {
  367. console.log("请求成功,响应数据:", res.data);
  368. if (typeof res.data === "string" && res.data.includes("data: {")) {
  369. const chunks = res.data.split("data: ").filter((chunk) => chunk.trim() !== "");
  370. chunks.forEach((chunk) => {
  371. this.handleStreamResponse(chunk);
  372. });
  373. } else {
  374. this.handleStreamResponse(res.data);
  375. }
  376. this.playDigitalHumanVideo();
  377. },
  378. fail: (err) => {
  379. console.error("请求失败:", err);
  380. },
  381. complete: () => {
  382. this.loading = false;
  383. }
  384. });
  385. } catch (error) {
  386. console.error("获取数据失败:", error);
  387. this.loading = false;
  388. }
  389. },
  390. handleStreamResponse(data) {
  391. if (typeof data === "string") {
  392. if (data === "[DONE]")
  393. return;
  394. try {
  395. const cleanData = data.trim();
  396. if (cleanData.startsWith("{") && cleanData.endsWith("}")) {
  397. const jsonData = JSON.parse(cleanData);
  398. this.processStreamChunk(jsonData);
  399. }
  400. } catch (e) {
  401. console.error("解析JSON失败:", e, "原始数据:", data);
  402. }
  403. } else {
  404. this.processStreamChunk(data);
  405. }
  406. },
  407. processStreamChunk(chunk) {
  408. if (chunk.choices && chunk.choices.length > 0) {
  409. const choice = chunk.choices[0];
  410. if (choice.delta && choice.delta.content) {
  411. this.assistantResponse += choice.delta.content;
  412. }
  413. if (choice.delta && choice.delta.audio && choice.delta.audio.transcript) {
  414. this.audioTranscript += choice.delta.audio.transcript;
  415. }
  416. if (choice.delta) {
  417. const result = {};
  418. if (choice.delta.role) {
  419. result.role = choice.delta.role;
  420. }
  421. if (choice.delta.audio && choice.delta.audio.transcript) {
  422. result.transcript = choice.delta.audio.transcript;
  423. }
  424. if (Object.keys(result).length > 0) {
  425. this.processedResponses.push(result);
  426. }
  427. }
  428. }
  429. },
  430. processResponseData() {
  431. this.processedResponses = this.responses.map((item) => {
  432. const result = {};
  433. if (item.delta && item.delta.role) {
  434. result.role = item.delta.role;
  435. }
  436. if (item.delta && item.delta.audio && item.delta.audio.transcript) {
  437. result.transcript = item.delta.audio.transcript;
  438. }
  439. return result;
  440. }).filter((item) => Object.keys(item).length > 0);
  441. },
  442. // 播放数字人视频
  443. playDigitalHumanVideo() {
  444. var _a;
  445. if (JSON.parse(common_vendor.index.getStorageSync("configData")) == null) {
  446. this.videoUrl = this.videoList[this.currentVideoIndex];
  447. } else {
  448. this.videoUrl = ((_a = JSON.parse(common_vendor.index.getStorageSync("configData")).digital_human) == null ? void 0 : _a.ending_video_url) || this.videoList[this.currentVideoIndex];
  449. }
  450. this.videoPlaying = true;
  451. console.log(`播放视频 ${this.currentVideoIndex + 1}/${this.videoList.length}: ${this.videoUrl}`);
  452. this.$nextTick(() => {
  453. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  454. if (videoContext) {
  455. videoContext.play();
  456. setTimeout(() => {
  457. if (this.videoPlaying && this.$refs.videoPlayer) {
  458. console.log("视频应该正在播放");
  459. } else {
  460. console.log("视频可能未成功播放,尝试替代方案");
  461. this.tryAlternativeVideoPath();
  462. }
  463. }, 1e3);
  464. } else {
  465. console.error("无法创建视频上下文");
  466. this.tryAlternativeVideoPath();
  467. }
  468. });
  469. },
  470. // 修改 tryAlternativeVideoPath 方法
  471. tryAlternativeVideoPath() {
  472. console.log("尝试使用替代路径");
  473. const alternativePaths = [
  474. "./static/demo.mp4",
  475. "../static/demo.mp4",
  476. "static/demo.mp4",
  477. "/static/demo.mp4",
  478. // 添加绝对路径
  479. `${window.location.origin}/static/demo.mp4`
  480. ];
  481. const currentPathIndex = alternativePaths.indexOf(this.videoUrl);
  482. const nextPathIndex = (currentPathIndex + 1) % alternativePaths.length;
  483. this.videoUrl = alternativePaths[nextPathIndex];
  484. console.log("尝试新路径:", this.videoUrl);
  485. this.$nextTick(() => {
  486. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  487. if (videoContext) {
  488. videoContext.stop();
  489. videoContext.play();
  490. setTimeout(() => {
  491. if (nextPathIndex === alternativePaths.length - 1 && !this.videoPlaying) {
  492. console.log("所有路径均失败,尝试使用uni.getVideoInfo检查视频");
  493. this.checkVideoWithAPI();
  494. }
  495. }, 1e3);
  496. }
  497. });
  498. },
  499. // 添加新方法:使用uni API检查视频
  500. checkVideoWithAPI() {
  501. common_vendor.index.getVideoInfo({
  502. src: "/static/demo.mp4",
  503. success: (res) => {
  504. console.log("视频信息获取成功:", res);
  505. this.videoUrl = "/static/demo.mp4";
  506. this.$nextTick(() => {
  507. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  508. if (videoContext) {
  509. videoContext.play();
  510. }
  511. });
  512. },
  513. fail: (err) => {
  514. console.error("视频信息获取失败:", err);
  515. this.fallbackToLocalVideo();
  516. }
  517. });
  518. },
  519. // 添加新方法:回退到本地视频
  520. fallbackToLocalVideo() {
  521. console.log("尝试使用本地视频资源");
  522. const platform = common_vendor.index.getSystemInfoSync().platform;
  523. if (platform === "android" || platform === "ios") {
  524. this.videoUrl = platform === "android" ? "android.resource://package_name/raw/demo" : "file:///assets/demo.mp4";
  525. this.$nextTick(() => {
  526. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  527. if (videoContext) {
  528. videoContext.play();
  529. }
  530. });
  531. } else {
  532. this.videoPlaying = false;
  533. common_vendor.index.showToast({
  534. title: "视频加载失败,显示静态图片",
  535. icon: "none"
  536. });
  537. }
  538. },
  539. // 修改 handleVideoError 方法
  540. handleVideoError(e) {
  541. console.error("视频加载错误:", e);
  542. if (e && e.detail) {
  543. console.error("详细错误信息:", e.detail);
  544. }
  545. common_vendor.index.getFileInfo({
  546. filePath: this.videoUrl.startsWith("/") ? this.videoUrl.substring(1) : this.videoUrl,
  547. success: (res) => {
  548. console.log("文件存在,大小:", res.size);
  549. this.tryDifferentFormat();
  550. },
  551. fail: (err) => {
  552. console.error("文件不存在或无法访问:", err);
  553. this.tryAlternativeVideoPath();
  554. }
  555. });
  556. common_vendor.index.showToast({
  557. title: "视频加载失败,请检查文件是否存在",
  558. icon: "none",
  559. duration: 2e3
  560. });
  561. },
  562. // 添加新方法:尝试不同格式
  563. tryDifferentFormat() {
  564. console.log("尝试不同的视频格式");
  565. const formats = [
  566. { ext: "mp4", mime: "video/mp4" },
  567. { ext: "webm", mime: "video/webm" },
  568. { ext: "ogg", mime: "video/ogg" },
  569. { ext: "mov", mime: "video/quicktime" }
  570. ];
  571. const currentPath = this.videoUrl;
  572. const basePath = currentPath.substring(0, currentPath.lastIndexOf(".")) || "/static/demo";
  573. let nextFormat = formats.find((f) => !currentPath.endsWith(f.ext));
  574. if (nextFormat) {
  575. this.videoUrl = `${basePath}.${nextFormat.ext}`;
  576. console.log("尝试新格式:", this.videoUrl);
  577. this.$nextTick(() => {
  578. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  579. if (videoContext) {
  580. videoContext.stop();
  581. videoContext.play();
  582. }
  583. });
  584. } else {
  585. this.useBuiltInResource();
  586. }
  587. },
  588. // 添加新方法:使用内置资源
  589. useBuiltInResource() {
  590. console.log("尝试使用内置资源");
  591. const platform = common_vendor.index.getSystemInfoSync().platform;
  592. if (platform === "windows") {
  593. process.env.UNI_INPUT_DIR || "";
  594. this.videoUrl = `./static/demo.mp4`;
  595. console.log("Windows平台尝试路径:", this.videoUrl);
  596. } else if (platform === "android" || platform === "ios") {
  597. this.useNativeVideo();
  598. } else {
  599. const baseUrl = window.location.origin;
  600. this.videoUrl = `${baseUrl}/static/demo.mp4`;
  601. console.log("Web平台尝试URL:", this.videoUrl);
  602. }
  603. this.$nextTick(() => {
  604. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  605. if (videoContext) {
  606. videoContext.play();
  607. }
  608. });
  609. },
  610. // 添加新方法:使用原生视频能力
  611. useNativeVideo() {
  612. console.log("尝试使用原生视频能力");
  613. common_vendor.index.chooseVideo({
  614. sourceType: ["album"],
  615. success: (res) => {
  616. this.videoUrl = res.tempFilePath;
  617. this.$nextTick(() => {
  618. const videoContext = common_vendor.index.createVideoContext("myVideo", this);
  619. if (videoContext) {
  620. videoContext.play();
  621. }
  622. });
  623. },
  624. fail: () => {
  625. this.videoPlaying = false;
  626. common_vendor.index.showToast({
  627. title: "无法加载视频,显示静态图片",
  628. icon: "none"
  629. });
  630. }
  631. });
  632. },
  633. // 处理视频结束事件
  634. handleVideoEnded() {
  635. console.log("视频播放结束,当前视频索引:", this.currentVideoIndex);
  636. this.videoPlaying = false;
  637. this.showStartRecordingButton = true;
  638. this.startCountdown();
  639. this.showAnswerButton = false;
  640. },
  641. // 添加新方法:开始倒计时
  642. startCountdown() {
  643. this.showCountdown = true;
  644. this.countdownValue = 10;
  645. this.countdownTimer = setInterval(() => {
  646. this.countdownValue--;
  647. if (this.countdownValue <= 0) {
  648. this.clearCountdown();
  649. this.showStartRecordingButton = false;
  650. this.startRecordingAnswer();
  651. }
  652. }, 1e3);
  653. },
  654. // 添加新方法:清除倒计时
  655. clearCountdown() {
  656. if (this.countdownTimer) {
  657. clearInterval(this.countdownTimer);
  658. this.countdownTimer = null;
  659. }
  660. this.showCountdown = false;
  661. },
  662. // 修改 handleStartRecordingClick 方法,使其可以终止倒计时
  663. handleStartRecordingClick() {
  664. this.showStartRecordingButton = false;
  665. this.clearCountdown();
  666. this.startRecordingAnswer();
  667. },
  668. // 修复 stopRecordingAnswer 方法,确保录制正确停止并上传
  669. stopRecordingAnswer() {
  670. this.clearCountdown();
  671. const recordingDuration = this.getRecordingDuration();
  672. const minimumDuration = 5;
  673. if (recordingDuration < minimumDuration) {
  674. common_vendor.index.showToast({
  675. title: "录制时间过短,请至少录制5秒",
  676. icon: "none",
  677. duration: 2e3
  678. });
  679. return;
  680. }
  681. this.showStopRecordingButton = false;
  682. if (this.recordingTimer) {
  683. clearInterval(this.recordingTimer);
  684. this.recordingTimer = null;
  685. }
  686. const systemInfo = common_vendor.index.getSystemInfoSync();
  687. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
  688. if (isMiniProgram) {
  689. this.stopMiniProgramRecording();
  690. } else {
  691. this.stopBrowserRecording();
  692. }
  693. this.isRecording = false;
  694. },
  695. // 添加新方法:开始录制用户回答
  696. startRecordingAnswer() {
  697. console.log("开始录制用户回答");
  698. this.isRecording = true;
  699. this.recordingStartTime = Date.now();
  700. this.recordingTimerCount = 0;
  701. this.remainingTime = this.maxRecordingTime;
  702. this.recordingTimer = setInterval(() => {
  703. this.recordingTimerCount++;
  704. this.remainingTime = Math.max(0, this.maxRecordingTime - this.recordingTimerCount);
  705. this.recordingTimeDisplay = this.formatTime(this.recordingTimerCount) + " / " + this.formatTime(this.maxRecordingTime);
  706. if (this.recordingTimerCount >= this.maxRecordingTime) {
  707. console.log("已达到最大录制时间(60秒),自动停止录制");
  708. this.stopRecordingAnswer();
  709. }
  710. }, 1e3);
  711. const systemInfo = common_vendor.index.getSystemInfoSync();
  712. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
  713. if (isMiniProgram) {
  714. this.startMiniProgramRecording();
  715. } else {
  716. this.startBrowserRecording();
  717. }
  718. this.showStopRecordingButton = true;
  719. },
  720. // 添加一个新方法:重置相机组件
  721. resetCamera() {
  722. console.log("重置相机组件");
  723. this.useMiniProgramCameraComponent = false;
  724. if (this.cameraContext) {
  725. this.cameraContext = null;
  726. }
  727. setTimeout(() => {
  728. this.useMiniProgramCameraComponent = true;
  729. setTimeout(() => {
  730. this.cameraContext = common_vendor.index.createCameraContext();
  731. console.log("相机组件已重置");
  732. }, 500);
  733. }, 500);
  734. },
  735. // 修改 startMiniProgramRecording 方法
  736. startMiniProgramRecording() {
  737. console.log("开始小程序录制方法");
  738. const systemInfo = common_vendor.index.getSystemInfoSync();
  739. const isIOS = systemInfo.platform === "ios";
  740. if (isIOS) {
  741. this.resetCamera();
  742. setTimeout(() => {
  743. this.actualStartRecording(isIOS);
  744. }, 1e3);
  745. } else {
  746. this.actualStartRecording(isIOS);
  747. }
  748. },
  749. // 添加新方法:实际开始录制
  750. actualStartRecording(isIOS) {
  751. if (!this.cameraContext) {
  752. this.cameraContext = common_vendor.index.createCameraContext();
  753. console.log("创建新的相机上下文");
  754. }
  755. common_vendor.index.getSetting({
  756. success: (res) => {
  757. const hasRecordAuth = res.authSetting["scope.record"];
  758. const hasCameraAuth = res.authSetting["scope.camera"];
  759. if (!hasRecordAuth || !hasCameraAuth) {
  760. console.warn("缺少必要权限,请求权限");
  761. this.requestMiniProgramPermissions();
  762. return;
  763. }
  764. if (isIOS) {
  765. console.log("iOS: 检查相机状态");
  766. const options = {
  767. timeout: 3e5,
  768. // 300秒超时 (5分钟)
  769. quality: "low",
  770. // 降低质量
  771. compressed: true,
  772. success: () => {
  773. console.log("iOS录制开始成功");
  774. },
  775. fail: (err) => {
  776. console.error("iOS录制失败:", err);
  777. this.useAlternativeRecordingMethod();
  778. }
  779. };
  780. try {
  781. console.log("尝试开始录制");
  782. this.recorder = this.cameraContext.startRecord(options);
  783. } catch (e) {
  784. console.error("开始录制异常:", e);
  785. this.useAlternativeRecordingMethod();
  786. }
  787. } else {
  788. const options = {
  789. timeout: 3e5,
  790. // 300秒超时 (5分钟)
  791. quality: "medium",
  792. compressed: true,
  793. success: () => {
  794. console.log("Android录制开始成功");
  795. },
  796. fail: (err) => {
  797. console.error("Android录制失败:", err);
  798. common_vendor.index.showToast({
  799. title: "录制失败,请检查相机权限",
  800. icon: "none"
  801. });
  802. this.proceedToNextQuestion();
  803. }
  804. };
  805. this.recorder = this.cameraContext.startRecord(options);
  806. }
  807. }
  808. });
  809. },
  810. // 添加新方法:使用替代录制方法
  811. useAlternativeRecordingMethod() {
  812. console.log("使用替代录制方法");
  813. common_vendor.index.showActionSheet({
  814. itemList: ["使用相册中的视频", "跳过此问题"],
  815. success: (res) => {
  816. if (res.tapIndex === 0) {
  817. common_vendor.index.chooseVideo({
  818. sourceType: ["album"],
  819. maxDuration: 300,
  820. // 从60秒改为300秒
  821. camera: "front",
  822. success: (res2) => {
  823. console.log("选择视频成功:", res2.tempFilePath);
  824. this.isRecording = false;
  825. this.showStopRecordingButton = false;
  826. this.uploadRecordedVideo(res2.tempFilePath);
  827. },
  828. fail: () => {
  829. console.log("用户取消选择视频");
  830. this.proceedToNextQuestion();
  831. }
  832. });
  833. } else {
  834. console.log("用户选择跳过问题");
  835. this.proceedToNextQuestion();
  836. }
  837. },
  838. fail: () => {
  839. console.log("操作取消");
  840. this.proceedToNextQuestion();
  841. }
  842. });
  843. },
  844. // 添加新方法:请求小程序权限
  845. requestMiniProgramPermissions() {
  846. common_vendor.index.authorize({
  847. scope: "scope.record",
  848. success: () => {
  849. console.log("录音权限已获取");
  850. common_vendor.index.authorize({
  851. scope: "scope.camera",
  852. success: () => {
  853. console.log("相机权限已获取");
  854. this.startMiniProgramRecording();
  855. },
  856. fail: (err) => {
  857. console.error("相机权限获取失败:", err);
  858. this.showPermissionDialog("相机");
  859. }
  860. });
  861. },
  862. fail: (err) => {
  863. console.error("录音权限获取失败:", err);
  864. this.showPermissionDialog("录音");
  865. }
  866. });
  867. },
  868. // 修改浏览器环境下的录制方法
  869. startBrowserRecording() {
  870. if (!this.cameraStream) {
  871. console.error("没有可用的摄像头流");
  872. common_vendor.index.showToast({
  873. title: "录制失败,摄像头未就绪",
  874. icon: "none"
  875. });
  876. this.proceedToNextQuestion();
  877. return;
  878. }
  879. try {
  880. const hasAudio = this.cameraStream.getAudioTracks().length > 0;
  881. if (!hasAudio) {
  882. console.warn("警告:媒体流中没有音频轨道,尝试重新获取带音频的媒体流");
  883. navigator.mediaDevices.getUserMedia({
  884. audio: {
  885. echoCancellation: true,
  886. noiseSuppression: true,
  887. autoGainControl: true
  888. },
  889. video: true
  890. }).then((newStream) => {
  891. const audioTracks = newStream.getAudioTracks();
  892. if (audioTracks.length > 0) {
  893. console.log("成功获取音频轨道:", audioTracks[0].label);
  894. const videoTrack = this.cameraStream.getVideoTracks()[0];
  895. const audioTrack = newStream.getAudioTracks()[0];
  896. const combinedStream = new MediaStream();
  897. if (videoTrack)
  898. combinedStream.addTrack(videoTrack);
  899. if (audioTrack)
  900. combinedStream.addTrack(audioTrack);
  901. this.cameraStream = combinedStream;
  902. const videoElement = this.$refs.userCameraVideo;
  903. if (videoElement) {
  904. videoElement.srcObject = combinedStream;
  905. videoElement.muted = true;
  906. }
  907. this.setupMediaRecorder(combinedStream);
  908. } else {
  909. console.warn("仍然无法获取音频轨道");
  910. this.setupMediaRecorder(this.cameraStream);
  911. }
  912. }).catch((err) => {
  913. console.error("获取音频失败:", err);
  914. this.setupMediaRecorder(this.cameraStream);
  915. });
  916. } else {
  917. console.log("检测到音频轨道,直接使用");
  918. this.setupMediaRecorder(this.cameraStream);
  919. }
  920. } catch (error) {
  921. console.error("浏览器录制失败:", error);
  922. common_vendor.index.showToast({
  923. title: "录制失败,浏览器可能不支持此功能",
  924. icon: "none"
  925. });
  926. this.proceedToNextQuestion();
  927. }
  928. },
  929. // 修改 setupMediaRecorder 方法
  930. setupMediaRecorder(stream) {
  931. const videoTracks = stream.getVideoTracks();
  932. const audioTracks = stream.getAudioTracks();
  933. console.log("设置MediaRecorder - 视频轨道:", videoTracks.length, "音频轨道:", audioTracks.length);
  934. let mimeType = "";
  935. const supportedTypes = [
  936. "video/webm;codecs=vp9,opus",
  937. "video/webm;codecs=vp8,opus",
  938. "video/webm;codecs=h264,opus",
  939. "video/mp4;codecs=h264,aac",
  940. "video/webm",
  941. "video/mp4"
  942. ];
  943. for (const type of supportedTypes) {
  944. if (MediaRecorder.isTypeSupported(type)) {
  945. mimeType = type;
  946. console.log("使用支持的MIME类型:", mimeType);
  947. break;
  948. }
  949. }
  950. const options = {
  951. mimeType: mimeType || "",
  952. audioBitsPerSecond: 64e3,
  953. // 降低音频比特率
  954. videoBitsPerSecond: 1e6
  955. // 降低视频比特率到1Mbps
  956. };
  957. try {
  958. this.mediaRecorder = new MediaRecorder(stream, options);
  959. console.log("MediaRecorder创建成功,使用选项:", options);
  960. } catch (e) {
  961. console.warn("使用指定选项创建MediaRecorder失败,尝试使用默认选项");
  962. this.mediaRecorder = new MediaRecorder(stream);
  963. }
  964. this.recordedChunks = [];
  965. this.mediaRecorder.ondataavailable = (event) => {
  966. if (event.data && event.data.size > 0) {
  967. this.recordedChunks.push(event.data);
  968. console.log(`收到数据块: ${event.data.size} 字节`);
  969. }
  970. };
  971. this.mediaRecorder.onstop = async () => {
  972. console.log("MediaRecorder停止,数据块数量:", this.recordedChunks.length);
  973. if (this.recordedChunks.length === 0) {
  974. console.error("没有录制到数据");
  975. common_vendor.index.showToast({
  976. title: "录制失败,未捕获到数据",
  977. icon: "none"
  978. });
  979. this.proceedToNextQuestion();
  980. return;
  981. }
  982. const mimeType2 = this.mediaRecorder.mimeType || "video/webm";
  983. const blob = new Blob(this.recordedChunks, { type: mimeType2 });
  984. console.log("创建Blob,原始大小:", blob.size, "类型:", mimeType2);
  985. common_vendor.index.showLoading({
  986. title: "正在处理视频...",
  987. mask: true
  988. });
  989. try {
  990. const compressedBlob = await this.compressVideo(blob);
  991. const fileName = `answer_${this.currentVideoIndex}_${Date.now()}.webm`;
  992. const file = new File([compressedBlob], fileName, { type: mimeType2 });
  993. common_vendor.index.hideLoading();
  994. this.uploadRecordedVideo(file);
  995. } catch (error) {
  996. console.error("视频处理失败:", error);
  997. common_vendor.index.hideLoading();
  998. const fileName = `answer_${this.currentVideoIndex}_${Date.now()}.webm`;
  999. const file = new File([blob], fileName, { type: mimeType2 });
  1000. this.uploadRecordedVideo(file);
  1001. }
  1002. };
  1003. this.mediaRecorder.onerror = (event) => {
  1004. console.error("MediaRecorder错误:", event.error);
  1005. };
  1006. try {
  1007. this.mediaRecorder.start(1e3);
  1008. console.log("MediaRecorder开始录制");
  1009. this.mediaRecorderTimeout = setTimeout(() => {
  1010. if (this.mediaRecorder && this.mediaRecorder.state === "recording") {
  1011. console.log("MediaRecorder备份超时机制触发,停止录制");
  1012. this.mediaRecorder.stop();
  1013. }
  1014. }, 3e5);
  1015. } catch (e) {
  1016. console.error("开始录制失败:", e);
  1017. }
  1018. },
  1019. // 添加新方法:停止录制用户回答
  1020. stopRecordingAnswer() {
  1021. console.log("停止录制用户回答");
  1022. if (this.countdownTimer) {
  1023. clearInterval(this.countdownTimer);
  1024. this.countdownTimer = null;
  1025. this.showCountdown = false;
  1026. }
  1027. const recordingDuration = this.getRecordingDuration();
  1028. const minimumDuration = 5;
  1029. if (recordingDuration < minimumDuration) {
  1030. common_vendor.index.showToast({
  1031. title: "录制时间过短,请至少录制5秒",
  1032. icon: "none",
  1033. duration: 2e3
  1034. });
  1035. return;
  1036. }
  1037. this.showStopRecordingButton = false;
  1038. if (this.recordingTimer) {
  1039. clearInterval(this.recordingTimer);
  1040. this.recordingTimer = null;
  1041. }
  1042. const systemInfo = common_vendor.index.getSystemInfoSync();
  1043. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
  1044. if (isMiniProgram) {
  1045. this.stopMiniProgramRecording();
  1046. } else {
  1047. this.stopBrowserRecording();
  1048. }
  1049. this.isRecording = false;
  1050. },
  1051. // 添加新方法:获取录制时长
  1052. getRecordingDuration() {
  1053. if (this.recordingStartTime) {
  1054. return (Date.now() - this.recordingStartTime) / 1e3;
  1055. }
  1056. if (this.mediaRecorder && this.$refs.userCameraVideo) {
  1057. return this.$refs.userCameraVideo.currentTime || 0;
  1058. }
  1059. if (this.recordingTimerCount) {
  1060. return this.recordingTimerCount;
  1061. }
  1062. return 0;
  1063. },
  1064. // 添加新方法:重置录制
  1065. resetRecording() {
  1066. if (this.recordingTimer) {
  1067. clearTimeout(this.recordingTimer);
  1068. }
  1069. this.recordingStartTime = Date.now();
  1070. this.recordingTimerCount = 0;
  1071. if (this.mediaRecorder && this.mediaRecorder.state !== "inactive") {
  1072. this.mediaRecorder.stop();
  1073. this.recordedChunks = [];
  1074. setTimeout(() => {
  1075. this.startBrowserRecording();
  1076. }, 500);
  1077. } else if (this.cameraContext) {
  1078. this.cameraContext.stopRecord({
  1079. success: () => {
  1080. console.log("重置录制:停止当前录制成功");
  1081. setTimeout(() => {
  1082. this.startMiniProgramRecording();
  1083. }, 500);
  1084. },
  1085. fail: (err) => {
  1086. console.error("重置录制:停止当前录制失败", err);
  1087. this.startMiniProgramRecording();
  1088. }
  1089. });
  1090. }
  1091. common_vendor.index.showToast({
  1092. title: "请重新开始回答",
  1093. icon: "none",
  1094. duration: 2e3
  1095. });
  1096. },
  1097. // 修复 completeRecordingStop 方法,确保视频正确上传和处理
  1098. completeRecordingStop() {
  1099. console.log("完成录制停止");
  1100. this.showStopRecordingButton = false;
  1101. if (this.recordingTimer) {
  1102. clearInterval(this.recordingTimer);
  1103. this.recordingTimer = null;
  1104. }
  1105. this.isRecording = false;
  1106. this.showUploadStatus = true;
  1107. this.uploadStatusText = "正在处理视频...";
  1108. this.isUploading = true;
  1109. const systemInfo = common_vendor.index.getSystemInfoSync();
  1110. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
  1111. if (isMiniProgram) {
  1112. this.stopMiniProgramRecording();
  1113. } else {
  1114. this.stopBrowserRecording();
  1115. }
  1116. },
  1117. // 修复 stopMiniProgramRecording 方法,确保小程序环境下正确停止录制
  1118. stopMiniProgramRecording() {
  1119. console.log("停止小程序录制");
  1120. if (!this.cameraContext) {
  1121. console.error("相机上下文不存在");
  1122. this.handleRecordingError(new Error("相机上下文不存在"));
  1123. return;
  1124. }
  1125. try {
  1126. common_vendor.index.showLoading({
  1127. title: "正在处理视频...",
  1128. mask: true
  1129. });
  1130. this.cameraContext.stopRecord({
  1131. success: (res) => {
  1132. console.log("停止录制成功:", res);
  1133. common_vendor.index.hideLoading();
  1134. const tempVideoPath = res.tempVideoPath || res.tempFilePath;
  1135. if (tempVideoPath) {
  1136. console.log("获取到视频临时路径:", tempVideoPath);
  1137. this.uploadRecordedVideo(tempVideoPath);
  1138. } else {
  1139. console.error("未获取到视频临时路径");
  1140. this.handleRecordingError(new Error("未获取到视频临时路径"));
  1141. }
  1142. },
  1143. fail: (err) => {
  1144. console.error("停止录制失败:", err);
  1145. common_vendor.index.hideLoading();
  1146. this.handleRecordingError(err);
  1147. }
  1148. });
  1149. } catch (e) {
  1150. console.error("停止录制异常:", e);
  1151. common_vendor.index.hideLoading();
  1152. this.handleRecordingError(e);
  1153. }
  1154. },
  1155. // 添加新方法:停止浏览器录制
  1156. stopBrowserRecording() {
  1157. if (this.mediaRecorder && this.mediaRecorder.state !== "inactive") {
  1158. this.mediaRecorder.stop();
  1159. console.log("浏览器录制停止成功");
  1160. } else {
  1161. console.error("MediaRecorder不存在或已经停止");
  1162. this.proceedToNextQuestion();
  1163. }
  1164. },
  1165. // 修复 uploadRecordedVideo 方法,确保视频正确上传到服务器
  1166. uploadRecordedVideo(videoPath) {
  1167. console.log("开始上传录制的视频:", videoPath);
  1168. this.lastVideoToRetry = videoPath;
  1169. this.showUploadStatus = true;
  1170. this.uploadStatusText = "正在上传视频...";
  1171. this.isUploading = true;
  1172. this.saveUploadStatus();
  1173. const tenant_id = common_vendor.index.getStorageSync("tenant_id") || "1";
  1174. const openid = common_vendor.index.getStorageSync("userInfo") ? JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid : "";
  1175. const application_id = common_vendor.index.getStorageSync("appId") || "";
  1176. const uploadTask = common_vendor.index.uploadFile({
  1177. url: `${common_config.apiBaseUrl}/api/upload/`,
  1178. filePath: videoPath,
  1179. name: "file",
  1180. formData: {
  1181. tenant_id,
  1182. openid,
  1183. application_id,
  1184. biz_type: "interview_video",
  1185. video_duration: this.recordingTimerCount || 0,
  1186. has_audio: "true"
  1187. // 明确标记包含音频
  1188. },
  1189. success: (uploadRes) => {
  1190. var _a, _b;
  1191. console.log("视频上传成功:", uploadRes);
  1192. try {
  1193. const result = typeof uploadRes.data === "string" ? JSON.parse(uploadRes.data) : uploadRes.data;
  1194. if ((result.success || result.code === 2e3) && (((_a = result.data) == null ? void 0 : _a.url) || ((_b = result.data) == null ? void 0 : _b.permanent_link))) {
  1195. const videoUrl = result.data.url || result.data.permanent_link || "";
  1196. console.log("视频URL:", videoUrl);
  1197. this.uploadStatusText = "视频处理完成,正在分析...";
  1198. this.saveUploadStatus();
  1199. this.submitToAiVoiceInteraction(videoUrl);
  1200. } else {
  1201. console.error("上传响应格式错误:", result);
  1202. const errorMsg = result.msg || result.message || "上传响应格式错误";
  1203. this.handleUploadError(new Error(errorMsg));
  1204. }
  1205. } catch (e) {
  1206. console.error("解析上传响应失败:", e);
  1207. this.handleUploadError(e);
  1208. }
  1209. },
  1210. fail: (err) => {
  1211. console.error("视频上传失败:", err);
  1212. let errorMessage = "网络错误,请检查网络连接";
  1213. if (err.errMsg) {
  1214. if (err.errMsg.includes("timeout")) {
  1215. errorMessage = "上传超时,请检查网络连接";
  1216. } else if (err.errMsg.includes("fail")) {
  1217. errorMessage = "上传失败: " + err.errMsg;
  1218. }
  1219. }
  1220. this.handleUploadError(new Error(errorMessage));
  1221. },
  1222. complete: () => {
  1223. this.showUploadStatus = false;
  1224. this.isUploading = false;
  1225. this.saveUploadStatus();
  1226. }
  1227. });
  1228. uploadTask.onProgressUpdate((res) => {
  1229. console.log("上传进度:", res.progress);
  1230. this.uploadStatusText = `正在上传视频... ${res.progress}%`;
  1231. if (res.progress < 10 && res.totalTimeMs > 1e4) {
  1232. this.uploadStatusText = `上传速度较慢,请耐心等待... ${res.progress}%`;
  1233. }
  1234. });
  1235. },
  1236. // 修改 processUploadQueue 方法,添加后台上传支持
  1237. processUploadQueue() {
  1238. if (this.uploadQueue.length === 0) {
  1239. this.isUploading = false;
  1240. this.showUploadStatus = false;
  1241. try {
  1242. common_vendor.index.removeStorageSync("videoUploadStatus");
  1243. } catch (e) {
  1244. console.error("清除上传状态失败:", e);
  1245. }
  1246. this.notifyUploadComplete();
  1247. return;
  1248. }
  1249. this.isUploading = true;
  1250. this.showUploadStatus = true;
  1251. const task = this.uploadQueue[0];
  1252. this.uploadStatus[task.id] = "uploading";
  1253. this.updateUploadStatusText();
  1254. task.attempts++;
  1255. if (typeof task.file !== "string") {
  1256. this.uploadFileWithXHR(task);
  1257. } else {
  1258. this.uploadFileWithUni(task);
  1259. }
  1260. this.saveUploadStatus();
  1261. },
  1262. // 添加新方法:发送上传完成通知
  1263. notifyUploadComplete() {
  1264. try {
  1265. common_vendor.index.$emit("videoUploadComplete", {
  1266. timestamp: Date.now()
  1267. });
  1268. console.log("发送上传完成通知");
  1269. } catch (e) {
  1270. console.error("发送上传完成通知失败:", e);
  1271. }
  1272. const systemInfo = common_vendor.index.getSystemInfoSync();
  1273. if (systemInfo.platform === "android" || systemInfo.platform === "ios") {
  1274. if (plus && plus.push) {
  1275. plus.push.createMessage("视频上传完成", "您的面试视频已成功上传", {});
  1276. }
  1277. }
  1278. },
  1279. // 添加新方法:使用XMLHttpRequest上传文件
  1280. uploadFileWithXHR(task) {
  1281. const userInfo = common_vendor.index.getStorageSync("userInfo");
  1282. const openid = userInfo ? JSON.parse(userInfo).openid || "" : "";
  1283. const tenant_id = common_vendor.index.getStorageSync("tenant_id") || "1";
  1284. const formData = new FormData();
  1285. formData.append("file", task.file);
  1286. formData.append("openid", openid);
  1287. formData.append("tenant_id", tenant_id);
  1288. formData.append("application_id", common_vendor.index.getStorageSync("appId"));
  1289. formData.append("question_id", task.questionId);
  1290. formData.append("video_duration", this.recordingTimerCount || 0);
  1291. formData.append("has_audio", "true");
  1292. const xhr = new XMLHttpRequest();
  1293. xhr.open("POST", `${common_config.apiBaseUrl}/api/upload/`, true);
  1294. xhr.timeout = 12e4;
  1295. xhr.upload.onprogress = (event) => {
  1296. if (event.lengthComputable) {
  1297. const percentComplete = Math.round(event.loaded / event.total * 100);
  1298. this.uploadProgress[task.id] = percentComplete;
  1299. this.updateUploadStatusText();
  1300. }
  1301. };
  1302. xhr.onload = () => {
  1303. if (xhr.status === 200) {
  1304. try {
  1305. const res = JSON.parse(xhr.responseText);
  1306. console.log("上传响应:", res);
  1307. if (res.code === 2e3) {
  1308. const videoUrl = res.data.url || res.data.photoUrl || "";
  1309. if (videoUrl) {
  1310. this.uploadStatus[task.id] = "success";
  1311. this.updateUploadStatusText();
  1312. this.submitVideoToInterview(videoUrl, task);
  1313. } else {
  1314. this.handleUploadFailure(task, "视频URL获取失败");
  1315. }
  1316. } else {
  1317. this.handleUploadFailure(task, res.msg || "上传失败");
  1318. }
  1319. } catch (e) {
  1320. this.handleUploadFailure(task, "解析响应失败");
  1321. }
  1322. } else {
  1323. this.handleUploadFailure(task, "HTTP状态: " + xhr.status);
  1324. }
  1325. };
  1326. xhr.onerror = () => {
  1327. this.handleUploadFailure(task, "网络错误");
  1328. };
  1329. xhr.ontimeout = () => {
  1330. this.handleUploadFailure(task, "上传超时");
  1331. };
  1332. xhr.send(formData);
  1333. },
  1334. // 添加新方法:使用uni.uploadFile上传文件
  1335. uploadFileWithUni(task) {
  1336. const userInfo = common_vendor.index.getStorageSync("userInfo");
  1337. const openid = userInfo ? JSON.parse(userInfo).openid || "" : "";
  1338. const tenant_id = common_vendor.index.getStorageSync("tenant_id") || "1";
  1339. const uploadTask = common_vendor.index.uploadFile({
  1340. url: `${common_config.apiBaseUrl}/api/upload/`,
  1341. filePath: task.file,
  1342. name: "file",
  1343. formData: {
  1344. openid,
  1345. tenant_id,
  1346. application_id: common_vendor.index.getStorageSync("appId"),
  1347. question_id: task.questionId,
  1348. video_duration: this.recordingTimerCount || 0,
  1349. has_audio: "true"
  1350. // 明确标记包含音频
  1351. },
  1352. success: (uploadRes) => {
  1353. try {
  1354. const res = JSON.parse(uploadRes.data);
  1355. console.log("上传响应:", res);
  1356. if (res.code === 2e3) {
  1357. const videoUrl = res.data.permanent_link || res.data.url || "";
  1358. if (videoUrl) {
  1359. this.uploadStatus[task.id] = "success";
  1360. this.updateUploadStatusText();
  1361. this.submitVideoToInterview(videoUrl, task);
  1362. } else {
  1363. this.handleUploadFailure(task, "视频URL获取失败");
  1364. }
  1365. } else {
  1366. this.handleUploadFailure(task, res.msg || "上传失败");
  1367. }
  1368. } catch (e) {
  1369. this.handleUploadFailure(task, "解析响应失败");
  1370. }
  1371. },
  1372. fail: (err) => {
  1373. this.handleUploadFailure(task, err.errMsg || "上传失败");
  1374. }
  1375. });
  1376. uploadTask.onProgressUpdate((res) => {
  1377. this.uploadProgress[task.id] = res.progress;
  1378. this.updateUploadStatusText();
  1379. });
  1380. },
  1381. // 添加新方法:处理上传失败
  1382. handleUploadFailure(task, errorMsg) {
  1383. console.error("上传失败:", errorMsg);
  1384. this.uploadStatus[task.id] = "failed";
  1385. this.updateUploadStatusText();
  1386. if (task.attempts < task.maxAttempts) {
  1387. console.log(`将在5秒后重试上传,当前尝试次数: ${task.attempts}/${task.maxAttempts}`);
  1388. setTimeout(() => {
  1389. this.uploadProgress[task.id] = 0;
  1390. if (typeof task.file !== "string") {
  1391. this.uploadFileWithXHR(task);
  1392. } else {
  1393. this.uploadFileWithUni(task);
  1394. }
  1395. }, 5e3);
  1396. } else {
  1397. console.log("超过最大重试次数,放弃上传");
  1398. common_vendor.index.showToast({
  1399. title: "视频上传失败,请稍后重试",
  1400. icon: "none",
  1401. duration: 2e3
  1402. });
  1403. this.uploadQueue.shift();
  1404. this.processUploadQueue();
  1405. }
  1406. },
  1407. // 修改 submitVideoToInterview 方法
  1408. submitVideoToInterview(videoUrl, task = null) {
  1409. console.log("提交视频URL到面试接口:", videoUrl);
  1410. let questionId;
  1411. if (task) {
  1412. questionId = task.questionId;
  1413. } else {
  1414. switch (this.currentVideoIndex) {
  1415. case 1:
  1416. questionId = 36;
  1417. break;
  1418. case 2:
  1419. questionId = 11;
  1420. break;
  1421. case 3:
  1422. questionId = 12;
  1423. break;
  1424. case 4:
  1425. questionId = 13;
  1426. break;
  1427. default:
  1428. questionId = 10;
  1429. }
  1430. }
  1431. ({
  1432. application_id: common_vendor.index.getStorageSync("appId"),
  1433. question_id: questionId,
  1434. video_url: videoUrl,
  1435. tenant_id: common_vendor.index.getStorageSync("tenant_id") || "1",
  1436. has_audio: true
  1437. // 明确标记包含音频
  1438. });
  1439. this.submitToAiVoiceInteraction(videoUrl);
  1440. },
  1441. // 添加新方法:处理提交失败
  1442. handleSubmitFailure(task, errorMsg) {
  1443. console.error("提交失败:", errorMsg);
  1444. this.uploadStatus[task.id] = "failed";
  1445. this.updateUploadStatusText();
  1446. if (task.attempts < task.maxAttempts) {
  1447. console.log(`将在5秒后重试提交,当前尝试次数: ${task.attempts}/${task.maxAttempts}`);
  1448. setTimeout(() => {
  1449. this.submitVideoToInterview(task.videoUrl, task);
  1450. }, 5e3);
  1451. } else {
  1452. console.log("超过最大重试次数,放弃提交");
  1453. common_vendor.index.showToast({
  1454. title: "视频提交失败,请稍后重试",
  1455. icon: "none",
  1456. duration: 2e3
  1457. });
  1458. this.uploadQueue.shift();
  1459. this.processUploadQueue();
  1460. }
  1461. },
  1462. // 添加新方法:更新上传状态文本
  1463. updateUploadStatusText() {
  1464. if (this.uploadQueue.length === 0) {
  1465. this.uploadStatusText = "";
  1466. return;
  1467. }
  1468. const currentTask = this.uploadQueue[0];
  1469. const progress = this.uploadProgress[currentTask.id] || 0;
  1470. const status = this.uploadStatus[currentTask.id] || "pending";
  1471. let statusText = "";
  1472. switch (status) {
  1473. case "pending":
  1474. statusText = "等待上传";
  1475. break;
  1476. case "uploading":
  1477. statusText = `上传中 ${progress}%`;
  1478. break;
  1479. case "success":
  1480. statusText = "上传成功,提交中...";
  1481. break;
  1482. case "failed":
  1483. statusText = `上传失败,${currentTask.attempts < currentTask.maxAttempts ? "即将重试" : "已放弃"}`;
  1484. break;
  1485. }
  1486. this.uploadStatusText = `问题${currentTask.questionId - 9}:${statusText}`;
  1487. if (this.uploadQueue.length > 1) {
  1488. this.uploadStatusText += ` (${this.uploadQueue.length}个视频待处理)`;
  1489. }
  1490. },
  1491. // 修改 proceedToNextQuestion 方法
  1492. proceedToNextQuestion() {
  1493. console.log("准备跳转到下一页面");
  1494. if (this.isPlayingAiVoice) {
  1495. console.log("AI语音正在播放,等待播放完成后再跳转");
  1496. return;
  1497. }
  1498. if (this.uploadQueue.length > 0) {
  1499. console.log("上传队列将在后台继续处理...");
  1500. this.saveUploadStatus();
  1501. }
  1502. },
  1503. // 修改 navigateToNextPage 方法
  1504. navigateToNextPage() {
  1505. console.log("执行页面跳转");
  1506. this.isPlayingAiVoice = false;
  1507. this.currentSubtitle = "";
  1508. setTimeout(() => {
  1509. common_vendor.index.reLaunch({
  1510. url: "/pages/success/success",
  1511. success: () => {
  1512. console.log("页面跳转成功");
  1513. },
  1514. fail: (err) => {
  1515. console.error("页面跳转失败:", err);
  1516. common_vendor.index.showToast({
  1517. title: "页面跳转失败",
  1518. icon: "none",
  1519. duration: 2e3
  1520. });
  1521. }
  1522. });
  1523. }, 100);
  1524. },
  1525. // 添加处理导航失败的方法
  1526. handleNavigationFailure() {
  1527. common_vendor.index.reLaunch({
  1528. url: "/pages/success/success",
  1529. //'/pages/posture-guide/posture-guide',
  1530. fail: (err2) => {
  1531. console.error("备用跳转也失败:", err2);
  1532. common_vendor.index.navigateBack({
  1533. delta: 1
  1534. });
  1535. }
  1536. });
  1537. },
  1538. // 修改 handleAnswerButtonClick 方法
  1539. handleAnswerButtonClick() {
  1540. this.showAnswerButton = false;
  1541. common_vendor.index.showToast({
  1542. title: "面试完成",
  1543. icon: "success",
  1544. duration: 500
  1545. // 只显示0.5秒
  1546. });
  1547. if (this.lastUploadedVideoUrl) {
  1548. this.submitToAiVoiceInteraction(this.lastUploadedVideoUrl);
  1549. } else {
  1550. this.navigateToNextPage();
  1551. }
  1552. },
  1553. // 处理相机错误
  1554. handleCameraError(e) {
  1555. console.error("相机错误:", e);
  1556. const systemInfo = common_vendor.index.getSystemInfoSync();
  1557. const isIOS = systemInfo.platform === "ios";
  1558. if (isIOS) {
  1559. console.log("iOS相机错误,尝试重新初始化");
  1560. common_vendor.index.showToast({
  1561. title: "相机初始化中...",
  1562. icon: "loading",
  1563. duration: 2e3
  1564. });
  1565. this.resetCamera();
  1566. if (this.isRecording) {
  1567. this.isRecording = false;
  1568. this.showStopRecordingButton = false;
  1569. setTimeout(() => {
  1570. this.useAlternativeRecordingMethod();
  1571. }, 1e3);
  1572. }
  1573. } else {
  1574. common_vendor.index.showToast({
  1575. title: "相机初始化失败,请检查权限设置",
  1576. icon: "none"
  1577. });
  1578. this.tryFallbackOptions();
  1579. }
  1580. },
  1581. // 添加新方法:尝试备用选项
  1582. tryFallbackOptions() {
  1583. const systemInfo = common_vendor.index.getSystemInfoSync();
  1584. if (systemInfo.uniPlatform === "mp-weixin" || systemInfo.uniPlatform === "mp-alipay") {
  1585. this.useMiniProgramCamera();
  1586. } else {
  1587. this.showStaticCameraPlaceholder();
  1588. }
  1589. },
  1590. // 添加新方法:使用小程序相机API
  1591. useMiniProgramCamera() {
  1592. console.log("尝试使用小程序相机组件");
  1593. this.useMiniProgramCameraComponent = true;
  1594. },
  1595. // 添加新方法:显示静态图像
  1596. showStaticCameraPlaceholder() {
  1597. console.log("显示静态摄像头占位图");
  1598. const img = document.createElement("img");
  1599. img.src = "/static/images/camera-placeholder.png";
  1600. img.className = "static-camera-image";
  1601. img.style.width = "100%";
  1602. img.style.height = "100%";
  1603. img.style.objectFit = "cover";
  1604. const container = this.$refs.userCameraVideo.parentNode;
  1605. container.appendChild(img);
  1606. },
  1607. // 处理视频时间更新事件
  1608. handleTimeUpdate(e) {
  1609. const currentTime = e.target.currentTime;
  1610. if (this.isRecording && this.recordingTimerCount) {
  1611. this.recordingTimeDisplay = this.formatTime(this.recordingTimerCount);
  1612. }
  1613. let currentSubtitles;
  1614. if (this.currentVideoIndex === 0) {
  1615. currentSubtitles = this.subtitles;
  1616. } else if (this.currentVideoIndex === 1) {
  1617. currentSubtitles = this.secondVideoSubtitles;
  1618. } else if (this.currentVideoIndex === 2) {
  1619. currentSubtitles = this.thirdVideoSubtitles;
  1620. } else if (this.currentVideoIndex === 3) {
  1621. currentSubtitles = this.fourthVideoSubtitles;
  1622. } else if (this.currentVideoIndex === 4) {
  1623. currentSubtitles = this.fifthVideoSubtitles;
  1624. } else if (this.currentVideoIndex === 5) {
  1625. currentSubtitles = this.sixthVideoSubtitles;
  1626. } else {
  1627. currentSubtitles = [];
  1628. }
  1629. const subtitle = currentSubtitles.find(
  1630. (sub) => currentTime >= sub.startTime && currentTime < sub.endTime
  1631. );
  1632. this.currentSubtitle = subtitle ? subtitle.text : "";
  1633. },
  1634. // Add a new method to handle the "Start Recording" button click
  1635. handleStartRecordingClick() {
  1636. this.showStartRecordingButton = false;
  1637. this.clearCountdown();
  1638. this.startRecordingAnswer();
  1639. },
  1640. // 修改 checkAudioPermission 方法,确保在录制前获取音频权限
  1641. checkAudioPermission() {
  1642. const systemInfo = common_vendor.index.getSystemInfoSync();
  1643. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
  1644. if (isMiniProgram) {
  1645. common_vendor.index.getSetting({
  1646. success: (res) => {
  1647. if (!res.authSetting["scope.record"]) {
  1648. common_vendor.index.authorize({
  1649. scope: "scope.record",
  1650. success: () => {
  1651. console.log("录音权限已获取");
  1652. },
  1653. fail: (err) => {
  1654. console.error("录音权限获取失败:", err);
  1655. this.showPermissionDialog("录音");
  1656. }
  1657. });
  1658. }
  1659. if (!res.authSetting["scope.camera"]) {
  1660. common_vendor.index.authorize({
  1661. scope: "scope.camera",
  1662. success: () => {
  1663. console.log("相机权限已获取");
  1664. },
  1665. fail: (err) => {
  1666. console.error("相机权限获取失败:", err);
  1667. this.showPermissionDialog("相机");
  1668. }
  1669. });
  1670. }
  1671. }
  1672. });
  1673. }
  1674. },
  1675. // 添加新方法:测试音频输入
  1676. testAudioInput() {
  1677. if (!this.cameraStream) {
  1678. console.warn("没有可用的媒体流,无法测试音频");
  1679. return;
  1680. }
  1681. const audioTracks = this.cameraStream.getAudioTracks();
  1682. if (audioTracks.length === 0) {
  1683. console.warn("没有检测到音频轨道,尝试重新获取");
  1684. this.tryGetAudioOnly();
  1685. return;
  1686. }
  1687. console.log("音频轨道信息:", audioTracks[0].getSettings());
  1688. try {
  1689. const AudioContext = window.AudioContext || window.webkitAudioContext;
  1690. if (!AudioContext) {
  1691. console.warn("浏览器不支持AudioContext");
  1692. return;
  1693. }
  1694. const audioContext = new AudioContext();
  1695. const analyser = audioContext.createAnalyser();
  1696. const microphone = audioContext.createMediaStreamSource(this.cameraStream);
  1697. microphone.connect(analyser);
  1698. analyser.fftSize = 256;
  1699. const bufferLength = analyser.frequencyBinCount;
  1700. const dataArray = new Uint8Array(bufferLength);
  1701. let silenceCounter = 0;
  1702. const checkAudio = () => {
  1703. if (this.isRecording)
  1704. return;
  1705. analyser.getByteFrequencyData(dataArray);
  1706. let sum = 0;
  1707. for (let i = 0; i < bufferLength; i++) {
  1708. sum += dataArray[i];
  1709. }
  1710. const average = sum / bufferLength;
  1711. if (average > 10) {
  1712. console.log("检测到音频输入,音量:", average);
  1713. silenceCounter = 0;
  1714. } else {
  1715. silenceCounter++;
  1716. if (silenceCounter > 10) {
  1717. console.warn("持续检测不到音频输入,可能麦克风未正常工作");
  1718. silenceCounter = 0;
  1719. }
  1720. }
  1721. requestAnimationFrame(checkAudio);
  1722. };
  1723. checkAudio();
  1724. } catch (e) {
  1725. console.error("音频测试失败:", e);
  1726. }
  1727. },
  1728. // 添加新方法:尝试单独获取音频
  1729. tryGetAudioOnly() {
  1730. navigator.mediaDevices.getUserMedia({ audio: true }).then((audioStream) => {
  1731. if (this.cameraStream) {
  1732. const videoTrack = this.cameraStream.getVideoTracks()[0];
  1733. const audioTrack = audioStream.getAudioTracks()[0];
  1734. const combinedStream = new MediaStream();
  1735. if (videoTrack)
  1736. combinedStream.addTrack(videoTrack);
  1737. if (audioTrack)
  1738. combinedStream.addTrack(audioTrack);
  1739. this.cameraStream = combinedStream;
  1740. const videoElement = this.$refs.userCameraVideo;
  1741. if (videoElement) {
  1742. videoElement.srcObject = combinedStream;
  1743. videoElement.muted = true;
  1744. }
  1745. console.log("成功合并音频和视频轨道");
  1746. } else {
  1747. console.warn("没有视频流可合并");
  1748. }
  1749. }).catch((err) => {
  1750. console.error("单独获取音频失败:", err);
  1751. });
  1752. },
  1753. // 添加新方法:显示权限对话框
  1754. showPermissionDialog(permissionType) {
  1755. common_vendor.index.showModal({
  1756. title: "需要权限",
  1757. content: `请允许使用${permissionType}权限,否则可能影响面试功能`,
  1758. confirmText: "去设置",
  1759. success: (res) => {
  1760. if (res.confirm) {
  1761. common_vendor.index.openSetting({
  1762. success: (settingRes) => {
  1763. console.log("设置页面打开成功", settingRes);
  1764. }
  1765. });
  1766. }
  1767. }
  1768. });
  1769. },
  1770. // 添加重试上传方法
  1771. retryVideoUpload() {
  1772. if (this.lastVideoToRetry) {
  1773. this.showRetryButton = false;
  1774. common_vendor.index.showLoading({
  1775. title: "正在重新提交...",
  1776. mask: true
  1777. });
  1778. this.submitVideoToInterview(this.lastVideoToRetry);
  1779. } else {
  1780. common_vendor.index.showToast({
  1781. title: "没有可重试的视频",
  1782. icon: "none"
  1783. });
  1784. }
  1785. },
  1786. // 添加一个新方法用于压缩视频
  1787. async compressVideo(videoBlob) {
  1788. if (videoBlob.size < 5 * 1024 * 1024) {
  1789. return videoBlob;
  1790. }
  1791. console.log("开始压缩视频,原始大小:", videoBlob.size);
  1792. const videoElement = document.createElement("video");
  1793. videoElement.muted = true;
  1794. videoElement.autoplay = false;
  1795. const canvas = document.createElement("canvas");
  1796. const ctx = canvas.getContext("2d");
  1797. videoElement.src = URL.createObjectURL(videoBlob);
  1798. return new Promise((resolve) => {
  1799. videoElement.onloadedmetadata = () => {
  1800. const width = Math.floor(videoElement.videoWidth / 2);
  1801. const height = Math.floor(videoElement.videoHeight / 2);
  1802. canvas.width = width;
  1803. canvas.height = height;
  1804. const stream = canvas.captureStream(15);
  1805. if (videoElement.captureStream) {
  1806. const originalStream = videoElement.captureStream();
  1807. const audioTracks = originalStream.getAudioTracks();
  1808. if (audioTracks.length > 0) {
  1809. stream.addTrack(audioTracks[0]);
  1810. }
  1811. }
  1812. const options = {
  1813. mimeType: "video/webm;codecs=vp8,opus",
  1814. audioBitsPerSecond: 64e3,
  1815. videoBitsPerSecond: 8e5
  1816. // 800kbps
  1817. };
  1818. const mediaRecorder = new MediaRecorder(stream, options);
  1819. const chunks = [];
  1820. mediaRecorder.ondataavailable = (e) => {
  1821. if (e.data.size > 0) {
  1822. chunks.push(e.data);
  1823. }
  1824. };
  1825. mediaRecorder.onstop = () => {
  1826. const compressedBlob = new Blob(chunks, { type: "video/webm" });
  1827. console.log("视频压缩完成,压缩后大小:", compressedBlob.size);
  1828. resolve(compressedBlob);
  1829. };
  1830. videoElement.onplay = () => {
  1831. mediaRecorder.start(100);
  1832. const drawFrame = () => {
  1833. if (videoElement.paused || videoElement.ended) {
  1834. mediaRecorder.stop();
  1835. return;
  1836. }
  1837. ctx.drawImage(videoElement, 0, 0, width, height);
  1838. requestAnimationFrame(drawFrame);
  1839. };
  1840. drawFrame();
  1841. };
  1842. videoElement.play();
  1843. };
  1844. });
  1845. },
  1846. // 修改 checkIOSCameraRecordPermission 方法
  1847. checkIOSCameraRecordPermission() {
  1848. const systemInfo = common_vendor.index.getSystemInfoSync();
  1849. if (systemInfo.platform !== "ios")
  1850. return;
  1851. common_vendor.index.getSetting({
  1852. success: (res) => {
  1853. if (!res.authSetting["scope.camera"]) {
  1854. common_vendor.index.authorize({
  1855. scope: "scope.camera",
  1856. success: () => {
  1857. console.log("iOS相机权限已获取");
  1858. },
  1859. fail: (err) => {
  1860. console.error("iOS相机权限获取失败:", err);
  1861. this.showPermissionDialog("相机");
  1862. }
  1863. });
  1864. }
  1865. if (!res.authSetting["scope.record"]) {
  1866. common_vendor.index.authorize({
  1867. scope: "scope.record",
  1868. success: () => {
  1869. console.log("iOS录音权限已获取");
  1870. },
  1871. fail: (err) => {
  1872. console.error("iOS录音权限获取失败:", err);
  1873. this.showPermissionDialog("录音");
  1874. }
  1875. });
  1876. }
  1877. }
  1878. });
  1879. },
  1880. // 添加新方法:检查并修复渲染问题
  1881. checkAndFixRenderingIssues() {
  1882. try {
  1883. if (typeof u !== "undefined" && u) {
  1884. if (!u.currentQuestion) {
  1885. console.log("修复: 创建缺失的currentQuestion对象");
  1886. u.currentQuestion = {};
  1887. }
  1888. if (u.currentQuestion && typeof u.currentQuestion.isImportant === "undefined") {
  1889. console.log("修复: 设置缺失的isImportant属性");
  1890. u.currentQuestion.isImportant = false;
  1891. }
  1892. }
  1893. } catch (e) {
  1894. console.log("防御性检查异常:", e);
  1895. }
  1896. },
  1897. // 添加格式化时间的辅助方法
  1898. formatTime(seconds) {
  1899. if (!seconds && seconds !== 0)
  1900. return "03:30";
  1901. const minutes = Math.floor(seconds / 60);
  1902. const remainingSeconds = seconds % 60;
  1903. return `${minutes.toString().padStart(2, "0")}:${remainingSeconds.toString().padStart(2, "0")}`;
  1904. },
  1905. // 添加新方法:保存上传状态到本地存储
  1906. saveUploadStatus() {
  1907. const uploadStatus = {
  1908. isUploading: this.isUploading,
  1909. uploadQueue: this.uploadQueue.length,
  1910. timestamp: Date.now()
  1911. };
  1912. try {
  1913. common_vendor.index.setStorageSync("videoUploadStatus", JSON.stringify(uploadStatus));
  1914. } catch (e) {
  1915. console.error("保存上传状态失败:", e);
  1916. }
  1917. },
  1918. // 修改 submitToAiVoiceInteraction 方法
  1919. submitToAiVoiceInteraction(videoUrl) {
  1920. console.log("提交视频到AI语音交互接口:", videoUrl);
  1921. common_vendor.index.showLoading({
  1922. title: "面试官正在思考...",
  1923. mask: true
  1924. });
  1925. const tenant_id = common_vendor.index.getStorageSync("tenant_id") || "1";
  1926. const application_id = common_vendor.index.getStorageSync("appId") || "98";
  1927. let positionConfigId = 1;
  1928. if (JSON.parse(common_vendor.index.getStorageSync("configData"))) {
  1929. positionConfigId = JSON.parse(common_vendor.index.getStorageSync("configData")).id;
  1930. }
  1931. const requestData = {
  1932. voice_url: videoUrl,
  1933. tenant_id,
  1934. application_id,
  1935. scene_type: "interview",
  1936. // 场景类型:面试
  1937. // voice_type: 'longxiaoxia', // 角色:龙小侠
  1938. position_config_id: positionConfigId,
  1939. conversation_history: this.conversationHistory
  1940. // 添加对话历史
  1941. };
  1942. const systemInfo = common_vendor.index.getSystemInfoSync();
  1943. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
  1944. if (isMiniProgram) {
  1945. common_vendor.index.request({
  1946. url: `${common_config.apiBaseUrl}/api/system/voice/mcp/interaction`,
  1947. // 使用新的接口地址
  1948. method: "POST",
  1949. data: requestData,
  1950. header: {
  1951. "content-type": "application/json"
  1952. // 修改为JSON格式
  1953. },
  1954. success: (res) => {
  1955. if (res.statusCode === 200) {
  1956. this.handleAiInteractionResponse(res.data);
  1957. } else {
  1958. this.handleAiInteractionError(res.data);
  1959. }
  1960. },
  1961. fail: (err) => {
  1962. this.handleAiInteractionError(err);
  1963. }
  1964. });
  1965. } else {
  1966. const xhr = new XMLHttpRequest();
  1967. xhr.open("POST", `${common_config.apiBaseUrl}/api/system/voice/mcp/interaction`, true);
  1968. xhr.timeout = 6e4;
  1969. xhr.setRequestHeader("Content-Type", "application/json");
  1970. xhr.onload = () => {
  1971. if (xhr.status === 200) {
  1972. try {
  1973. const response = JSON.parse(xhr.responseText);
  1974. this.handleAiInteractionResponse(response);
  1975. } catch (e) {
  1976. console.error("解析AI响应失败:", e);
  1977. this.handleAiInteractionError({ errMsg: "解析响应失败" });
  1978. }
  1979. } else {
  1980. this.handleAiInteractionError({ errMsg: "HTTP状态: " + xhr.status });
  1981. }
  1982. };
  1983. xhr.onerror = () => {
  1984. this.handleAiInteractionError({ errMsg: "网络错误" });
  1985. };
  1986. xhr.ontimeout = () => {
  1987. this.handleAiInteractionError({ errMsg: "请求超时" });
  1988. };
  1989. xhr.send(JSON.stringify(requestData));
  1990. }
  1991. },
  1992. // 添加处理AI交互响应的方法
  1993. handleAiInteractionResponse(data) {
  1994. console.log("AI语音交互接口响应:", data);
  1995. const systemInfo = common_vendor.index.getSystemInfoSync();
  1996. const isIOS = systemInfo.platform === "ios";
  1997. this.isPlayingAiVoice = true;
  1998. common_vendor.index.hideLoading();
  1999. this.hasTriedFallbackMethod = false;
  2000. if (data && data.success) {
  2001. this.aiText = data.ai_text || "";
  2002. this.transcribedText = data.transcribed_text ? data.transcribed_text.text : "";
  2003. this.conversationHistory.push({
  2004. role: "user",
  2005. content: this.transcribedText
  2006. });
  2007. this.conversationHistory.push({
  2008. role: "assistant",
  2009. content: this.aiText
  2010. });
  2011. const aiVoiceUrl = data.ai_voice_url || "";
  2012. if (aiVoiceUrl) {
  2013. this.aiVoiceUrl = aiVoiceUrl.startsWith("http") ? aiVoiceUrl : `${common_config.apiBaseUrl}${aiVoiceUrl}`;
  2014. console.log("AI语音URL:", this.aiVoiceUrl);
  2015. this.currentSubtitle = this.aiText;
  2016. const systemInfo2 = common_vendor.index.getSystemInfoSync();
  2017. const isMiniProgram = systemInfo2.uniPlatform && systemInfo2.uniPlatform.startsWith("mp-");
  2018. const isUnsupportedFormat = this.checkUnsupportedAudioFormat(this.aiVoiceUrl);
  2019. if (isUnsupportedFormat && isMiniProgram) {
  2020. console.warn("检测到小程序不支持的音频格式,直接使用文本显示");
  2021. this.displayTextResponse();
  2022. return;
  2023. }
  2024. if (isMiniProgram) {
  2025. if (isIOS) {
  2026. this.playIOSMiniProgramAudio();
  2027. } else {
  2028. this.playMiniProgramAudio();
  2029. }
  2030. } else {
  2031. this.playAiVoice();
  2032. }
  2033. this.showContinueQuestionButton = false;
  2034. this.showEndInterviewButton = false;
  2035. } else {
  2036. console.warn("未获取到AI语音URL,使用文本显示");
  2037. this.displayTextResponse();
  2038. }
  2039. } else {
  2040. console.error("AI语音交互失败:", data);
  2041. this.showContinueQuestionOptions();
  2042. this.checkPendingNavigation();
  2043. }
  2044. },
  2045. // 修改 handleAiInteractionError 方法,不要直接跳转,而是显示继续提问选项
  2046. handleAiInteractionError(err) {
  2047. console.error("AI语音交互请求失败:", err);
  2048. common_vendor.index.hideLoading();
  2049. common_vendor.index.showToast({
  2050. title: "AI处理失败,请重试",
  2051. icon: "none",
  2052. duration: 2e3
  2053. });
  2054. this.showContinueQuestionOptions();
  2055. },
  2056. // 添加新方法:播放AI语音
  2057. async playAiVoice() {
  2058. console.log("开始播放AI语音:", this.aiVoiceUrl);
  2059. this.resetAudioState();
  2060. this.isPlayingAiVoice = true;
  2061. this.showContinueQuestionButton = false;
  2062. this.showEndInterviewButton = false;
  2063. this.currentSubtitle = this.aiText;
  2064. if (!this.aiVoiceUrl || this.aiVoiceUrl.trim() === "") {
  2065. console.error("无效的音频URL,直接显示文本");
  2066. this.useTextFallbackAndNavigate();
  2067. return;
  2068. }
  2069. try {
  2070. const systemInfo = common_vendor.index.getSystemInfoSync();
  2071. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
  2072. const isIOS = systemInfo.platform === "ios";
  2073. this.audioPlaybackTimer = setTimeout(() => {
  2074. console.log("音频播放超时,使用备选方案");
  2075. if (this.isPlayingAiVoice) {
  2076. this.handlePlaybackTimeout();
  2077. }
  2078. }, 3e4);
  2079. if (isMiniProgram) {
  2080. if (isIOS) {
  2081. await this.playIOSMiniProgramAudio();
  2082. } else {
  2083. await this.playMiniProgramAudio();
  2084. }
  2085. } else if (isIOS) {
  2086. await this.playAiVoiceForIOS();
  2087. } else {
  2088. await this.playAiVoiceForAndroid();
  2089. }
  2090. this.pendingAutoNavigation = true;
  2091. } catch (error) {
  2092. console.error("音频播放失败:", error);
  2093. this.handlePlaybackError(error);
  2094. }
  2095. },
  2096. // 添加新方法:处理播放超时
  2097. handlePlaybackTimeout() {
  2098. console.log("处理音频播放超时");
  2099. this.resetAudioState();
  2100. common_vendor.index.showToast({
  2101. title: "音频播放超时,将显示文字回复",
  2102. icon: "none",
  2103. duration: 2e3
  2104. });
  2105. this.useTextFallbackAndNavigate();
  2106. },
  2107. // 添加新方法:处理播放错误
  2108. handlePlaybackError(error) {
  2109. console.error("处理音频播放错误:", error);
  2110. this.resetAudioState();
  2111. const isIOS = common_vendor.index.getSystemInfoSync().platform === "ios";
  2112. if (isIOS && !this.hasTriedFallbackMethod) {
  2113. this.hasTriedFallbackMethod = true;
  2114. console.log("iOS设备尝试使用备选播放方法");
  2115. this.fallbackIOSAudioPlay();
  2116. return;
  2117. }
  2118. common_vendor.index.showToast({
  2119. title: "音频播放失败,将显示文字回复",
  2120. icon: "none",
  2121. duration: 2e3
  2122. });
  2123. this.useTextFallbackAndNavigate();
  2124. },
  2125. // 新增方法:文本回退并导航
  2126. useTextFallbackAndNavigate() {
  2127. console.log("使用文本回退并准备导航");
  2128. this.isPlayingAiVoice = false;
  2129. if (!this.hasShownTextFallbackToast) {
  2130. this.hasShownTextFallbackToast = true;
  2131. common_vendor.index.showToast({
  2132. title: "为您显示文字回复",
  2133. icon: "none",
  2134. duration: 2e3
  2135. });
  2136. }
  2137. this.currentSubtitle = this.aiText || "抱歉,AI回复内容加载失败";
  2138. setTimeout(() => {
  2139. this.navigateToNextPage();
  2140. }, 5e3);
  2141. },
  2142. // 修改 handleIOSAudioPlaybackComplete 方法
  2143. handleIOSAudioPlaybackComplete() {
  2144. this.isPlayingAiVoice = false;
  2145. setTimeout(() => {
  2146. this.currentSubtitle = "";
  2147. }, 1e3);
  2148. if (this.aiAudioPlayer) {
  2149. try {
  2150. this.aiAudioPlayer.destroy();
  2151. } catch (e) {
  2152. console.error("销毁iOS音频播放器失败:", e);
  2153. }
  2154. this.aiAudioPlayer = null;
  2155. }
  2156. this.navigateToNextPage();
  2157. },
  2158. // 修改 playMiniProgramAudio 方法
  2159. playMiniProgramAudio() {
  2160. return new Promise(async (resolve, reject) => {
  2161. try {
  2162. common_vendor.index.showLoading({
  2163. title: "音频加载中...",
  2164. mask: true
  2165. });
  2166. const localAudioPath = await this.preloadAudio(this.aiVoiceUrl);
  2167. common_vendor.index.hideLoading();
  2168. const audioContext = common_vendor.wx$1.createInnerAudioContext();
  2169. audioContext.src = localAudioPath;
  2170. audioContext.autoplay = true;
  2171. audioContext.bufferSize = 4096;
  2172. let hasStarted = false;
  2173. let hasError = false;
  2174. audioContext.onPlay(() => {
  2175. console.log("AI语音开始播放");
  2176. hasStarted = true;
  2177. this.currentSubtitle = this.aiText;
  2178. });
  2179. audioContext.onEnded(() => {
  2180. console.log("AI语音播放结束");
  2181. this.isPlayingAiVoice = false;
  2182. this.currentSubtitle = "";
  2183. audioContext.destroy();
  2184. if (!hasError) {
  2185. console.log("准备跳转到下一页");
  2186. this.navigateToNextPage();
  2187. resolve();
  2188. }
  2189. });
  2190. audioContext.onStop(() => {
  2191. console.log("AI语音播放停止");
  2192. this.isPlayingAiVoice = false;
  2193. this.currentSubtitle = "";
  2194. audioContext.destroy();
  2195. if (!hasError) {
  2196. console.log("播放停止,准备跳转到下一页");
  2197. this.navigateToNextPage();
  2198. resolve();
  2199. }
  2200. });
  2201. audioContext.onError((err) => {
  2202. hasError = true;
  2203. console.error("AI语音播放错误:", err);
  2204. audioContext.destroy();
  2205. common_vendor.index.showToast({
  2206. title: "音频播放异常,将显示文字",
  2207. icon: "none",
  2208. duration: 2e3
  2209. });
  2210. if (this.aiVoiceUrl.endsWith(".mp3")) {
  2211. const wavUrl = this.aiVoiceUrl.replace(".mp3", ".wav");
  2212. console.log("尝试使用WAV格式:", wavUrl);
  2213. this.aiVoiceUrl = wavUrl;
  2214. this.playMiniProgramAudio().then(resolve).catch(reject);
  2215. } else {
  2216. reject(err);
  2217. }
  2218. });
  2219. setTimeout(() => {
  2220. if (!hasStarted && !hasError) {
  2221. console.error("音频播放启动超时");
  2222. audioContext.destroy();
  2223. reject(new Error("音频播放启动超时"));
  2224. }
  2225. }, 5e3);
  2226. } catch (error) {
  2227. common_vendor.index.hideLoading();
  2228. console.error("音频播放初始化失败:", error);
  2229. reject(error);
  2230. }
  2231. });
  2232. },
  2233. // 新增方法:导航到下一页
  2234. navigateToNextPage() {
  2235. console.log("执行页面跳转");
  2236. this.isPlayingAiVoice = false;
  2237. this.currentSubtitle = "";
  2238. setTimeout(() => {
  2239. common_vendor.index.reLaunch({
  2240. url: "/pages/success/success",
  2241. success: () => {
  2242. console.log("页面跳转成功");
  2243. },
  2244. fail: (err) => {
  2245. console.error("页面跳转失败:", err);
  2246. common_vendor.index.showToast({
  2247. title: "页面跳转失败",
  2248. icon: "none",
  2249. duration: 2e3
  2250. });
  2251. }
  2252. });
  2253. }, 100);
  2254. },
  2255. // 新增方法:专门处理iOS小程序音频播放
  2256. playIOSMiniProgramAudio() {
  2257. return new Promise((resolve, reject) => {
  2258. try {
  2259. const bgAudio = common_vendor.index.getBackgroundAudioManager();
  2260. bgAudio.title = "语音播报";
  2261. bgAudio.epname = "AI Voice";
  2262. bgAudio.singer = "Assistant";
  2263. bgAudio.onCanplay(() => {
  2264. try {
  2265. bgAudio.play();
  2266. } catch (e) {
  2267. console.warn("调用 play 失败,稍后重试", e);
  2268. setTimeout(() => {
  2269. try {
  2270. bgAudio.play();
  2271. } catch (_) {
  2272. }
  2273. }, 50);
  2274. }
  2275. });
  2276. bgAudio.onPlay(() => {
  2277. console.log("iOS小程序音频开始播放");
  2278. });
  2279. bgAudio.onEnded(() => {
  2280. console.log("iOS小程序音频播放完成");
  2281. try {
  2282. bgAudio.stop();
  2283. } catch (_) {
  2284. }
  2285. this.navigateToNextPage();
  2286. resolve();
  2287. });
  2288. bgAudio.onError((err) => {
  2289. console.error("iOS小程序音频播放错误:", err);
  2290. try {
  2291. bgAudio.stop();
  2292. } catch (_) {
  2293. }
  2294. reject(err);
  2295. });
  2296. bgAudio.autoplay = true;
  2297. bgAudio.src = this.aiVoiceUrl;
  2298. } catch (error) {
  2299. reject(error);
  2300. }
  2301. });
  2302. },
  2303. playAiVoiceForIOS() {
  2304. return new Promise((resolve, reject) => {
  2305. try {
  2306. const audioContext = new Audio();
  2307. audioContext.src = this.aiVoiceUrl;
  2308. audioContext.autoplay = true;
  2309. audioContext.addEventListener("play", () => {
  2310. console.log("iOS音频开始播放");
  2311. });
  2312. audioContext.addEventListener("ended", () => {
  2313. console.log("iOS音频播放完成");
  2314. resolve();
  2315. });
  2316. audioContext.addEventListener("error", (err) => {
  2317. console.error("iOS音频播放错误:", err);
  2318. reject(err);
  2319. });
  2320. } catch (error) {
  2321. reject(error);
  2322. }
  2323. });
  2324. },
  2325. playAiVoiceForAndroid() {
  2326. return new Promise((resolve, reject) => {
  2327. try {
  2328. const audioContext = new Audio();
  2329. audioContext.src = this.aiVoiceUrl;
  2330. audioContext.autoplay = true;
  2331. audioContext.addEventListener("play", () => {
  2332. console.log("Android音频开始播放");
  2333. });
  2334. audioContext.addEventListener("ended", () => {
  2335. console.log("Android音频播放完成");
  2336. resolve();
  2337. });
  2338. audioContext.addEventListener("error", (err) => {
  2339. console.error("Android音频播放错误:", err);
  2340. reject(err);
  2341. });
  2342. } catch (error) {
  2343. reject(error);
  2344. }
  2345. });
  2346. },
  2347. // 新增方法:iOS小程序音频预下载
  2348. preloadIOSMiniProgramAudio(audioUrl) {
  2349. return new Promise((resolve, reject) => {
  2350. console.log("开始预下载iOS小程序音频:", audioUrl);
  2351. common_vendor.index.downloadFile({
  2352. url: audioUrl,
  2353. timeout: 15e3,
  2354. // 15秒超时
  2355. success: (res) => {
  2356. if (res.statusCode === 200) {
  2357. console.log("iOS小程序音频下载成功:", res.tempFilePath);
  2358. resolve(res.tempFilePath);
  2359. } else {
  2360. console.error("iOS小程序音频下载失败,状态码:", res.statusCode);
  2361. reject(new Error(`下载失败,状态码: ${res.statusCode}`));
  2362. }
  2363. },
  2364. fail: (err) => {
  2365. console.error("iOS小程序音频下载请求失败:", err);
  2366. reject(err);
  2367. }
  2368. });
  2369. });
  2370. },
  2371. // 新增方法:iOS小程序错误处理
  2372. handleIOSMiniProgramError(audioContext, error) {
  2373. console.error("处理iOS小程序音频错误:", error);
  2374. if (audioContext) {
  2375. try {
  2376. audioContext.destroy();
  2377. } catch (e) {
  2378. console.error("销毁音频播放器失败:", e);
  2379. }
  2380. }
  2381. let errorMessage = "音频播放异常,显示文字";
  2382. if (error.errMsg && error.errMsg.includes("-11850")) {
  2383. console.log("iOS小程序检测到系统音频错误(-11850)");
  2384. errorMessage = "系统音频服务暂停,显示文字";
  2385. } else if (error.errCode === 10002) {
  2386. console.log("iOS小程序检测到errCode:10002,网络或资源问题");
  2387. errorMessage = "音频加载中断,显示文字";
  2388. } else if (error.errCode === 10001) {
  2389. console.log("iOS小程序检测到errCode:10001,系统错误");
  2390. errorMessage = "系统音频错误,显示文字";
  2391. } else if (error.errCode === 10003) {
  2392. console.log("iOS小程序检测到errCode:10003,文件错误");
  2393. errorMessage = "音频文件错误,显示文字";
  2394. } else if (error.errCode === 10004) {
  2395. console.log("iOS小程序检测到errCode:10004,格式不支持");
  2396. errorMessage = "音频格式不支持,显示文字";
  2397. }
  2398. common_vendor.index.showToast({
  2399. title: errorMessage,
  2400. icon: "none",
  2401. duration: 2e3
  2402. });
  2403. this.useIOSTextFallback();
  2404. },
  2405. // 新增方法:iOS小程序播放超时处理
  2406. handleIOSPlaybackTimeout(audioContext) {
  2407. console.log("iOS小程序音频播放超时处理");
  2408. if (audioContext) {
  2409. try {
  2410. audioContext.destroy();
  2411. } catch (e) {
  2412. console.error("销毁超时音频播放器失败:", e);
  2413. }
  2414. }
  2415. this.useIOSTextFallback();
  2416. },
  2417. // 新增方法:iOS小程序备选播放方法
  2418. fallbackIOSMiniProgramPlay(audioContext) {
  2419. console.log("iOS小程序使用备选播放方法");
  2420. try {
  2421. audioContext.src = this.aiVoiceUrl;
  2422. const fallbackTimeout = setTimeout(() => {
  2423. if (this.isPlayingAiVoice) {
  2424. console.log("iOS小程序备选方法也超时");
  2425. clearTimeout(fallbackTimeout);
  2426. this.handleIOSPlaybackTimeout(audioContext);
  2427. }
  2428. }, 3e3);
  2429. audioContext.play();
  2430. } catch (e) {
  2431. console.error("iOS小程序备选播放方法失败:", e);
  2432. this.handleIOSPlaybackTimeout(audioContext);
  2433. }
  2434. },
  2435. // 新增方法:统一的iOS音频完成处理
  2436. handleIOSAudioComplete(audioContext) {
  2437. console.log("iOS音频播放完成");
  2438. this.isPlayingAiVoice = false;
  2439. setTimeout(() => {
  2440. this.currentSubtitle = "";
  2441. }, 2e3);
  2442. if (audioContext) {
  2443. try {
  2444. audioContext.destroy();
  2445. } catch (e) {
  2446. console.error("销毁iOS音频播放器失败:", e);
  2447. }
  2448. }
  2449. this.showContinueQuestionOptions();
  2450. this.checkPendingNavigation();
  2451. },
  2452. // 移除原来的 playMiniProgramAudioForIOS 方法,因为已经被新的 playIOSMiniProgramAudio 替代
  2453. // playMiniProgramAudioForIOS() 方法可以删除或注释掉
  2454. // 保留原有的 useIOSTextFallback 方法,但确保它能正确处理所有iOS场景
  2455. useIOSTextFallback() {
  2456. console.log("iOS使用文本回退方案");
  2457. this.isPlayingAiVoice = false;
  2458. if (!this.hasShownTextFallbackToast) {
  2459. this.hasShownTextFallbackToast = true;
  2460. }
  2461. this.currentSubtitle = this.aiText || "抱歉,AI回复内容加载失败";
  2462. this.showNextButton = true;
  2463. },
  2464. // 添加处理继续按钮点击的方法
  2465. handleNextButtonClick() {
  2466. this.showNextButton = false;
  2467. this.handleIOSAudioComplete(null);
  2468. },
  2469. // 添加新方法:iOS音频播放完成处理
  2470. handleIOSAudioPlaybackComplete() {
  2471. console.log("iOS音频播放完成");
  2472. this.isPlayingAiVoice = false;
  2473. common_vendor.index.hideLoading();
  2474. setTimeout(() => {
  2475. this.currentSubtitle = "";
  2476. }, 2e3);
  2477. if (this.aiAudioPlayer) {
  2478. try {
  2479. this.aiAudioPlayer.destroy();
  2480. } catch (e) {
  2481. console.error("销毁iOS音频播放器失败:", e);
  2482. }
  2483. this.aiAudioPlayer = null;
  2484. }
  2485. this.resetAudioState();
  2486. if (this.pendingAutoNavigation) {
  2487. console.log("执行待处理的自动跳转");
  2488. this.navigateToNextPage();
  2489. } else {
  2490. this.showContinueQuestionOptions();
  2491. }
  2492. },
  2493. // 添加新方法:重置音频状态
  2494. resetAudioState() {
  2495. this.isPlayingAiVoice = false;
  2496. this.hasTriedFallbackMethod = false;
  2497. this.hasShownTextFallbackToast = false;
  2498. if (this.aiAudioPlayer) {
  2499. try {
  2500. this.aiAudioPlayer.destroy();
  2501. } catch (e) {
  2502. console.error("销毁音频播放器失败:", e);
  2503. }
  2504. this.aiAudioPlayer = null;
  2505. }
  2506. if (this.audioPlaybackTimer) {
  2507. clearTimeout(this.audioPlaybackTimer);
  2508. this.audioPlaybackTimer = null;
  2509. }
  2510. },
  2511. // 添加新方法:iOS音频错误处理
  2512. handleIOSAudioError(error) {
  2513. console.error("iOS音频播放错误:", error);
  2514. switch (error.errCode) {
  2515. case 10001:
  2516. console.log("iOS音频系统错误,尝试重新播放");
  2517. this.retryIOSAudioPlay();
  2518. break;
  2519. case 10002:
  2520. console.log("iOS音频网络错误,使用备选方案");
  2521. this.handleIOS10002Error();
  2522. break;
  2523. case 10003:
  2524. console.log("iOS音频文件错误,使用文本回退");
  2525. this.useIOSTextFallback();
  2526. break;
  2527. case 10004:
  2528. console.log("iOS音频格式不支持,使用文本回退");
  2529. this.useIOSTextFallback();
  2530. break;
  2531. default:
  2532. console.log("iOS音频未知错误,使用文本回退");
  2533. this.useIOSTextFallback();
  2534. break;
  2535. }
  2536. },
  2537. // 添加新方法:重试iOS音频播放
  2538. retryIOSAudioPlay() {
  2539. console.log("重试iOS音频播放");
  2540. if (this.aiAudioPlayer) {
  2541. try {
  2542. this.aiAudioPlayer.destroy();
  2543. } catch (e) {
  2544. console.error("销毁播放器失败:", e);
  2545. }
  2546. this.aiAudioPlayer = null;
  2547. }
  2548. setTimeout(() => {
  2549. this.fallbackIOSAudioPlay();
  2550. }, 1e3);
  2551. },
  2552. // 添加新方法:iOS专用音频播放
  2553. async playAiVoiceForIOS() {
  2554. console.log("使用iOS专用音频播放方法");
  2555. return new Promise((resolve, reject) => {
  2556. try {
  2557. this.aiAudioPlayer = common_vendor.index.createInnerAudioContext();
  2558. this.aiAudioPlayer.autoplay = true;
  2559. this.aiAudioPlayer.obeyMuteSwitch = false;
  2560. this.aiAudioPlayer.volume = 1;
  2561. this.aiAudioPlayer.src = this.aiVoiceUrl;
  2562. this.aiAudioPlayer.onPlay(() => {
  2563. console.log("iOS音频开始播放");
  2564. this.currentSubtitle = this.aiText;
  2565. });
  2566. this.aiAudioPlayer.onEnded(() => {
  2567. console.log("iOS音频播放完成");
  2568. this.handleIOSAudioPlaybackComplete();
  2569. resolve();
  2570. });
  2571. this.aiAudioPlayer.onError((err) => {
  2572. console.error("iOS音频播放错误:", err);
  2573. reject(err);
  2574. });
  2575. this.aiAudioPlayer.onWaiting(() => {
  2576. console.log("iOS音频加载中...");
  2577. });
  2578. this.aiAudioPlayer.onCanplay(() => {
  2579. console.log("iOS音频准备就绪");
  2580. });
  2581. } catch (error) {
  2582. console.error("创建iOS音频播放器失败:", error);
  2583. reject(error);
  2584. }
  2585. });
  2586. },
  2587. // 添加新方法:iOS备选音频播放
  2588. fallbackIOSAudioPlay() {
  2589. console.log("iOS备选音频播放方案");
  2590. try {
  2591. this.aiAudioPlayer = common_vendor.index.createInnerAudioContext();
  2592. this.aiAudioPlayer.autoplay = true;
  2593. this.aiAudioPlayer.obeyMuteSwitch = true;
  2594. this.aiAudioPlayer.volume = 0.8;
  2595. this.aiAudioPlayer.src = this.aiVoiceUrl;
  2596. this.aiAudioPlayer.onPlay(() => {
  2597. console.log("iOS备选方案:音频开始播放");
  2598. this.currentSubtitle = this.aiText;
  2599. });
  2600. this.aiAudioPlayer.onEnded(() => {
  2601. console.log("iOS备选方案:音频播放结束");
  2602. this.handleIOSAudioPlaybackComplete();
  2603. });
  2604. this.aiAudioPlayer.onError((err) => {
  2605. console.error("iOS备选方案:音频播放错误:", err);
  2606. this.useIOSTextFallback();
  2607. });
  2608. setTimeout(() => {
  2609. if (this.isPlayingAiVoice && this.aiAudioPlayer) {
  2610. console.log("iOS音频播放超时,使用文本回退");
  2611. this.useIOSTextFallback();
  2612. }
  2613. }, 5e3);
  2614. } catch (e) {
  2615. console.error("iOS备选音频播放失败:", e);
  2616. this.useIOSTextFallback();
  2617. }
  2618. },
  2619. // 修改 playMiniProgramAudio 方法,添加iOS特殊处理
  2620. /* playMiniProgramAudio() {
  2621. console.log('使用小程序原生音频API播放:', this.aiVoiceUrl);
  2622. // 标记正在播放AI语音
  2623. this.isPlayingAiVoice = true;
  2624. // 确保在播放期间不显示继续提问按钮
  2625. this.showContinueQuestionButton = false;
  2626. this.showEndInterviewButton = false;
  2627. // 检查音频URL是否有效
  2628. if (!this.aiVoiceUrl || this.aiVoiceUrl.trim() === '') {
  2629. console.error('无效的音频URL');
  2630. this.handleAudioPlaybackFailure();
  2631. return;
  2632. }
  2633. // 检查平台
  2634. const systemInfo = uni.getSystemInfoSync();
  2635. const isIOS = systemInfo.platform === 'ios';
  2636. // iOS小程序特殊处理
  2637. if (isIOS) {
  2638. this.playMiniProgramAudioForIOS();
  2639. return;
  2640. }
  2641. // 非iOS平台的原有逻辑
  2642. try {
  2643. // 使用wx.createInnerAudioContext API (微信小程序)
  2644. const audioContext = wx.createInnerAudioContext();
  2645. // 设置音频属性
  2646. audioContext.autoplay = false;
  2647. audioContext.obeyMuteSwitch = false; // 忽略静音开关
  2648. // 监听播放开始事件
  2649. audioContext.onPlay(() => {
  2650. console.log('AI语音开始播放');
  2651. // 显示正在播放提示
  2652. });
  2653. // 监听播放结束事件
  2654. audioContext.onEnded(() => {
  2655. console.log('AI语音播放结束');
  2656. // 标记播放结束
  2657. this.isPlayingAiVoice = false;
  2658. // 清空字幕
  2659. this.currentSubtitle = '';
  2660. // 销毁音频播放器
  2661. audioContext.destroy();
  2662. // 播放结束后显示继续提问选项,而不是直接跳转
  2663. this.showContinueQuestionOptions();
  2664. });
  2665. // 监听播放错误事件
  2666. audioContext.onError((err) => {
  2667. console.error('AI语音播放错误:', err);
  2668. // 标记播放结束
  2669. this.isPlayingAiVoice = false;
  2670. // 清空字幕
  2671. this.currentSubtitle = '';
  2672. // 销毁音频播放器
  2673. audioContext.destroy();
  2674. // 播放错误时也显示继续提问选项
  2675. this.showContinueQuestionOptions();
  2676. });
  2677. // 设置音频源
  2678. audioContext.src = this.aiVoiceUrl;
  2679. // 添加超时处理,如果5秒内没有开始播放,则认为出错
  2680. const playTimeout = setTimeout(() => {
  2681. if (this.isPlayingAiVoice) {
  2682. console.warn('小程序音频播放超时,尝试备选方法');
  2683. this.tryMiniProgramFallbackAudioPlay();
  2684. }
  2685. }, 5000);
  2686. // 延迟一小段时间再播放,确保src已经设置完成
  2687. setTimeout(() => {
  2688. audioContext.play();
  2689. // 播放开始后清除超时
  2690. clearTimeout(playTimeout);
  2691. }, 300);
  2692. } catch (e) {
  2693. console.error('小程序播放AI语音时发生错误:', e);
  2694. // 标记播放结束
  2695. this.isPlayingAiVoice = false;
  2696. // 显示错误提示
  2697. // 使用文本显示方式作为备选方案
  2698. this.handleAudioPlaybackFailure();
  2699. }
  2700. }, */
  2701. // 添加新方法:iOS小程序音频播放
  2702. playMiniProgramAudioForIOS() {
  2703. console.log("iOS小程序环境:开始播放AI语音");
  2704. this.hasShownTextFallbackToast = false;
  2705. try {
  2706. const audioContext = common_vendor.wx$1.createInnerAudioContext();
  2707. audioContext.autoplay = false;
  2708. audioContext.obeyMuteSwitch = true;
  2709. audioContext.volume = 1;
  2710. audioContext.onError((err) => {
  2711. console.error("iOS小程序音频播放错误:", err);
  2712. if (err.errMsg && err.errMsg.includes("-11850")) {
  2713. console.log("iOS小程序检测到系统音频错误(-11850)");
  2714. } else if (err.errCode === 10002) {
  2715. console.log("iOS小程序检测到errCode:10002,网络或资源问题");
  2716. } else {
  2717. console.log("iOS小程序其他音频错误:", err.errCode);
  2718. }
  2719. this.useIOSMiniProgramTextFallback(audioContext);
  2720. });
  2721. audioContext.src = this.aiVoiceUrl;
  2722. audioContext.onPlay(() => {
  2723. console.log("iOS小程序音频开始播放");
  2724. this.currentSubtitle = this.aiText;
  2725. });
  2726. audioContext.onEnded(() => {
  2727. console.log("iOS小程序音频播放结束");
  2728. this.handleIOSMiniProgramAudioComplete(audioContext);
  2729. });
  2730. const playTimeout = setTimeout(() => {
  2731. if (this.isPlayingAiVoice) {
  2732. console.log("iOS小程序音频播放超时,切换到文本显示");
  2733. clearTimeout(playTimeout);
  2734. this.useIOSMiniProgramTextFallback(audioContext);
  2735. }
  2736. }, 3e3);
  2737. audioContext.play();
  2738. } catch (e) {
  2739. console.error("iOS小程序音频播放初始化失败:", e);
  2740. this.handleAudioPlaybackFailure();
  2741. }
  2742. },
  2743. // 添加新方法:iOS小程序音频播放完成
  2744. handleIOSMiniProgramAudioComplete(audioContext) {
  2745. this.isPlayingAiVoice = false;
  2746. setTimeout(() => {
  2747. this.currentSubtitle = "";
  2748. }, 2e3);
  2749. if (audioContext) {
  2750. try {
  2751. audioContext.destroy();
  2752. } catch (e) {
  2753. console.error("销毁iOS小程序音频播放器失败:", e);
  2754. }
  2755. }
  2756. this.showContinueQuestionOptions();
  2757. this.checkPendingNavigation();
  2758. },
  2759. // 添加新方法:iOS小程序音频错误处理
  2760. handleIOSMiniProgramAudioError(audioContext, error) {
  2761. console.error("iOS小程序音频错误:", error);
  2762. if (error.errCode === 10002) {
  2763. this.useIOSMiniProgramTextFallback(audioContext);
  2764. } else {
  2765. this.useIOSMiniProgramTextFallback(audioContext);
  2766. }
  2767. },
  2768. // 添加新方法:iOS小程序文本回退
  2769. useIOSMiniProgramTextFallback(audioContext) {
  2770. console.log("iOS小程序使用文本回退方案");
  2771. if (audioContext) {
  2772. try {
  2773. audioContext.destroy();
  2774. } catch (e) {
  2775. console.error("销毁音频播放器失败:", e);
  2776. }
  2777. }
  2778. this.isPlayingAiVoice = false;
  2779. this.currentSubtitle = this.aiText || "抱歉,AI回复内容加载失败";
  2780. const textLength = this.aiText ? this.aiText.length : 20;
  2781. const readingTime = Math.max(6e3, Math.min(textLength * 120, 18e3));
  2782. setTimeout(() => {
  2783. this.handleIOSMiniProgramAudioComplete(null);
  2784. }, readingTime);
  2785. },
  2786. // 添加新方法:处理音频播放错误
  2787. handleAudioPlaybackError(error) {
  2788. console.error("音频播放错误:", error);
  2789. if (!this.hasTriedFallbackMethod) {
  2790. this.hasTriedFallbackMethod = true;
  2791. this.tryFallbackAudioPlay();
  2792. return;
  2793. }
  2794. this.handleAudioPlaybackFailure();
  2795. },
  2796. // 添加新方法:尝试备选音频播放方法
  2797. tryFallbackAudioPlay() {
  2798. console.log("使用备选方法播放音频:", this.aiVoiceUrl);
  2799. if (this.aiAudioPlayer) {
  2800. try {
  2801. this.aiAudioPlayer.destroy();
  2802. } catch (e) {
  2803. console.error("销毁音频播放器失败:", e);
  2804. }
  2805. this.aiAudioPlayer = null;
  2806. }
  2807. common_vendor.index.downloadFile({
  2808. url: this.aiVoiceUrl,
  2809. success: (res) => {
  2810. if (res.statusCode === 200) {
  2811. console.log("音频文件下载成功:", res.tempFilePath);
  2812. const newAudioPlayer = common_vendor.index.createInnerAudioContext();
  2813. this.aiAudioPlayer = newAudioPlayer;
  2814. newAudioPlayer.autoplay = true;
  2815. newAudioPlayer.src = res.tempFilePath;
  2816. newAudioPlayer.onPlay(() => {
  2817. console.log("备选方法:音频开始播放");
  2818. });
  2819. newAudioPlayer.onEnded(() => {
  2820. console.log("备选方法:音频播放结束");
  2821. this.isPlayingAiVoice = false;
  2822. this.currentSubtitle = "";
  2823. newAudioPlayer.destroy();
  2824. this.aiAudioPlayer = null;
  2825. this.showContinueQuestionOptions();
  2826. this.checkPendingNavigation();
  2827. });
  2828. newAudioPlayer.onError((err) => {
  2829. console.error("备选方法:音频播放错误:", err);
  2830. this.isPlayingAiVoice = false;
  2831. this.currentSubtitle = "";
  2832. newAudioPlayer.destroy();
  2833. this.aiAudioPlayer = null;
  2834. this.showContinueQuestionOptions();
  2835. this.checkPendingNavigation();
  2836. });
  2837. } else {
  2838. console.error("音频文件下载失败:", res);
  2839. this.handleAudioPlaybackFailure();
  2840. }
  2841. },
  2842. fail: (err) => {
  2843. console.error("音频文件下载请求失败:", err);
  2844. this.handleAudioPlaybackFailure();
  2845. }
  2846. });
  2847. },
  2848. // 添加新方法:处理音频播放失败的情况
  2849. handleAudioPlaybackFailure() {
  2850. this.isPlayingAiVoice = false;
  2851. this.currentSubtitle = this.aiText;
  2852. setTimeout(() => {
  2853. this.currentSubtitle = "";
  2854. this.showContinueQuestionOptions();
  2855. this.checkPendingNavigation();
  2856. }, 1e4);
  2857. },
  2858. // 添加新方法:从视频中提取音频
  2859. async extractAudioFromVideo(videoBlob) {
  2860. console.log("开始从视频中提取音频");
  2861. return new Promise((resolve, reject) => {
  2862. try {
  2863. const videoElement = document.createElement("video");
  2864. videoElement.muted = false;
  2865. videoElement.autoplay = false;
  2866. const audioContext = new (window.AudioContext || window.webkitAudioContext)();
  2867. let audioDestination = null;
  2868. let mediaRecorder = null;
  2869. const audioChunks = [];
  2870. videoElement.src = URL.createObjectURL(videoBlob);
  2871. videoElement.onloadedmetadata = () => {
  2872. console.log("视频元数据已加载,视频时长:", videoElement.duration);
  2873. const source = audioContext.createMediaElementSource(videoElement);
  2874. audioDestination = audioContext.createMediaStreamDestination();
  2875. source.connect(audioDestination);
  2876. mediaRecorder = new MediaRecorder(audioDestination.stream);
  2877. mediaRecorder.ondataavailable = (event) => {
  2878. if (event.data.size > 0) {
  2879. audioChunks.push(event.data);
  2880. }
  2881. };
  2882. mediaRecorder.onstop = () => {
  2883. const audioBlob = new Blob(audioChunks, { type: "audio/wav" });
  2884. console.log("音频提取完成,大小:", audioBlob.size);
  2885. resolve(audioBlob);
  2886. };
  2887. videoElement.onplay = () => {
  2888. mediaRecorder.start(100);
  2889. };
  2890. videoElement.onended = () => {
  2891. mediaRecorder.stop();
  2892. audioContext.close();
  2893. };
  2894. videoElement.play();
  2895. };
  2896. videoElement.onerror = (err) => {
  2897. console.error("视频加载失败:", err);
  2898. reject(new Error("视频加载失败"));
  2899. };
  2900. } catch (err) {
  2901. console.error("提取音频失败:", err);
  2902. reject(err);
  2903. }
  2904. });
  2905. },
  2906. // 添加新方法:上传音频文件
  2907. async uploadAudioFile(audioBlob, videoUrl) {
  2908. console.log("准备上传音频文件");
  2909. const formData = new FormData();
  2910. const fileName = `audio_${Date.now()}.wav`;
  2911. const audioFile = new File([audioBlob], fileName, { type: "audio/wav" });
  2912. formData.append("audio_file", audioFile);
  2913. formData.append("video_url", videoUrl);
  2914. formData.append("tenant_id", common_vendor.index.getStorageSync("tenant_id") || "1");
  2915. formData.append("openid", common_vendor.index.getStorageSync("userInfo") ? JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid : "");
  2916. formData.append("application_id", common_vendor.index.getStorageSync("appId") || "");
  2917. return new Promise((resolve, reject) => {
  2918. const xhr = new XMLHttpRequest();
  2919. xhr.open("POST", `${common_config.apiBaseUrl}/api/voice_ai_interaction`, true);
  2920. xhr.timeout = 6e4;
  2921. xhr.onload = () => {
  2922. if (xhr.status === 200) {
  2923. try {
  2924. const response = JSON.parse(xhr.responseText);
  2925. resolve(response);
  2926. } catch (e) {
  2927. reject(new Error("解析响应失败"));
  2928. }
  2929. } else {
  2930. reject(new Error("HTTP状态: " + xhr.status));
  2931. }
  2932. };
  2933. xhr.onerror = () => {
  2934. reject(new Error("网络错误"));
  2935. };
  2936. xhr.ontimeout = () => {
  2937. reject(new Error("请求超时"));
  2938. };
  2939. xhr.send(formData);
  2940. });
  2941. },
  2942. // 添加一个新方法:使用小程序原生音频API
  2943. /* playMiniProgramAudio() {
  2944. console.log('使用小程序原生音频API播放:', this.aiVoiceUrl);
  2945. // 标记正在播放AI语音
  2946. this.isPlayingAiVoice = true;
  2947. // 确保在播放期间不显示继续提问按钮
  2948. this.showContinueQuestionButton = false;
  2949. this.showEndInterviewButton = false;
  2950. // 检查音频URL是否有效
  2951. if (!this.aiVoiceUrl || this.aiVoiceUrl.trim() === '') {
  2952. console.error('无效的音频URL');
  2953. // 显示错误提示
  2954. // 标记播放结束
  2955. this.isPlayingAiVoice = false;
  2956. // 显示继续提问选项
  2957. this.showContinueQuestionOptions();
  2958. return;
  2959. }
  2960. try {
  2961. // 使用wx.createInnerAudioContext API (微信小程序)
  2962. const audioContext = wx.createInnerAudioContext();
  2963. // 设置音频属性
  2964. audioContext.autoplay = false;
  2965. audioContext.obeyMuteSwitch = false; // 忽略静音开关
  2966. // 监听播放开始事件
  2967. audioContext.onPlay(() => {
  2968. console.log('AI语音开始播放');
  2969. // 显示正在播放提
  2970. });
  2971. // 监听播放结束事件
  2972. audioContext.onEnded(() => {
  2973. console.log('AI语音播放结束');
  2974. // 标记播放结束
  2975. this.isPlayingAiVoice = false;
  2976. // 清空字幕
  2977. this.currentSubtitle = '';
  2978. // 销毁音频播放器
  2979. audioContext.destroy();
  2980. // 播放结束后显示继续提问选项,而不是直接跳转
  2981. this.showContinueQuestionOptions();
  2982. });
  2983. // 监听播放错误事件
  2984. audioContext.onError((err) => {
  2985. console.error('AI语音播放错误:', err);
  2986. // 标记播放结束
  2987. this.isPlayingAiVoice = false;
  2988. // 清空字幕
  2989. this.currentSubtitle = '';
  2990. // 销毁音频播放器
  2991. audioContext.destroy();
  2992. // 播放错误时也显示继续提问选项
  2993. this.showContinueQuestionOptions();
  2994. });
  2995. // 设置音频源
  2996. audioContext.src = this.aiVoiceUrl;
  2997. // 添加超时处理,如果5秒内没有开始播放,则认为出错
  2998. const playTimeout = setTimeout(() => {
  2999. if (this.isPlayingAiVoice) {
  3000. console.warn('小程序音频播放超时,尝试备选方法');
  3001. this.tryMiniProgramFallbackAudioPlay();
  3002. }
  3003. }, 5000);
  3004. // 延迟一小段时间再播放,确保src已经设置完成
  3005. setTimeout(() => {
  3006. audioContext.play();
  3007. // 播放开始后清除超时
  3008. clearTimeout(playTimeout);
  3009. }, 300);
  3010. } catch (e) {
  3011. console.error('小程序播放AI语音时发生错误:', e);
  3012. // 标记播放结束
  3013. this.isPlayingAiVoice = false;
  3014. // 显示错误提示
  3015. // 使用文本显示方式作为备选方案
  3016. this.handleAudioPlaybackFailure();
  3017. }
  3018. }, */
  3019. // 添加新方法:小程序环境的备选音频播放方法
  3020. tryMiniProgramFallbackAudioPlay() {
  3021. console.log("使用小程序备选方法播放音频:", this.aiVoiceUrl);
  3022. common_vendor.index.downloadFile({
  3023. url: this.aiVoiceUrl,
  3024. success: (res) => {
  3025. if (res.statusCode === 200) {
  3026. console.log("小程序音频文件下载成功:", res.tempFilePath);
  3027. const newAudioContext = common_vendor.wx$1.createInnerAudioContext();
  3028. newAudioContext.autoplay = true;
  3029. newAudioContext.src = res.tempFilePath;
  3030. newAudioContext.onPlay(() => {
  3031. console.log("小程序备选方法:音频开始播放");
  3032. });
  3033. newAudioContext.onEnded(() => {
  3034. console.log("小程序备选方法:音频播放结束");
  3035. this.isPlayingAiVoice = false;
  3036. this.currentSubtitle = "";
  3037. newAudioContext.destroy();
  3038. this.showContinueQuestionOptions();
  3039. this.checkPendingNavigation();
  3040. });
  3041. newAudioContext.onError((err) => {
  3042. console.error("小程序备选方法:音频播放错误:", err);
  3043. this.isPlayingAiVoice = false;
  3044. this.currentSubtitle = "";
  3045. newAudioContext.destroy();
  3046. this.trySystemAudioPlayer();
  3047. });
  3048. } else {
  3049. console.error("小程序音频文件下载失败:", res);
  3050. this.handleAudioPlaybackFailure();
  3051. }
  3052. },
  3053. fail: (err) => {
  3054. console.error("小程序音频文件下载请求失败:", err);
  3055. this.handleAudioPlaybackFailure();
  3056. }
  3057. });
  3058. },
  3059. // 添加新方法:尝试使用系统播放器
  3060. trySystemAudioPlayer() {
  3061. console.log("尝试使用系统播放器播放音频");
  3062. const systemInfo = common_vendor.index.getSystemInfoSync();
  3063. if (systemInfo.platform === "android" || systemInfo.platform === "ios") {
  3064. if (typeof common_vendor.index.playVoice === "function") {
  3065. common_vendor.index.playVoice({
  3066. filePath: this.aiVoiceUrl,
  3067. success: () => {
  3068. console.log("系统播放器播放成功");
  3069. setTimeout(() => {
  3070. this.isPlayingAiVoice = false;
  3071. this.currentSubtitle = "";
  3072. this.showContinueQuestionOptions();
  3073. }, 5e3);
  3074. },
  3075. fail: (err) => {
  3076. console.error("系统播放器播放失败:", err);
  3077. this.handleAudioPlaybackFailure();
  3078. }
  3079. });
  3080. } else {
  3081. common_vendor.index.openDocument({
  3082. filePath: this.aiVoiceUrl,
  3083. fileType: "audio",
  3084. success: () => {
  3085. console.log("使用系统应用打开音频文件");
  3086. setTimeout(() => {
  3087. this.isPlayingAiVoice = false;
  3088. this.currentSubtitle = "";
  3089. this.showContinueQuestionOptions();
  3090. }, 8e3);
  3091. },
  3092. fail: (err) => {
  3093. console.error("无法使用系统应用打开音频:", err);
  3094. this.handleAudioPlaybackFailure();
  3095. }
  3096. });
  3097. }
  3098. } else {
  3099. this.handleAudioPlaybackFailure();
  3100. }
  3101. },
  3102. // 修改 showContinueQuestionOptions 方法,确保状态正确设置
  3103. showContinueQuestionOptions() {
  3104. if (this.isPlayingAiVoice) {
  3105. console.log("AI语音正在播放,暂不显示继续提问选项");
  3106. return;
  3107. }
  3108. this.questionRound++;
  3109. this.currentSubtitle = "";
  3110. console.log("准备跳转到下一页面");
  3111. setTimeout(() => {
  3112. this.navigateToNextPage();
  3113. }, 3e3);
  3114. this.isRecording = false;
  3115. if (this.recordingTimer) {
  3116. clearInterval(this.recordingTimer);
  3117. this.recordingTimer = null;
  3118. }
  3119. this.recordedChunks = [];
  3120. this.recordingTimerCount = 0;
  3121. this.remainingTime = this.maxRecordingTime;
  3122. },
  3123. // 修复 handleContinueQuestionClick 方法,确保状态正确重置
  3124. handleContinueQuestionClick() {
  3125. if (this.isPlayingAiVoice) {
  3126. return;
  3127. }
  3128. this.showContinueQuestionButton = false;
  3129. this.showEndInterviewButton = false;
  3130. this.isRecording = false;
  3131. this.recordingTimerCount = 0;
  3132. this.remainingTime = this.maxRecordingTime;
  3133. this.recordingTimeDisplay = "00:00 / " + this.formatTime(this.maxRecordingTime);
  3134. this.recordedChunks = [];
  3135. if (this.mediaRecorder && this.mediaRecorder.state === "recording") {
  3136. this.mediaRecorder.stop();
  3137. }
  3138. if (this.recorder) {
  3139. try {
  3140. this.cameraContext.stopRecord();
  3141. } catch (e) {
  3142. console.error("停止录制失败:", e);
  3143. }
  3144. this.recorder = null;
  3145. }
  3146. setTimeout(() => {
  3147. this.startRecordingAnswer();
  3148. }, 500);
  3149. },
  3150. // 添加新方法:处理结束面试按钮点击
  3151. handleEndInterviewClick() {
  3152. this.showContinueQuestionButton = false;
  3153. this.showEndInterviewButton = false;
  3154. this.navigateToNextPage();
  3155. },
  3156. // 添加新方法:处理录制错误
  3157. handleRecordingError(error) {
  3158. console.error("录制错误:", error);
  3159. this.isRecording = false;
  3160. this.showStopRecordingButton = false;
  3161. this.showStartRecordingButton = true;
  3162. },
  3163. // 添加新方法:处理上传错误
  3164. handleUploadError(error) {
  3165. console.error("上传错误:", error);
  3166. this.showRetryButton = true;
  3167. this.showUploadStatus = false;
  3168. this.isUploading = false;
  3169. },
  3170. // 添加新方法:检查是否有待处理的自动跳转
  3171. checkPendingNavigation() {
  3172. if (this.pendingAutoNavigation && !this.isPlayingAiVoice && !this.isUploading && !this.currentSubtitle) {
  3173. console.log("所有处理已完成,准备跳转");
  3174. this.pendingAutoNavigation = false;
  3175. setTimeout(() => {
  3176. this.navigateToNextPage();
  3177. }, 1e3);
  3178. }
  3179. },
  3180. // 添加新方法:显示文本回复
  3181. displayTextResponse() {
  3182. this.isPlayingAiVoice = true;
  3183. this.currentSubtitle = "";
  3184. const charDisplayTime = 200;
  3185. let currentIndex = 0;
  3186. const textInterval = setInterval(() => {
  3187. if (currentIndex <= this.aiText.length) {
  3188. this.currentSubtitle = this.aiText.substring(0, currentIndex);
  3189. currentIndex++;
  3190. } else {
  3191. clearInterval(textInterval);
  3192. setTimeout(() => {
  3193. this.isPlayingAiVoice = false;
  3194. this.currentSubtitle = "";
  3195. this.showContinueQuestionOptions();
  3196. this.checkPendingNavigation();
  3197. }, 3e3);
  3198. }
  3199. }, charDisplayTime);
  3200. },
  3201. // 添加新方法:检查不支持的音频格式
  3202. checkUnsupportedAudioFormat(url) {
  3203. if (!url)
  3204. return false;
  3205. const extension = url.split(".").pop().toLowerCase();
  3206. const systemInfo = common_vendor.index.getSystemInfoSync();
  3207. const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
  3208. if (isMiniProgram) {
  3209. const unsupportedFormats = ["ogg", "flac", "aac", "m4a", "opus"];
  3210. return unsupportedFormats.includes(extension);
  3211. }
  3212. return false;
  3213. },
  3214. // 修改文本回退方法
  3215. useIOSTextFallback() {
  3216. console.log("切换到文本显示模式");
  3217. this.isPlayingAiVoice = false;
  3218. if (!this.hasShownTextFallbackToast) {
  3219. this.hasShownTextFallbackToast = true;
  3220. }
  3221. this.currentSubtitle = this.aiText || "抱歉,无法获取AI回复内容";
  3222. const textLength = this.aiText ? this.aiText.length : 20;
  3223. const readingTime = Math.max(8e3, Math.min(textLength * 150, 2e4));
  3224. console.log(`文本长度: ${textLength}字,预计阅读时间: ${readingTime / 1e3}秒`);
  3225. setTimeout(() => {
  3226. this.navigateToNextPage();
  3227. }, readingTime);
  3228. },
  3229. // 添加音频预加载方法
  3230. preloadAudio(audioUrl) {
  3231. return new Promise((resolve, reject) => {
  3232. console.log("开始预加载音频:", audioUrl);
  3233. const downloadTask = common_vendor.wx$1.downloadFile({
  3234. url: audioUrl,
  3235. success: (res) => {
  3236. if (res.statusCode === 200) {
  3237. console.log("音频文件下载成功,临时路径:", res.tempFilePath);
  3238. resolve(res.tempFilePath);
  3239. } else {
  3240. console.error("音频文件下载失败,状态码:", res.statusCode);
  3241. reject(new Error(`下载失败,状态码: ${res.statusCode}`));
  3242. }
  3243. },
  3244. fail: (error) => {
  3245. console.error("音频文件下载失败:", error);
  3246. reject(error);
  3247. }
  3248. });
  3249. downloadTask.onProgressUpdate((res) => {
  3250. console.log("音频下载进度:", res.progress);
  3251. });
  3252. });
  3253. },
  3254. // 修改音频播放方法
  3255. playMiniProgramAudio() {
  3256. return new Promise(async (resolve, reject) => {
  3257. try {
  3258. common_vendor.index.showLoading({
  3259. title: "音频加载中...",
  3260. mask: true
  3261. });
  3262. const localAudioPath = await this.preloadAudio(this.aiVoiceUrl);
  3263. common_vendor.index.hideLoading();
  3264. const audioContext = common_vendor.wx$1.createInnerAudioContext();
  3265. audioContext.src = localAudioPath;
  3266. audioContext.autoplay = true;
  3267. audioContext.bufferSize = 4096;
  3268. let hasStarted = false;
  3269. let hasError = false;
  3270. audioContext.onPlay(() => {
  3271. console.log("AI语音开始播放");
  3272. hasStarted = true;
  3273. this.currentSubtitle = this.aiText;
  3274. });
  3275. audioContext.onEnded(() => {
  3276. console.log("AI语音播放结束");
  3277. this.isPlayingAiVoice = false;
  3278. this.currentSubtitle = "";
  3279. audioContext.destroy();
  3280. if (!hasError) {
  3281. console.log("准备跳转到下一页");
  3282. this.navigateToNextPage();
  3283. resolve();
  3284. }
  3285. });
  3286. audioContext.onStop(() => {
  3287. console.log("AI语音播放停止");
  3288. this.isPlayingAiVoice = false;
  3289. this.currentSubtitle = "";
  3290. audioContext.destroy();
  3291. if (!hasError) {
  3292. console.log("播放停止,准备跳转到下一页");
  3293. this.navigateToNextPage();
  3294. resolve();
  3295. }
  3296. });
  3297. audioContext.onError((err) => {
  3298. hasError = true;
  3299. console.error("AI语音播放错误:", err);
  3300. audioContext.destroy();
  3301. common_vendor.index.showToast({
  3302. title: "音频播放异常,将显示文字",
  3303. icon: "none",
  3304. duration: 2e3
  3305. });
  3306. if (this.aiVoiceUrl.endsWith(".mp3")) {
  3307. const wavUrl = this.aiVoiceUrl.replace(".mp3", ".wav");
  3308. console.log("尝试使用WAV格式:", wavUrl);
  3309. this.aiVoiceUrl = wavUrl;
  3310. this.playMiniProgramAudio().then(resolve).catch(reject);
  3311. } else {
  3312. reject(err);
  3313. }
  3314. });
  3315. setTimeout(() => {
  3316. if (!hasStarted && !hasError) {
  3317. console.error("音频播放启动超时");
  3318. audioContext.destroy();
  3319. reject(new Error("音频播放启动超时"));
  3320. }
  3321. }, 5e3);
  3322. } catch (error) {
  3323. common_vendor.index.hideLoading();
  3324. console.error("音频播放初始化失败:", error);
  3325. reject(error);
  3326. }
  3327. });
  3328. },
  3329. // 添加备选的音频播放方法
  3330. async playFallbackAudio() {
  3331. return new Promise((resolve, reject) => {
  3332. try {
  3333. const audio = common_vendor.wx$1.createInnerAudioContext();
  3334. audio.volume = 1;
  3335. audio.playbackRate = 1;
  3336. audio.src = this.aiVoiceUrl;
  3337. audio.autoplay = true;
  3338. audio.onPlay(() => {
  3339. console.log("备选音频开始播放");
  3340. });
  3341. audio.onEnded(() => {
  3342. console.log("备选音频播放完成");
  3343. audio.destroy();
  3344. resolve();
  3345. });
  3346. audio.onError((err) => {
  3347. console.error("备选音频播放失败:", err);
  3348. audio.destroy();
  3349. reject(err);
  3350. });
  3351. } catch (error) {
  3352. reject(error);
  3353. }
  3354. });
  3355. },
  3356. // 修改主音频播放方法
  3357. async playAiVoice() {
  3358. console.log("开始播放AI语音:", this.aiVoiceUrl);
  3359. this.isPlayingAiVoice = true;
  3360. this.currentSubtitle = this.aiText;
  3361. try {
  3362. await this.playMiniProgramAudio();
  3363. console.log("音频播放完成,准备跳转");
  3364. this.navigateToNextPage();
  3365. } catch (error) {
  3366. console.error("主要播放方法失败,尝试备选方法:", error);
  3367. try {
  3368. await this.playFallbackAudio();
  3369. console.log("备选音频播放完成,准备跳转");
  3370. this.navigateToNextPage();
  3371. } catch (fallbackError) {
  3372. console.error("备选播放方法也失败:", fallbackError);
  3373. this.useTextFallbackAndNavigate();
  3374. }
  3375. }
  3376. },
  3377. // 监听字幕内容变化
  3378. handleSubtitleChange() {
  3379. this.$nextTick(() => {
  3380. const subtitleEl = document.querySelector(".subtitle-overlay");
  3381. if (subtitleEl) {
  3382. const contentHeight = subtitleEl.scrollHeight;
  3383. this.subtitleHeight = contentHeight;
  3384. this.isSubtitleExpanded = contentHeight > window.innerHeight * 0.3;
  3385. }
  3386. });
  3387. }
  3388. },
  3389. // 添加watch来监听字幕内容变化
  3390. watch: {
  3391. currentSubtitle: {
  3392. handler(newVal) {
  3393. if (newVal) {
  3394. this.handleSubtitleChange();
  3395. } else {
  3396. this.isSubtitleExpanded = false;
  3397. }
  3398. },
  3399. immediate: true
  3400. }
  3401. }
  3402. };
  3403. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  3404. return common_vendor.e({
  3405. a: $data.videoUrl,
  3406. b: common_vendor.o((...args) => $options.handleVideoError && $options.handleVideoError(...args)),
  3407. c: common_vendor.o((...args) => $options.handleVideoEnded && $options.handleVideoEnded(...args)),
  3408. d: common_vendor.o((...args) => $options.handleTimeUpdate && $options.handleTimeUpdate(...args)),
  3409. e: $data.showAnswerButton
  3410. }, $data.showAnswerButton ? {
  3411. f: common_vendor.o((...args) => $options.handleAnswerButtonClick && $options.handleAnswerButtonClick(...args))
  3412. } : {}, {
  3413. g: $data.currentSubtitle
  3414. }, $data.currentSubtitle ? common_vendor.e({
  3415. h: common_vendor.t($data.currentSubtitle),
  3416. i: $data.showNextButton
  3417. }, $data.showNextButton ? {
  3418. j: common_vendor.o((...args) => $options.handleNextButtonClick && $options.handleNextButtonClick(...args))
  3419. } : {}, {
  3420. k: $data.isSubtitleExpanded ? 1 : "",
  3421. l: $data.subtitleHeight ? `${$data.subtitleHeight}px` : null
  3422. }) : {}, {
  3423. m: $data.useMiniProgramCameraComponent
  3424. }, $data.useMiniProgramCameraComponent ? {
  3425. n: common_vendor.o((...args) => $options.handleCameraError && $options.handleCameraError(...args))
  3426. } : {}, {
  3427. o: $data.loading
  3428. }, $data.loading ? {} : {}, {
  3429. p: $data.showDebugInfo
  3430. }, $data.showDebugInfo ? common_vendor.e({
  3431. q: $data.assistantResponse
  3432. }, $data.assistantResponse ? {
  3433. r: common_vendor.t($data.assistantResponse)
  3434. } : {}, {
  3435. s: $data.audioTranscript
  3436. }, $data.audioTranscript ? {
  3437. t: common_vendor.t($data.audioTranscript)
  3438. } : {}, {
  3439. v: common_vendor.f($data.processedResponses, (item, index, i0) => {
  3440. return common_vendor.e({
  3441. a: item.role
  3442. }, item.role ? {
  3443. b: common_vendor.t(item.role)
  3444. } : {}, {
  3445. c: item.transcript
  3446. }, item.transcript ? {
  3447. d: common_vendor.t(item.transcript)
  3448. } : {}, {
  3449. e: index
  3450. });
  3451. })
  3452. }) : {}, {
  3453. w: $data.showStopRecordingButton
  3454. }, $data.showStopRecordingButton ? {
  3455. x: common_vendor.o((...args) => $options.stopRecordingAnswer && $options.stopRecordingAnswer(...args))
  3456. } : {}, {
  3457. y: $data.isRecording
  3458. }, $data.isRecording ? {
  3459. z: common_vendor.t($data.recordingTimeDisplay || "00:00 / 05:00")
  3460. } : {}, {
  3461. A: $data.showStartRecordingButton
  3462. }, $data.showStartRecordingButton ? {
  3463. B: common_vendor.o((...args) => $options.handleStartRecordingClick && $options.handleStartRecordingClick(...args))
  3464. } : {}, {
  3465. C: $data.showRetryButton
  3466. }, $data.showRetryButton ? {
  3467. D: common_vendor.o((...args) => $options.retryVideoUpload && $options.retryVideoUpload(...args))
  3468. } : {}, {
  3469. E: $data.showCountdown
  3470. }, $data.showCountdown ? {
  3471. F: common_vendor.t($data.countdownValue)
  3472. } : {}, {
  3473. G: $data.isPlayingAiVoice
  3474. }, $data.isPlayingAiVoice ? {} : {}, {
  3475. H: $data.showContinueQuestionButton
  3476. }, $data.showContinueQuestionButton ? {
  3477. I: common_vendor.o((...args) => $options.handleContinueQuestionClick && $options.handleContinueQuestionClick(...args))
  3478. } : {});
  3479. }
  3480. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-2a02c54e"]]);
  3481. wx.createPage(MiniProgramPage);