1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const common_config = require("../../common/config.js");
- const _sfc_main = {
- name: "IdentityVerify",
- data() {
- return {
- loading: false,
- responses: [],
- processedResponses: [],
- assistantResponse: "",
- audioTranscript: "",
- videoPlaying: false,
- showDebugInfo: false,
- // 设置为true可以显示调试信息
- videoUrl: "",
- // 修改为空字符串,将通过API获取
- showReplayButton: false,
- cameraStream: null,
- // 存储摄像头流
- cameraError: null,
- // 存储摄像头错误信息
- useMiniProgramCameraComponent: false,
- // 添加小程序相机组件标志
- cameraContext: null,
- // 添加相机上下文
- currentSubtitle: "",
- currentTranslation: "",
- // 添加翻译文本
- subtitles: [],
- // 修改为空数组,将通过API获取
- // 移除硬编码的字幕数组
- // secondVideoSubtitles: [...],
- // thirdVideoSubtitles: [...],
- // 等等...
- showAnswerButton: false,
- // 控制答题按钮显示
- currentVideoIndex: 0,
- // 当前播放的视频索引
- videoList: [],
- // 修改为空数组,将通过API获取
- // 其他属性保持不变...
- questions: [],
- // 添加新属性存储API返回的问题数据
- introVideoUrl: "http://121.36.251.245:9000/minlong/tenant_1/general_uploads/880a117c8fcc4196b0d8c0750608d373.mp4",
- // 保留介绍视频
- isRecording: false,
- recordingTimer: null,
- showStopRecordingButton: false,
- mediaRecorder: null,
- recordedChunks: [],
- recorder: null,
- lastUploadedVideoUrl: "",
- showStartRecordingButton: false,
- showRetryButton: false,
- // 控制重试按钮显示
- lastVideoToRetry: null,
- // 存储上次失败的视频URL,用于重试
- recordingStartTime: null,
- // 录制开始时间
- recordingTimerCount: 0,
- // 录制计时器计数
- recordingTimeDisplay: "00:00",
- // 格式化的录制时间显示
- // 添加上传队列相关数据
- uploadQueue: [],
- // 存储待上传的视频
- isUploading: false,
- // 标记是否正在上传
- uploadProgress: {},
- // 存储每个视频的上传进度
- uploadStatus: {},
- // 存储每个视频的上传状态
- showUploadStatus: false,
- // 是否显示上传状态指示器
- uploadStatusText: "",
- // 上传状态文本
- mediaRecorderTimeout: null,
- // 用于存储MediaRecorder的超时机制
- maxRecordingTime: 300,
- // 最大录制时间(秒)- 从60秒改为300秒(5分钟)
- remainingTime: 300,
- // 剩余录制时间(秒)- 从60秒改为300秒
- countdownValue: 10,
- // 倒计时数值
- showCountdown: false,
- // 是否显示倒计时蒙层
- countdownTimer: null,
- showGif: false,
- // 控制是否显示GIF
- gifUrl: "",
- // GIF图片的URL
- globalSocketTask: null,
- // 添加全局 WebSocket 连接对象
- lowScoreVideoUrl: "https://data.qicai321.com/minlong/latentsync/0530e7f5-1957-422d-8f34-ba4a92608081_result.mp4",
- // 低分提示视频URL
- showRerecordButton: false,
- // 控制重新录制按钮显示
- isPlayingLowScoreVideo: false,
- // 标记是否正在播放低分提示视频
- lowScoreVideoSubtitles: [
- {
- startTime: 0,
- endTime: 10,
- // 假设视频长度为10秒,可根据实际情况调整
- text: "我未听清楚您在说什么,请您再说一遍!"
- }
- ],
- // 用于存储低分提示视频的字幕
- retryCount: 0,
- // 添加重试次数计数器
- maxRetryAttempts: 2,
- // 最大重试次数限制
- needPlayLowScoreVideo: false,
- // 是否需要播放低分视频
- finalRecordingDuration: 0,
- // 最终录制时长
- historyTime: 0,
- // 添加历史时间记录
- followUpQuestions: [],
- // 存储追问问题数据
- currentParentQuestionId: null,
- // 当前父问题ID
- hasPlayedFollowUp: {},
- // 记录已播放的追问,格式: {questionId: true}
- isFollowUpQuestion: false,
- // 标记当前是否正在播放追问问题
- currentFollowUpQuestion: null,
- // 添加当前追问问题的完整信息
- lastQuestionWasFollowUp: false,
- lastFollowUpQuestionId: null,
- lastUpdateTime: Date.now(),
- // 添加最后更新时间戳
- subtitleMap: {}
- // 用于存储字幕和翻译的映射
- };
- },
- mounted() {
- this.fetchQuestions();
- this.fetchFollowUpQuestions();
- this.checkAudioPermission();
- this.initCamera();
- this.checkIOSCameraRecordPermission();
- this.checkAndFixRenderingIssues();
- setTimeout(() => {
- if (this.cameraStream && !this.useMiniProgramCameraComponent) {
- this.testAudioInput();
- }
- }, 3e3);
- this.historyTime = 0;
- common_vendor.index.setKeepScreenOn({
- keepScreenOn: true
- });
- },
- beforeDestroy() {
- this.stopUserCamera();
- this.clearCountdown();
- },
- methods: {
- // 初始化相机
- async initCamera() {
- const systemInfo = common_vendor.index.getSystemInfoSync();
- const isMiniProgram = systemInfo.uniPlatform === "mp-weixin" || systemInfo.uniPlatform === "mp-alipay" || systemInfo.uniPlatform === "mp-baidu";
- if (isMiniProgram) {
- this.useMiniProgramCameraComponent = true;
- this.cameraContext = common_vendor.index.createCameraContext();
- common_vendor.index.getSetting({
- success: (res) => {
- if (!res.authSetting["scope.record"]) {
- common_vendor.index.authorize({
- scope: "scope.record",
- success: () => {
- console.log("录音权限已获取");
- },
- fail: (err) => {
- console.error("录音权限获取失败:", err);
- this.showPermissionDialog("录音");
- }
- });
- }
- if (!res.authSetting["scope.camera"]) {
- common_vendor.index.authorize({
- scope: "scope.camera",
- success: () => {
- console.log("相机权限已获取");
- },
- fail: (err) => {
- console.error("相机权限获取失败:", err);
- this.showPermissionDialog("相机");
- }
- });
- }
- const systemInfo2 = common_vendor.index.getSystemInfoSync();
- if (systemInfo2.platform === "ios") {
- if (!res.authSetting["scope.camera"] || !res.authSetting["scope.record"]) {
- console.log("iOS需要同时获取相机和录音权限");
- }
- }
- }
- });
- } else {
- try {
- const constraints = {
- audio: {
- echoCancellation: true,
- noiseSuppression: true,
- autoGainControl: true
- },
- video: {
- width: { ideal: 640, max: 1280 },
- // 控制视频宽度
- height: { ideal: 480, max: 720 },
- // 控制视频高度
- frameRate: { ideal: 15, max: 24 },
- // 控制帧率
- facingMode: "user"
- }
- };
- const stream = await navigator.mediaDevices.getUserMedia(constraints);
- this.cameraStream = stream;
- const audioTracks = stream.getAudioTracks();
- console.log("音频轨道数量:", audioTracks.length);
- if (audioTracks.length > 0) {
- console.log("音频轨道已获取:", audioTracks[0].label);
- audioTracks[0].enabled = true;
- } else {
- console.warn("未检测到音频轨道,尝试单独获取音频");
- this.tryGetAudioOnly();
- }
- const videoElement = this.$refs.userCameraVideo;
- if (videoElement) {
- videoElement.srcObject = stream;
- videoElement.muted = true;
- }
- } catch (error) {
- console.error("获取摄像头失败:", error);
- this.cameraError = error.message || "无法访问摄像头";
- common_vendor.index.showToast({
- title: "无法访问摄像头,请检查权限设置",
- icon: "none"
- });
- }
- }
- },
- // 停止用户摄像头
- stopUserCamera() {
- if (this.cameraStream) {
- this.cameraStream.getTracks().forEach((track) => {
- track.stop();
- });
- this.cameraStream = null;
- }
- },
- async fetchData() {
- this.loading = true;
- this.assistantResponse = "";
- this.audioTranscript = "";
- this.processedResponses = [];
- try {
- const requestTask = common_vendor.index.request({
- url: "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions",
- method: "POST",
- header: {
- "Content-Type": "application/json",
- "Authorization": "Bearer sk-9e1ec73a7d97493b8613c63f06b6110c"
- },
- data: {
- "model": "qwen-omni-turbo",
- "messages": [
- {
- "role": "user",
- "content": [
- {
- "type": "input_audio",
- "input_audio": {
- "data": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250211/tixcef/cherry.wav",
- "format": "wav"
- }
- },
- {
- "type": "text",
- "text": "这段音频在说什么"
- }
- ]
- }
- ],
- "stream": true,
- "stream_options": {
- "include_usage": true
- },
- "modalities": ["text", "audio"],
- "audio": { "voice": "Cherry", "format": "wav" }
- },
- success: (res) => {
- console.log("请求成功,响应数据:", res.data);
- if (typeof res.data === "string" && res.data.includes("data: {")) {
- const chunks = res.data.split("data: ").filter((chunk) => chunk.trim() !== "");
- chunks.forEach((chunk) => {
- this.handleStreamResponse(chunk);
- });
- } else {
- this.handleStreamResponse(res.data);
- }
- this.playDigitalHumanVideo();
- },
- fail: (err) => {
- console.error("请求失败:", err);
- },
- complete: () => {
- this.loading = false;
- }
- });
- } catch (error) {
- console.error("获取数据失败:", error);
- this.loading = false;
- }
- },
- handleStreamResponse(data) {
- if (typeof data === "string") {
- if (data === "[DONE]")
- return;
- try {
- const cleanData = data.trim();
- if (cleanData.startsWith("{") && cleanData.endsWith("}")) {
- const jsonData = JSON.parse(cleanData);
- this.processStreamChunk(jsonData);
- }
- } catch (e) {
- console.error("解析JSON失败:", e, "原始数据:", data);
- }
- } else {
- this.processStreamChunk(data);
- }
- },
- processStreamChunk(chunk) {
- if (chunk.choices && chunk.choices.length > 0) {
- const choice = chunk.choices[0];
- if (choice.delta && choice.delta.content) {
- this.assistantResponse += choice.delta.content;
- }
- if (choice.delta && choice.delta.audio && choice.delta.audio.transcript) {
- this.audioTranscript += choice.delta.audio.transcript;
- }
- if (choice.delta) {
- const result = {};
- if (choice.delta.role) {
- result.role = choice.delta.role;
- }
- if (choice.delta.audio && choice.delta.audio.transcript) {
- result.transcript = choice.delta.audio.transcript;
- }
- if (Object.keys(result).length > 0) {
- this.processedResponses.push(result);
- }
- }
- }
- },
- processResponseData() {
- this.processedResponses = this.responses.map((item) => {
- const result = {};
- if (item.delta && item.delta.role) {
- result.role = item.delta.role;
- }
- if (item.delta && item.delta.audio && item.delta.audio.transcript) {
- result.transcript = item.delta.audio.transcript;
- }
- return result;
- }).filter((item) => Object.keys(item).length > 0);
- },
- // 播放数字人视频
- playDigitalHumanVideo() {
- if (this.videoList.length === 0) {
- this.fetchQuestions();
- return;
- }
- this.videoUrl = this.videoList[this.currentVideoIndex];
- this.videoPlaying = true;
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.play();
- setTimeout(() => {
- if (this.videoPlaying && this.$refs.videoPlayer) {
- console.log("视频应该正在播放");
- } else {
- console.log("视频可能未成功播放,尝试替代方案");
- this.tryAlternativeVideoPath();
- }
- }, 1e3);
- } else {
- console.error("无法创建视频上下文");
- this.tryAlternativeVideoPath();
- }
- });
- },
- // 修改 tryAlternativeVideoPath 方法
- tryAlternativeVideoPath() {
- console.log("尝试使用替代路径");
- const alternativePaths = [
- "./static/demo.mp4",
- "../static/demo.mp4",
- "static/demo.mp4",
- "/static/demo.mp4",
- // 添加绝对路径
- `${window.location.origin}/static/demo.mp4`
- ];
- const currentPathIndex = alternativePaths.indexOf(this.videoUrl);
- const nextPathIndex = (currentPathIndex + 1) % alternativePaths.length;
- this.videoUrl = alternativePaths[nextPathIndex];
- console.log("尝试新路径:", this.videoUrl);
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.stop();
- videoContext.play();
- setTimeout(() => {
- if (nextPathIndex === alternativePaths.length - 1 && !this.videoPlaying) {
- console.log("所有路径均失败,尝试使用uni.getVideoInfo检查视频");
- this.checkVideoWithAPI();
- }
- }, 1e3);
- }
- });
- },
- // 添加新方法:使用uni API检查视频
- checkVideoWithAPI() {
- common_vendor.index.getVideoInfo({
- src: "/static/demo.mp4",
- success: (res) => {
- console.log("视频信息获取成功:", res);
- this.videoUrl = "/static/demo.mp4";
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.play();
- }
- });
- },
- fail: (err) => {
- console.error("视频信息获取失败:", err);
- this.fallbackToLocalVideo();
- }
- });
- },
- // 添加新方法:回退到本地视频
- fallbackToLocalVideo() {
- console.log("尝试使用本地视频资源");
- const platform = common_vendor.index.getSystemInfoSync().platform;
- if (platform === "android" || platform === "ios") {
- this.videoUrl = platform === "android" ? "android.resource://package_name/raw/demo" : "file:///assets/demo.mp4";
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.play();
- }
- });
- } else {
- this.videoPlaying = false;
- common_vendor.index.showToast({
- title: "视频加载失败,显示静态图片",
- icon: "none"
- });
- }
- },
- // 修改 handleVideoError 方法
- handleVideoError(e) {
- console.error("视频加载错误:", e);
- if (e && e.detail) {
- console.error("详细错误信息:", e.detail);
- }
- common_vendor.index.getFileInfo({
- filePath: this.videoUrl.startsWith("/") ? this.videoUrl.substring(1) : this.videoUrl,
- success: (res) => {
- console.log("文件存在,大小:", res.size);
- this.tryDifferentFormat();
- },
- fail: (err) => {
- console.error("文件不存在或无法访问:", err);
- this.tryAlternativeVideoPath();
- }
- });
- common_vendor.index.showToast({
- title: "视频加载失败,请检查文件是否存在",
- icon: "none",
- duration: 2e3
- });
- },
- // 添加新方法:尝试不同格式
- tryDifferentFormat() {
- console.log("尝试不同的视频格式");
- const formats = [
- { ext: "mp4", mime: "video/mp4" },
- { ext: "webm", mime: "video/webm" },
- { ext: "ogg", mime: "video/ogg" },
- { ext: "mov", mime: "video/quicktime" }
- ];
- const currentPath = this.videoUrl;
- const basePath = currentPath.substring(0, currentPath.lastIndexOf(".")) || "/static/demo";
- let nextFormat = formats.find((f) => !currentPath.endsWith(f.ext));
- if (nextFormat) {
- this.videoUrl = `${basePath}.${nextFormat.ext}`;
- console.log("尝试新格式:", this.videoUrl);
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.stop();
- videoContext.play();
- }
- });
- } else {
- this.useBuiltInResource();
- }
- },
- // 添加新方法:使用内置资源
- useBuiltInResource() {
- console.log("尝试使用内置资源");
- const platform = common_vendor.index.getSystemInfoSync().platform;
- if (platform === "windows") {
- process.env.UNI_INPUT_DIR || "";
- this.videoUrl = `./static/demo.mp4`;
- console.log("Windows平台尝试路径:", this.videoUrl);
- } else if (platform === "android" || platform === "ios") {
- this.useNativeVideo();
- } else {
- const baseUrl = window.location.origin;
- this.videoUrl = `${baseUrl}/static/demo.mp4`;
- console.log("Web平台尝试URL:", this.videoUrl);
- }
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.play();
- }
- });
- },
- // 添加新方法:使用原生视频能力
- useNativeVideo() {
- console.log("尝试使用原生视频能力");
- common_vendor.index.chooseVideo({
- sourceType: ["album"],
- success: (res) => {
- this.videoUrl = res.tempFilePath;
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.play();
- }
- });
- },
- fail: () => {
- this.videoPlaying = false;
- common_vendor.index.showToast({
- title: "无法加载视频,显示静态图片",
- icon: "none"
- });
- }
- });
- },
- // 处理视频结束事件
- handleVideoEnded() {
- console.log("视频播放结束事件触发");
- const videoElement = this.$refs.videoPlayer;
- if (videoElement) {
- const currentTime = videoElement.currentTime || 0;
- const duration = videoElement.duration || 0;
- if (duration > 0 && duration - currentTime > 0.5) {
- console.log("检测到可能的误触发结束事件,继续播放", currentTime, duration);
- setTimeout(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- if (duration - currentTime > 2) {
- videoContext.seek(this.historyTime || 0);
- } else {
- videoContext.play();
- }
- }
- }, 100);
- return;
- }
- console.log("视频确认结束,当前时间:", currentTime, "总时长:", duration);
- }
- this.videoPlaying = false;
- if (this.isPlayingLowScoreVideo) {
- console.log("低分提示视频播放完成");
- if (this.retryCount < this.maxRetryAttempts) {
- console.log(`显示重新录制按钮 (重试次数: ${this.retryCount + 1}/${this.maxRetryAttempts})`);
- this.showRerecordButton = true;
- } else {
- console.log("已达到最大重试次数,继续下一题");
- this.retryCount = 0;
- this.proceedToNextQuestion();
- }
- this.isPlayingLowScoreVideo = false;
- this.currentSubtitle = "";
- return;
- }
- if (this.isFollowUpQuestion) {
- console.log("追问问题视频播放完成");
- this.isFollowUpQuestion = false;
- this.showStartRecordingButton = true;
- this.startCountdown();
- return;
- }
- if (this.currentVideoIndex >= 1) {
- this.showStartRecordingButton = true;
- this.startCountdown();
- } else {
- this.showAnswerButton = true;
- }
- },
- // 添加新方法:开始倒计时
- startCountdown() {
- this.showCountdown = true;
- this.countdownValue = 10;
- this.countdownTimer = setInterval(() => {
- this.countdownValue--;
- if (this.countdownValue <= 0) {
- this.clearCountdown();
- this.showStartRecordingButton = false;
- this.startRecordingAnswer();
- }
- }, 1e3);
- },
- // 添加新方法:清除倒计时
- clearCountdown() {
- if (this.countdownTimer) {
- clearInterval(this.countdownTimer);
- this.countdownTimer = null;
- }
- this.showCountdown = false;
- },
- // 修改 handleStartRecordingClick 方法,使其可以终止倒计时
- handleStartRecordingClick() {
- this.showStartRecordingButton = false;
- this.clearCountdown();
- this.startRecordingAnswer();
- },
- // 修改 stopRecordingAnswer 方法,添加录制时长检查
- stopRecordingAnswer() {
- this.clearCountdown();
- const recordingDuration = this.getRecordingDuration();
- const minimumDuration = 3;
- const lowScoreDuration = 7;
- if (recordingDuration < minimumDuration) {
- common_vendor.index.showToast({
- title: "录制时间过短,请至少录制3秒",
- icon: "none",
- duration: 2e3
- });
- return;
- }
- this.completeRecordingStop();
- if (recordingDuration < lowScoreDuration) {
- console.log(`录制时间 ${recordingDuration} 秒,少于 ${lowScoreDuration} 秒,将播放低分提示视频`);
- this.needPlayLowScoreVideo = true;
- } else {
- this.needPlayLowScoreVideo = false;
- }
- },
- // 添加新方法:开始录制用户回答
- startRecordingAnswer() {
- console.log("开始录制用户回答");
- this.isRecording = true;
- this.recordingStartTime = Date.now();
- this.recordingTimerCount = 0;
- this.remainingTime = this.maxRecordingTime;
- this.recordingTimer = setInterval(() => {
- this.recordingTimerCount++;
- this.remainingTime = Math.max(0, this.maxRecordingTime - this.recordingTimerCount);
- this.recordingTimeDisplay = this.formatTime(this.recordingTimerCount) + " / " + this.formatTime(this.maxRecordingTime);
- if (this.recordingTimerCount >= this.maxRecordingTime) {
- console.log("已达到最大录制时间(5分钟),自动停止录制");
- this.stopRecordingAnswer();
- }
- }, 1e3);
- const systemInfo = common_vendor.index.getSystemInfoSync();
- const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
- if (isMiniProgram) {
- this.startMiniProgramRecording();
- } else {
- this.startBrowserRecording();
- }
- this.showStopRecordingButton = true;
- },
- // 添加一个新方法:重置相机组件
- resetCamera() {
- console.log("重置相机组件");
- this.useMiniProgramCameraComponent = false;
- if (this.cameraContext) {
- this.cameraContext = null;
- }
- setTimeout(() => {
- this.useMiniProgramCameraComponent = true;
- setTimeout(() => {
- this.cameraContext = common_vendor.index.createCameraContext();
- console.log("相机组件已重置");
- }, 500);
- }, 500);
- },
- // 修改 startMiniProgramRecording 方法
- startMiniProgramRecording() {
- console.log("开始小程序录制方法");
- const systemInfo = common_vendor.index.getSystemInfoSync();
- const isIOS = systemInfo.platform === "ios";
- if (isIOS) {
- this.resetCamera();
- setTimeout(() => {
- this.actualStartRecording(isIOS);
- }, 1e3);
- } else {
- this.actualStartRecording(isIOS);
- }
- },
- // 添加新方法:实际开始录制
- actualStartRecording(isIOS) {
- if (!this.cameraContext) {
- this.cameraContext = common_vendor.index.createCameraContext();
- console.log("创建新的相机上下文");
- }
- common_vendor.index.getSetting({
- success: (res) => {
- const hasRecordAuth = res.authSetting["scope.record"];
- const hasCameraAuth = res.authSetting["scope.camera"];
- if (!hasRecordAuth || !hasCameraAuth) {
- console.warn("缺少必要权限,请求权限");
- this.requestMiniProgramPermissions();
- return;
- }
- if (isIOS) {
- console.log("iOS: 检查相机状态");
- const options = {
- timeout: 3e5,
- // 300秒超时 (5分钟)
- quality: "low",
- // 降低质量
- compressed: true,
- success: () => {
- console.log("iOS录制开始成功");
- },
- fail: (err) => {
- console.error("iOS录制失败:", err);
- this.useAlternativeRecordingMethod();
- }
- };
- try {
- console.log("尝试开始录制");
- this.recorder = this.cameraContext.startRecord(options);
- } catch (e) {
- console.error("开始录制异常:", e);
- this.useAlternativeRecordingMethod();
- }
- } else {
- const options = {
- timeout: 3e5,
- // 300秒超时 (5分钟)
- quality: "medium",
- compressed: true,
- success: () => {
- console.log("Android录制开始成功");
- },
- fail: (err) => {
- console.error("Android录制失败:", err);
- common_vendor.index.showToast({
- title: "录制失败,请检查相机权限",
- icon: "none"
- });
- this.proceedToNextQuestion();
- }
- };
- this.recorder = this.cameraContext.startRecord(options);
- }
- }
- });
- },
- // 添加新方法:使用替代录制方法
- useAlternativeRecordingMethod() {
- console.log("使用替代录制方法");
- common_vendor.index.showActionSheet({
- itemList: ["使用相册中的视频", "跳过此问题"],
- success: (res) => {
- if (res.tapIndex === 0) {
- common_vendor.index.chooseVideo({
- sourceType: ["album"],
- maxDuration: 300,
- // 从60秒改为300秒
- camera: "front",
- success: (res2) => {
- console.log("选择视频成功:", res2.tempFilePath);
- this.isRecording = false;
- this.showStopRecordingButton = false;
- this.uploadRecordedVideo(res2.tempFilePath);
- },
- fail: () => {
- console.log("用户取消选择视频");
- this.proceedToNextQuestion();
- }
- });
- } else {
- console.log("用户选择跳过问题");
- this.proceedToNextQuestion();
- }
- },
- fail: () => {
- console.log("操作取消");
- this.proceedToNextQuestion();
- }
- });
- },
- // 添加新方法:请求小程序权限
- requestMiniProgramPermissions() {
- common_vendor.index.authorize({
- scope: "scope.record",
- success: () => {
- console.log("录音权限已获取");
- common_vendor.index.authorize({
- scope: "scope.camera",
- success: () => {
- console.log("相机权限已获取");
- this.startMiniProgramRecording();
- },
- fail: (err) => {
- console.error("相机权限获取失败:", err);
- this.showPermissionDialog("相机");
- }
- });
- },
- fail: (err) => {
- console.error("录音权限获取失败:", err);
- this.showPermissionDialog("录音");
- }
- });
- },
- // 修改浏览器环境下的录制方法
- startBrowserRecording() {
- if (!this.cameraStream) {
- console.error("没有可用的摄像头流");
- common_vendor.index.showToast({
- title: "录制失败,摄像头未就绪",
- icon: "none"
- });
- this.proceedToNextQuestion();
- return;
- }
- try {
- const hasAudio = this.cameraStream.getAudioTracks().length > 0;
- if (!hasAudio) {
- console.warn("警告:媒体流中没有音频轨道,尝试重新获取带音频的媒体流");
- navigator.mediaDevices.getUserMedia({
- audio: {
- echoCancellation: true,
- noiseSuppression: true,
- autoGainControl: true
- },
- video: true
- }).then((newStream) => {
- const audioTracks = newStream.getAudioTracks();
- if (audioTracks.length > 0) {
- console.log("成功获取音频轨道:", audioTracks[0].label);
- const videoTrack = this.cameraStream.getVideoTracks()[0];
- const audioTrack = newStream.getAudioTracks()[0];
- const combinedStream = new MediaStream();
- if (videoTrack)
- combinedStream.addTrack(videoTrack);
- if (audioTrack)
- combinedStream.addTrack(audioTrack);
- this.cameraStream = combinedStream;
- const videoElement = this.$refs.userCameraVideo;
- if (videoElement) {
- videoElement.srcObject = combinedStream;
- videoElement.muted = true;
- }
- this.setupMediaRecorder(combinedStream);
- } else {
- console.warn("仍然无法获取音频轨道");
- this.setupMediaRecorder(this.cameraStream);
- }
- }).catch((err) => {
- console.error("获取音频失败:", err);
- this.setupMediaRecorder(this.cameraStream);
- });
- } else {
- console.log("检测到音频轨道,直接使用");
- this.setupMediaRecorder(this.cameraStream);
- }
- } catch (error) {
- console.error("浏览器录制失败:", error);
- common_vendor.index.showToast({
- title: "录制失败,浏览器可能不支持此功能",
- icon: "none"
- });
- this.proceedToNextQuestion();
- }
- },
- // 修改 setupMediaRecorder 方法
- setupMediaRecorder(stream) {
- const videoTracks = stream.getVideoTracks();
- const audioTracks = stream.getAudioTracks();
- console.log("设置MediaRecorder - 视频轨道:", videoTracks.length, "音频轨道:", audioTracks.length);
- let mimeType = "";
- const supportedTypes = [
- "video/webm;codecs=vp9,opus",
- "video/webm;codecs=vp8,opus",
- "video/webm;codecs=h264,opus",
- "video/mp4;codecs=h264,aac",
- "video/webm",
- "video/mp4"
- ];
- for (const type of supportedTypes) {
- if (MediaRecorder.isTypeSupported(type)) {
- mimeType = type;
- console.log("使用支持的MIME类型:", mimeType);
- break;
- }
- }
- const options = {
- mimeType: mimeType || "",
- audioBitsPerSecond: 64e3,
- // 降低音频比特率
- videoBitsPerSecond: 1e6
- // 降低视频比特率到1Mbps
- };
- try {
- this.mediaRecorder = new MediaRecorder(stream, options);
- console.log("MediaRecorder创建成功,使用选项:", options);
- } catch (e) {
- console.warn("使用指定选项创建MediaRecorder失败,尝试使用默认选项");
- this.mediaRecorder = new MediaRecorder(stream);
- }
- this.recordedChunks = [];
- this.mediaRecorder.ondataavailable = (event) => {
- if (event.data && event.data.size > 0) {
- this.recordedChunks.push(event.data);
- console.log(`收到数据块: ${event.data.size} 字节`);
- }
- };
- this.mediaRecorder.onstop = async () => {
- console.log("MediaRecorder停止,数据块数量:", this.recordedChunks.length);
- if (this.recordedChunks.length === 0) {
- console.error("没有录制到数据");
- common_vendor.index.showToast({
- title: "录制失败,未捕获到数据",
- icon: "none"
- });
- this.proceedToNextQuestion();
- return;
- }
- const mimeType2 = this.mediaRecorder.mimeType || "video/webm";
- const blob = new Blob(this.recordedChunks, { type: mimeType2 });
- console.log("创建Blob,原始大小:", blob.size, "类型:", mimeType2);
- common_vendor.index.showLoading({
- title: "正在处理视频...",
- mask: true
- });
- try {
- const compressedBlob = await this.compressVideo(blob);
- const fileName = `answer_${this.currentVideoIndex}_${Date.now()}.webm`;
- const file = new File([compressedBlob], fileName, { type: mimeType2 });
- common_vendor.index.hideLoading();
- this.uploadRecordedVideo(file);
- } catch (error) {
- console.error("视频处理失败:", error);
- common_vendor.index.hideLoading();
- const fileName = `answer_${this.currentVideoIndex}_${Date.now()}.webm`;
- const file = new File([blob], fileName, { type: mimeType2 });
- this.uploadRecordedVideo(file);
- }
- };
- this.mediaRecorder.onerror = (event) => {
- console.error("MediaRecorder错误:", event.error);
- };
- try {
- this.mediaRecorder.start(1e3);
- console.log("MediaRecorder开始录制");
- this.mediaRecorderTimeout = setTimeout(() => {
- if (this.mediaRecorder && this.mediaRecorder.state === "recording") {
- console.log("MediaRecorder备份超时机制触发,停止录制");
- this.mediaRecorder.stop();
- }
- }, 3e5);
- } catch (e) {
- console.error("开始录制失败:", e);
- }
- },
- // 添加新方法:停止录制用户回答
- stopRecordingAnswer() {
- console.log("停止录制用户回答");
- if (this.countdownTimer) {
- clearInterval(this.countdownTimer);
- this.countdownTimer = null;
- this.showCountdown = false;
- }
- const recordingDuration = this.getRecordingDuration();
- const minimumDuration = 3;
- const lowScoreDuration = 7;
- if (recordingDuration < minimumDuration) {
- common_vendor.index.showToast({
- title: "录制时间过短,请至少录制3秒",
- icon: "none",
- duration: 2e3
- });
- return;
- }
- this.completeRecordingStop();
- if (recordingDuration < lowScoreDuration) {
- console.log(`录制时间 ${recordingDuration} 秒,少于 ${lowScoreDuration} 秒,将播放低分提示视频`);
- this.needPlayLowScoreVideo = true;
- } else {
- this.needPlayLowScoreVideo = false;
- }
- },
- // 添加新方法:获取录制时长
- getRecordingDuration() {
- if (this.recordingStartTime) {
- return (Date.now() - this.recordingStartTime) / 1e3;
- }
- if (this.mediaRecorder && this.$refs.userCameraVideo) {
- return this.$refs.userCameraVideo.currentTime || 0;
- }
- if (this.recordingTimerCount) {
- return this.recordingTimerCount;
- }
- return 0;
- },
- // 添加新方法:重置录制
- resetRecording() {
- if (this.recordingTimer) {
- clearTimeout(this.recordingTimer);
- }
- this.recordingStartTime = Date.now();
- this.recordingTimerCount = 0;
- if (this.mediaRecorder && this.mediaRecorder.state !== "inactive") {
- this.mediaRecorder.stop();
- this.recordedChunks = [];
- setTimeout(() => {
- this.startBrowserRecording();
- }, 500);
- } else if (this.cameraContext) {
- this.cameraContext.stopRecord({
- success: () => {
- console.log("相机录制已停止");
- },
- fail: (err) => {
- console.error("停止相机录制失败:", err);
- }
- });
- }
- common_vendor.index.showToast({
- title: "请重新开始回答",
- icon: "none",
- duration: 2e3
- });
- },
- // 修改 completeRecordingStop 方法,确保正确处理追问问题ID
- completeRecordingStop() {
- console.log("完成录制停止");
- if (this.recordingTimer) {
- clearInterval(this.recordingTimer);
- this.recordingTimer = null;
- }
- this.finalRecordingDuration = this.recordingTimerCount;
- this.showStopRecordingButton = false;
- this.isRecording = false;
- const systemInfo = common_vendor.index.getSystemInfoSync();
- const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
- if (isMiniProgram) {
- this.stopMiniProgramRecording();
- } else {
- this.stopBrowserRecording();
- }
- if (this.isFollowUpQuestion && this.currentFollowUpQuestion) {
- console.log("当前是追问问题,记录追问问题ID:", this.currentFollowUpQuestion.id);
- this.lastQuestionWasFollowUp = true;
- this.lastFollowUpQuestionId = this.currentFollowUpQuestion.id;
- } else {
- this.lastQuestionWasFollowUp = false;
- this.lastFollowUpQuestionId = null;
- }
- },
- // 修改 stopMiniProgramRecording 方法,确保正确传递追问问题ID
- stopMiniProgramRecording() {
- console.log("停止小程序录制");
- if (!this.cameraContext) {
- console.error("相机上下文不存在");
- this.proceedToNextQuestion();
- return;
- }
- this.cameraContext.stopRecord({
- success: (res) => {
- console.log("小程序录制停止成功:", res);
- const videoPath = res.tempVideoPath;
- if (videoPath) {
- this.uploadRecordedVideo(videoPath);
- } else {
- console.error("未获取到录制视频路径");
- this.proceedToNextQuestion();
- }
- },
- fail: (err) => {
- console.error("小程序录制停止失败:", err);
- this.proceedToNextQuestion();
- }
- });
- },
- // 添加新方法:停止浏览器录制
- stopBrowserRecording() {
- if (this.mediaRecorder && this.mediaRecorder.state !== "inactive") {
- this.mediaRecorder.stop();
- console.log("浏览器录制停止成功");
- } else {
- console.error("MediaRecorder不存在或已经停止");
- this.proceedToNextQuestion();
- }
- },
- // 修改 uploadRecordedVideo 方法,添加记录父问题ID的逻辑
- uploadRecordedVideo(fileOrPath) {
- console.log("准备上传视频:", typeof fileOrPath === "string" ? fileOrPath : fileOrPath.name);
- console.log("当前问题ID:", this.currentParentQuestionId);
- console.log("当前问题类型:", this.isFollowUpQuestion);
- console.log("当前追问问题:", this.currentFollowUpQuestion);
- let questionId;
- let isFollowUpQuestionUpload = false;
- let questionText = "";
- let questionForm = 0;
- if (this.currentFollowUpQuestion && (this.currentFollowUpQuestion.question_form === 5 || this.isFollowUpQuestion)) {
- questionId = this.currentFollowUpQuestion.id;
- isFollowUpQuestionUpload = true;
- questionText = this.currentFollowUpQuestion.question || "";
- questionForm = 5;
- console.log("正在上传追问问题的回答:", {
- questionId,
- questionText,
- questionForm,
- isFollowUp: true
- });
- } else {
- const currentQuestion = this.getCurrentQuestionByIndex(this.currentVideoIndex);
- if (currentQuestion && currentQuestion.id) {
- questionId = currentQuestion.id;
- questionText = currentQuestion.question || "";
- console.log("正在上传常规问题的回答:", {
- questionId,
- questionText,
- questionForm: 0
- });
- } else {
- questionId = this.getDefaultQuestionId(this.currentVideoIndex);
- console.log("使用默认问题ID:", questionId);
- }
- }
- const uploadTask = {
- id: Date.now().toString(),
- file: fileOrPath,
- questionId,
- isFollowUp: isFollowUpQuestionUpload,
- questionText,
- questionForm,
- attempts: 0,
- maxAttempts: 3,
- parentQuestionId: this.currentParentQuestionId
- // 添加父问题ID
- };
- if (!isFollowUpQuestionUpload) {
- this.currentParentQuestionId = questionId;
- }
- this.uploadQueue.push(uploadTask);
- this.uploadProgress[uploadTask.id] = 0;
- this.uploadStatus[uploadTask.id] = "pending";
- common_vendor.index.showToast({
- title: "已完成回答",
- icon: "none",
- duration: 1500
- });
- this.updateUploadStatusText();
- if (!this.isUploading) {
- this.processUploadQueue();
- }
- this.handlePostUploadActions(uploadTask);
- },
- // 添加新方法:处理上传后的逻辑
- handlePostUploadActions(task) {
- if (this.needPlayLowScoreVideo && this.retryCount < 1) {
- this.playLowScoreVideo();
- this.needPlayLowScoreVideo = false;
- } else {
- if (task.isFollowUp) {
- console.log("追问问题回答完成,进入下一个问题");
- this.retryCount = 0;
- this.isFollowUpQuestion = false;
- this.currentFollowUpQuestion = null;
- this.proceedToNextQuestion();
- } else {
- this.currentParentQuestionId = task.questionId;
- console.log("检查常规问题的追问,父问题ID:", this.currentParentQuestionId);
- this.checkAndPlayFollowUpQuestion(this.currentParentQuestionId);
- }
- }
- },
- // 修改 processUploadQueue 方法
- processUploadQueue() {
- if (this.uploadQueue.length === 0) {
- this.isUploading = false;
- this.showUploadStatus = false;
- return;
- }
- this.isUploading = true;
- this.showUploadStatus = true;
- const task = this.uploadQueue[0];
- this.uploadStatus[task.id] = "uploading";
- this.updateUploadStatusText();
- task.attempts++;
- if (typeof task.file === "string") {
- this.uploadFileWithUni(task);
- } else {
- this.uploadFileWithXHR(task);
- }
- },
- // 添加新方法:使用XMLHttpRequest上传文件
- uploadFileWithXHR(task) {
- const userInfo = common_vendor.index.getStorageSync("userInfo");
- const openid = userInfo ? JSON.parse(userInfo).openid || "" : "";
- const tenant_id = JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || "1";
- const formData = new FormData();
- formData.append("file", task.file);
- formData.append("openid", openid);
- formData.append("tenant_id", tenant_id);
- formData.append("application_id", common_vendor.index.getStorageSync("appId"));
- formData.append("question_id", task.questionId);
- formData.append("video_duration", 0);
- formData.append("has_audio", "true");
- const xhr = new XMLHttpRequest();
- xhr.open("POST", `${common_config.apiBaseUrl}/api/upload/`, true);
- xhr.timeout = 12e4;
- xhr.upload.onprogress = (event) => {
- if (event.lengthComputable) {
- const percentComplete = Math.round(event.loaded / event.total * 100);
- this.uploadProgress[task.id] = percentComplete;
- this.updateUploadStatusText();
- }
- };
- xhr.onload = () => {
- if (xhr.status === 200) {
- try {
- const res = JSON.parse(xhr.responseText);
- console.log("上传响应:", res);
- if (res.code === 2e3) {
- const videoUrl = res.data.url || res.data.photoUrl || "";
- if (videoUrl) {
- this.uploadStatus[task.id] = "success";
- this.updateUploadStatusText();
- this.submitVideoToInterview(videoUrl, task);
- } else {
- this.handleUploadFailure(task, "视频URL获取失败");
- }
- } else {
- this.handleUploadFailure(task, res.msg || "上传失败");
- }
- } catch (e) {
- this.handleUploadFailure(task, "解析响应失败");
- }
- } else {
- this.handleUploadFailure(task, "HTTP状态: " + xhr.status);
- }
- };
- xhr.onerror = () => {
- this.handleUploadFailure(task, "网络错误");
- };
- xhr.ontimeout = () => {
- this.handleUploadFailure(task, "上传超时");
- };
- xhr.send(formData);
- },
- // 添加新方法:使用uni.uploadFile上传文件
- uploadFileWithUni(task) {
- const userInfo = common_vendor.index.getStorageSync("userInfo");
- const openid = userInfo ? JSON.parse(userInfo).openid || "" : "";
- const tenant_id = JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || "1";
- const uploadTask = common_vendor.index.uploadFile({
- url: `${common_config.apiBaseUrl}/api/upload/`,
- filePath: task.file,
- name: "file",
- formData: {
- openid,
- tenant_id,
- application_id: common_vendor.index.getStorageSync("appId"),
- question_id: task.questionId,
- video_duration: 0,
- has_audio: "true"
- },
- success: (uploadRes) => {
- try {
- const res = JSON.parse(uploadRes.data);
- console.log("上传响应:", res);
- if (res.code === 2e3) {
- const videoUrl = res.data.permanent_link || res.data.url || "";
- if (videoUrl) {
- this.uploadStatus[task.id] = "success";
- this.updateUploadStatusText();
- this.submitVideoToInterview(videoUrl, task);
- } else {
- this.handleUploadFailure(task, "视频URL获取失败");
- }
- } else {
- this.handleUploadFailure(task, res.msg || "上传失败");
- }
- } catch (e) {
- this.handleUploadFailure(task, "解析响应失败");
- }
- },
- fail: (err) => {
- this.handleUploadFailure(task, err.errMsg || "上传失败");
- }
- });
- uploadTask.onProgressUpdate((res) => {
- this.uploadProgress[task.id] = res.progress;
- this.updateUploadStatusText();
- });
- },
- // 添加新方法:处理上传失败
- handleUploadFailure(task, errorMsg) {
- console.error("上传失败:", errorMsg);
- this.uploadStatus[task.id] = "failed";
- this.updateUploadStatusText();
- if (task.attempts < task.maxAttempts) {
- console.log(`将在5秒后重试上传,当前尝试次数: ${task.attempts}/${task.maxAttempts}`);
- setTimeout(() => {
- this.uploadProgress[task.id] = 0;
- if (typeof task.file !== "string") {
- this.uploadFileWithXHR(task);
- } else {
- this.uploadFileWithUni(task);
- }
- }, 5e3);
- } else {
- console.log("超过最大重试次数,放弃上传");
- common_vendor.index.showToast({
- title: "视频上传失败,请稍后重试",
- icon: "none",
- duration: 2e3
- });
- this.uploadQueue.shift();
- this.processUploadQueue();
- }
- },
- // 修改 submitVideoToInterview 方法
- submitVideoToInterview(videoUrl, task) {
- const requestData = {
- application_id: common_vendor.index.getStorageSync("appId"),
- question_id: task.questionId,
- video_url: videoUrl,
- tenant_id: JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || "1",
- is_follow_up: task.isFollowUp ? 1 : 0,
- question_form: task.questionForm,
- question_text: task.questionText
- };
- common_vendor.index.request({
- url: `${common_config.apiBaseUrl}/api/job/upload_video`,
- method: "POST",
- data: requestData,
- header: {
- "content-type": "application/x-www-form-urlencoded"
- },
- success: (res) => {
- if (res.data.code === 200 || res.data.code === 2e3) {
- this.uploadQueue.shift();
- this.processUploadQueue();
- } else {
- this.handleUploadError(task, "提交失败: " + (res.data.msg || "未知错误"));
- }
- },
- fail: (err) => {
- this.handleUploadError(task, "网络错误: " + err.errMsg);
- }
- });
- },
- // 添加新方法:处理提交失败
- handleSubmitFailure(task, errorMsg) {
- console.error("提交失败:", errorMsg);
- this.uploadStatus[task.id] = "failed";
- this.updateUploadStatusText();
- if (task.attempts < task.maxAttempts) {
- console.log(`将在5秒后重试提交,当前尝试次数: ${task.attempts}/${task.maxAttempts}`);
- setTimeout(() => {
- this.submitVideoToInterview(task.videoUrl, task);
- }, 5e3);
- } else {
- console.log("超过最大重试次数,放弃提交");
- common_vendor.index.showToast({
- title: "视频提交失败,请稍后重试",
- icon: "none",
- duration: 2e3
- });
- this.uploadQueue.shift();
- this.processUploadQueue();
- }
- },
- // 添加新方法:更新上传状态文本
- updateUploadStatusText() {
- if (this.uploadQueue.length === 0) {
- this.uploadStatusText = "";
- return;
- }
- const currentTask = this.uploadQueue[0];
- const progress = this.uploadProgress[currentTask.id] || 0;
- const status = this.uploadStatus[currentTask.id] || "pending";
- let statusText = "";
- switch (status) {
- case "pending":
- statusText = "等待上传";
- break;
- case "uploading":
- statusText = `上传中 ${progress}%`;
- break;
- case "success":
- statusText = "上传成功,提交中...";
- break;
- case "failed":
- statusText = `上传失败,${currentTask.attempts < currentTask.maxAttempts ? "即将重试" : "已放弃"}`;
- break;
- }
- const questionTypeText = currentTask.isFollowUp ? "追问" : "问题";
- const questionShortText = currentTask.questionText ? currentTask.questionText.length > 10 ? currentTask.questionText.substring(0, 10) + "..." : currentTask.questionText : `${questionTypeText}${currentTask.questionId}`;
- this.uploadStatusText = `${questionTypeText}「${questionShortText}」:${statusText}`;
- if (this.uploadQueue.length > 1) {
- this.uploadStatusText += ` (${this.uploadQueue.length}个视频待处理)`;
- }
- },
- // 修改 proceedToNextQuestion 方法,确保在切换视频时重置历史时间
- proceedToNextQuestion() {
- console.log("继续下一个问题");
- this.currentVideoIndex++;
- this.historyTime = 0;
- if (this.currentVideoIndex < this.videoList.length) {
- this.videoUrl = this.videoList[this.currentVideoIndex];
- this.videoPlaying = true;
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.play();
- }
- });
- } else {
- console.log("所有视频已播放完毕");
- this.stopUserCamera();
- this.clearCountdown();
- setTimeout(() => {
- common_vendor.index.navigateTo({
- url: "/pages/camera/camera",
- success: () => {
- console.log("成功跳转到camera页面");
- },
- fail: (err) => {
- console.error("跳转到camera页面失败:", err);
- common_vendor.index.redirectTo({
- url: "/pages/camera/camera",
- fail: (redirectErr) => {
- console.error("重定向到camera页面也失败:", redirectErr);
- common_vendor.index.switchTab({
- url: "/pages/camera/camera",
- fail: (switchErr) => {
- console.error("所有跳转方式都失败:", switchErr);
- common_vendor.index.navigateBack({
- delta: 1
- });
- }
- });
- }
- });
- }
- });
- }, 2e3);
- }
- },
- // 修改 handleAnswerButtonClick 方法,确保在切换视频时重置历史时间
- handleAnswerButtonClick() {
- console.log("点击开始回答按钮");
- this.showAnswerButton = false;
- this.currentVideoIndex++;
- this.historyTime = 0;
- if (this.currentVideoIndex < this.videoList.length) {
- this.videoUrl = this.videoList[this.currentVideoIndex];
- this.videoPlaying = true;
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.play();
- }
- });
- }
- },
- // 处理相机错误
- handleCameraError(e) {
- console.error("相机错误:", e);
- const systemInfo = common_vendor.index.getSystemInfoSync();
- const isIOS = systemInfo.platform === "ios";
- if (isIOS) {
- console.log("iOS相机错误,尝试重新初始化");
- common_vendor.index.showToast({
- title: "相机初始化中...",
- icon: "loading",
- duration: 2e3
- });
- this.resetCamera();
- if (this.isRecording) {
- this.isRecording = false;
- this.showStopRecordingButton = false;
- setTimeout(() => {
- this.useAlternativeRecordingMethod();
- }, 1e3);
- }
- } else {
- common_vendor.index.showToast({
- title: "相机初始化失败,请检查权限设置",
- icon: "none"
- });
- this.tryFallbackOptions();
- }
- },
- // 添加新方法:尝试备用选项
- tryFallbackOptions() {
- const systemInfo = common_vendor.index.getSystemInfoSync();
- if (systemInfo.uniPlatform === "mp-weixin" || systemInfo.uniPlatform === "mp-alipay") {
- this.useMiniProgramCamera();
- } else {
- this.showStaticCameraPlaceholder();
- }
- },
- // 添加新方法:使用小程序相机API
- useMiniProgramCamera() {
- console.log("尝试使用小程序相机组件");
- this.useMiniProgramCameraComponent = true;
- },
- // 添加新方法:显示静态图像
- showStaticCameraPlaceholder() {
- console.log("显示静态摄像头占位图");
- const img = document.createElement("img");
- img.src = "/static/images/camera-placeholder.png";
- img.className = "static-camera-image";
- img.style.width = "100%";
- img.style.height = "100%";
- img.style.objectFit = "cover";
- const container = this.$refs.userCameraVideo.parentNode;
- container.appendChild(img);
- },
- // 修改 handleTimeUpdate 方法
- handleTimeUpdate(e) {
- const currentTime = e.detail.currentTime || e.target.currentTime;
- if (this.isRecording && this.recordingTimerCount) {
- this.recordingTimeDisplay = this.formatTime(this.recordingTimerCount);
- }
- if (this.isPlayingLowScoreVideo) {
- if (this.lowScoreVideoSubtitles && this.lowScoreVideoSubtitles.length > 0) {
- const subtitle = this.lowScoreVideoSubtitles[0];
- this.currentSubtitle = subtitle.text;
- }
- return;
- }
- let currentSubtitles = null;
- if (this.isFollowUpQuestion && this.currentFollowUpQuestion) {
- const subtitleKey = `followUpSubtitles_${this.currentFollowUpQuestion.id}`;
- currentSubtitles = this[subtitleKey] || [{
- startTime: 0,
- endTime: 30,
- text: this.currentFollowUpQuestion.digital_human_video_subtitle || this.currentFollowUpQuestion.question
- }];
- } else {
- if (this.currentVideoIndex === 0) {
- currentSubtitles = this.subtitles;
- } else {
- const subtitleArrayName = `question${this.currentVideoIndex}Subtitles`;
- currentSubtitles = this[subtitleArrayName];
- }
- }
- if (currentSubtitles && currentSubtitles.length > 0) {
- const subtitle = currentSubtitles.find(
- (sub) => currentTime >= sub.startTime && currentTime <= sub.endTime
- ) || currentSubtitles[0];
- if (subtitle) {
- this.currentSubtitle = subtitle.text;
- }
- }
- this.historyTime = currentTime;
- this.lastUpdateTime = Date.now();
- },
- // Add a new method to handle the "Start Recording" button click
- handleStartRecordingClick() {
- this.showStartRecordingButton = false;
- this.clearCountdown();
- this.startRecordingAnswer();
- },
- // 修改 checkAudioPermission 方法,确保在录制前获取音频权限
- checkAudioPermission() {
- const systemInfo = common_vendor.index.getSystemInfoSync();
- const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
- if (isMiniProgram) {
- common_vendor.index.getSetting({
- success: (res) => {
- if (!res.authSetting["scope.record"]) {
- common_vendor.index.authorize({
- scope: "scope.record",
- success: () => {
- console.log("录音权限已获取");
- },
- fail: (err) => {
- console.error("录音权限获取失败:", err);
- this.showPermissionDialog("录音");
- }
- });
- }
- if (!res.authSetting["scope.camera"]) {
- common_vendor.index.authorize({
- scope: "scope.camera",
- success: () => {
- console.log("相机权限已获取");
- },
- fail: (err) => {
- console.error("相机权限获取失败:", err);
- this.showPermissionDialog("相机");
- }
- });
- }
- }
- });
- }
- },
- // 添加新方法:测试音频输入
- testAudioInput() {
- if (!this.cameraStream) {
- console.warn("没有可用的媒体流,无法测试音频");
- return;
- }
- const audioTracks = this.cameraStream.getAudioTracks();
- if (audioTracks.length === 0) {
- console.warn("没有检测到音频轨道,尝试重新获取");
- this.tryGetAudioOnly();
- return;
- }
- console.log("音频轨道信息:", audioTracks[0].getSettings());
- try {
- const AudioContext = window.AudioContext || window.webkitAudioContext;
- if (!AudioContext) {
- console.warn("浏览器不支持AudioContext");
- return;
- }
- const audioContext = new AudioContext();
- const analyser = audioContext.createAnalyser();
- const microphone = audioContext.createMediaStreamSource(this.cameraStream);
- microphone.connect(analyser);
- analyser.fftSize = 256;
- const bufferLength = analyser.frequencyBinCount;
- const dataArray = new Uint8Array(bufferLength);
- let silenceCounter = 0;
- const checkAudio = () => {
- if (this.isRecording)
- return;
- analyser.getByteFrequencyData(dataArray);
- let sum = 0;
- for (let i = 0; i < bufferLength; i++) {
- sum += dataArray[i];
- }
- const average = sum / bufferLength;
- if (average > 10) {
- console.log("检测到音频输入,音量:", average);
- silenceCounter = 0;
- } else {
- silenceCounter++;
- if (silenceCounter > 10) {
- console.warn("持续检测不到音频输入,可能麦克风未正常工作");
- silenceCounter = 0;
- }
- }
- requestAnimationFrame(checkAudio);
- };
- checkAudio();
- } catch (e) {
- console.error("音频测试失败:", e);
- }
- },
- // 添加新方法:尝试单独获取音频
- tryGetAudioOnly() {
- navigator.mediaDevices.getUserMedia({ audio: true }).then((audioStream) => {
- if (this.cameraStream) {
- const videoTrack = this.cameraStream.getVideoTracks()[0];
- const audioTrack = audioStream.getAudioTracks()[0];
- const combinedStream = new MediaStream();
- if (videoTrack)
- combinedStream.addTrack(videoTrack);
- if (audioTrack)
- combinedStream.addTrack(audioTrack);
- this.cameraStream = combinedStream;
- const videoElement = this.$refs.userCameraVideo;
- if (videoElement) {
- videoElement.srcObject = combinedStream;
- videoElement.muted = true;
- }
- console.log("成功合并音频和视频轨道");
- } else {
- console.warn("没有视频流可合并");
- }
- }).catch((err) => {
- console.error("单独获取音频失败:", err);
- });
- },
- // 添加新方法:显示权限对话框
- showPermissionDialog(permissionType) {
- common_vendor.index.showModal({
- title: "需要权限",
- content: `请允许使用${permissionType}权限,否则可能影响面试功能`,
- confirmText: "去设置",
- success: (res) => {
- if (res.confirm) {
- common_vendor.index.openSetting({
- success: (settingRes) => {
- console.log("设置页面打开成功", settingRes);
- }
- });
- }
- }
- });
- },
- // 添加重试上传方法
- retryVideoUpload() {
- if (this.lastVideoToRetry) {
- this.showRetryButton = false;
- common_vendor.index.showLoading({
- title: "正在重新提交...",
- mask: true
- });
- this.submitVideoToInterview(this.lastVideoToRetry);
- } else {
- common_vendor.index.showToast({
- title: "没有可重试的视频",
- icon: "none"
- });
- }
- },
- // 添加一个新方法用于压缩视频
- async compressVideo(videoBlob) {
- if (videoBlob.size < 5 * 1024 * 1024) {
- return videoBlob;
- }
- console.log("开始压缩视频,原始大小:", videoBlob.size);
- const videoElement = document.createElement("video");
- videoElement.muted = true;
- videoElement.autoplay = false;
- const canvas = document.createElement("canvas");
- const ctx = canvas.getContext("2d");
- videoElement.src = URL.createObjectURL(videoBlob);
- return new Promise((resolve) => {
- videoElement.onloadedmetadata = () => {
- const width = Math.floor(videoElement.videoWidth / 2);
- const height = Math.floor(videoElement.videoHeight / 2);
- canvas.width = width;
- canvas.height = height;
- const stream = canvas.captureStream(15);
- if (videoElement.captureStream) {
- const originalStream = videoElement.captureStream();
- const audioTracks = originalStream.getAudioTracks();
- if (audioTracks.length > 0) {
- stream.addTrack(audioTracks[0]);
- }
- }
- const options = {
- mimeType: "video/webm;codecs=vp8,opus",
- audioBitsPerSecond: 64e3,
- videoBitsPerSecond: 8e5
- // 800kbps
- };
- const mediaRecorder = new MediaRecorder(stream, options);
- const chunks = [];
- mediaRecorder.ondataavailable = (e) => {
- if (e.data.size > 0) {
- chunks.push(e.data);
- }
- };
- mediaRecorder.onstop = () => {
- const compressedBlob = new Blob(chunks, { type: "video/webm" });
- console.log("视频压缩完成,压缩后大小:", compressedBlob.size);
- resolve(compressedBlob);
- };
- videoElement.onplay = () => {
- mediaRecorder.start(10);
- const drawFrame = () => {
- if (videoElement.paused || videoElement.ended) {
- mediaRecorder.stop();
- return;
- }
- ctx.drawImage(videoElement, 0, 0, width, height);
- requestAnimationFrame(drawFrame);
- };
- drawFrame();
- };
- videoElement.play();
- };
- });
- },
- // 修改 checkIOSCameraRecordPermission 方法
- checkIOSCameraRecordPermission() {
- const systemInfo = common_vendor.index.getSystemInfoSync();
- if (systemInfo.platform !== "ios")
- return;
- common_vendor.index.getSetting({
- success: (res) => {
- if (!res.authSetting["scope.camera"]) {
- common_vendor.index.authorize({
- scope: "scope.camera",
- success: () => {
- console.log("iOS相机权限已获取");
- },
- fail: (err) => {
- console.error("iOS相机权限获取失败:", err);
- this.showPermissionDialog("相机");
- }
- });
- }
- if (!res.authSetting["scope.record"]) {
- common_vendor.index.authorize({
- scope: "scope.record",
- success: () => {
- console.log("iOS录音权限已获取");
- },
- fail: (err) => {
- console.error("iOS录音权限获取失败:", err);
- this.showPermissionDialog("录音");
- }
- });
- }
- }
- });
- },
- // 添加新方法:检查并修复渲染问题
- checkAndFixRenderingIssues() {
- try {
- if (typeof u !== "undefined" && u) {
- if (!u.currentQuestion) {
- console.log("修复: 创建缺失的currentQuestion对象");
- u.currentQuestion = {};
- }
- if (u.currentQuestion && typeof u.currentQuestion.isImportant === "undefined") {
- console.log("修复: 设置缺失的isImportant属性");
- u.currentQuestion.isImportant = false;
- }
- }
- } catch (e) {
- console.log("防御性检查异常:", e);
- }
- },
- // 添加格式化时间的辅助方法
- formatTime(seconds) {
- if (!seconds && seconds !== 0)
- return "03:30";
- const minutes = Math.floor(seconds / 60);
- const remainingSeconds = seconds % 60;
- return `${minutes.toString().padStart(2, "0")}:${remainingSeconds.toString().padStart(2, "0")}`;
- },
- // 添加获取问题数据的方法
- fetchQuestions() {
- this.loading = true;
- const tenant_id = JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || "1";
- let position_id = 1;
- try {
- const selectedJob = JSON.parse(common_vendor.index.getStorageSync("selectedJob") || "{}");
- if (selectedJob && selectedJob.id) {
- position_id = selectedJob.id;
- console.log("使用选择的职位ID获取问题:", position_id);
- } else {
- console.warn("未找到选择的职位信息,使用默认职位ID:", position_id);
- }
- } catch (e) {
- console.error("解析职位信息失败:", e);
- }
- const timestamp = Date.now();
- const requestUrl = `${common_config.apiBaseUrl}/api/wechat/open_questions/?position_id=${position_id}&tenant_id=${tenant_id}&question_form=0&_t=${timestamp}`;
- console.log("完整的请求URL:", requestUrl);
- common_vendor.index.request({
- url: requestUrl,
- method: "GET",
- success: (res) => {
- if (res.data && res.data.code === 2e3 && res.data.data && res.data.data.items) {
- console.log("获取问题数据成功:", res.data.data.items);
- this.questions = res.data.data.items;
- this.processQuestionData();
- this.playIntroVideo();
- } else {
- console.error("获取问题数据失败:", res.data);
- common_vendor.index.showToast({
- title: "获取问题数据失败",
- icon: "none"
- });
- }
- },
- fail: (err) => {
- console.error("请求问题数据失败:", err);
- common_vendor.index.showToast({
- title: "网络错误,请检查网络连接",
- icon: "none"
- });
- },
- complete: () => {
- this.loading = false;
- }
- });
- },
- // 处理问题数据,提取视频URL和字幕
- processQuestionData() {
- this.videoList = [];
- this.videoList.push(this.introVideoUrl);
- this.subtitles = [
- {
- startTime: 0,
- endTime: 5,
- text: "你好,我是本次面试的面试官,欢迎参加本公司的线上面试!"
- },
- {
- startTime: 5,
- endTime: 13,
- text: "面试预计需要15分钟,请你提前安排在网络良好、光线亮度合适、且相对安静的环境参加这次面试"
- },
- {
- startTime: 13,
- endTime: 20,
- text: "以免影响本次面试的结果。如果你在面试过程中遇到问题,请与我们的招聘人员联系。"
- }
- ];
- const sortedQuestions = [...this.questions].sort((a, b) => a.sequence_number - b.sequence_number);
- const questionsToUse = sortedQuestions.slice(0, 5);
- questionsToUse.forEach((question, index) => {
- if (question.digital_human_video_url) {
- this.videoList.push(question.digital_human_video_url);
- const subtitleArray = [{
- startTime: 0,
- endTime: 30,
- // 延长字幕显示时间到30秒
- text: question.digital_human_video_subtitle || question.question
- }];
- const videoIndex = this.videoList.length - 1;
- this[`question${videoIndex}Subtitles`] = subtitleArray;
- this.subtitleMap[question.digital_human_video_url] = subtitleArray;
- }
- });
- if (this.videoList.length <= 1)
- ;
- else {
- console.log("处理后的视频列表:", this.videoList);
- console.log("处理后的字幕:", this.subtitles);
- }
- },
- // 使用默认视频和字幕(作为备用)
- useDefaultVideosAndSubtitles() {
- console.log("使用默认视频和字幕");
- this.subtitles = [
- {
- startTime: 0,
- endTime: 5,
- text: "你好,我是本次面试的面试官,欢迎参加本公司的线上面试!"
- },
- {
- startTime: 5,
- endTime: 13,
- text: "面试预计需要15分钟,请你提前安排在网络良好、光线亮度合适、且相对安静的环境参加这次面试"
- },
- {
- startTime: 13,
- endTime: 20,
- text: "以免影响本次面试的结果。如果你在面试过程中遇到问题,请与我们的招聘人员联系。"
- }
- ];
- this.question1Subtitles = [{
- startTime: 0,
- endTime: 10,
- text: "请结合您的基本信息与过往履历进行简单的自我介绍,并讲一讲您有哪些优势胜任本岗位:"
- }];
- this.question2Subtitles = [{
- startTime: 0,
- endTime: 4,
- text: "在工作中,你如何确保个人防护装备的正确使用?"
- }];
- this.question3Subtitles = [{
- startTime: 0,
- endTime: 4,
- text: "描述一次你与团队合作改善生产流程的经历。"
- }];
- this.question4Subtitles = [{
- startTime: 0,
- endTime: 6,
- text: "你在团队合作中曾遇到过哪些挑战?如何解决团队内部的分歧?"
- }];
- this.question5Subtitles = [{
- startTime: 0,
- endTime: 5,
- text: "您已完成本次面试全部题目,请问您对于这个岗位还有什么想要了解的吗?"
- }];
- },
- // 播放介绍视频
- playIntroVideo() {
- this.videoUrl = this.videoList[0];
- this.videoPlaying = true;
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.play();
- }
- });
- },
- // 添加新方法:获取默认问题ID
- getDefaultQuestionId(videoIndex) {
- switch (videoIndex) {
- case 1:
- return 10;
- case 2:
- return 11;
- case 3:
- return 12;
- case 4:
- return 13;
- default:
- return 10;
- }
- },
- // 添加新方法:根据索引获取当前问题
- getCurrentQuestionByIndex(videoIndex) {
- const questionIndex = videoIndex - 1;
- const sortedQuestions = [...this.questions].sort((a, b) => a.sequence_number - b.sequence_number);
- if (questionIndex >= 0 && questionIndex < sortedQuestions.length) {
- return sortedQuestions[questionIndex];
- }
- return null;
- },
- onShow() {
- console.log("identity-verify页面onShow");
- console.log("当前本地存储中的职位信息:", common_vendor.index.getStorageSync("selectedJob"));
- this.fetchQuestions();
- this.fetchFollowUpQuestions();
- },
- // 添加新方法:重置录制状态,准备重新回答
- resetForRerecording() {
- console.log("重置录制状态,准备重新回答");
- this.isRecording = false;
- this.showStopRecordingButton = false;
- this.showStartRecordingButton = true;
- this.clearCountdown();
- if (this.recordingTimer) {
- clearInterval(this.recordingTimer);
- this.recordingTimer = null;
- }
- this.recordingTimerCount = 0;
- this.recordingTimeDisplay = "00:00 / 05:00";
- this.remainingTime = this.maxRecordingTime;
- if (this.mediaRecorder && this.mediaRecorder.state !== "inactive") {
- this.mediaRecorder.stop();
- this.recordedChunks = [];
- }
- if (this.cameraContext) {
- this.cameraContext.stopRecord({
- success: () => {
- console.log("相机录制已停止");
- },
- fail: (err) => {
- console.error("停止相机录制失败:", err);
- }
- });
- }
- },
- // 修改 playLowScoreVideo 方法,优化字幕显示
- playLowScoreVideo() {
- console.log("播放低分提示视频");
- this.isPlayingLowScoreVideo = true;
- this.showStartRecordingButton = false;
- this.showStopRecordingButton = false;
- this.showRerecordButton = false;
- this.videoUrl = this.lowScoreVideoUrl;
- this.videoPlaying = true;
- this.currentSubtitle = "";
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.play();
- setTimeout(() => {
- this.currentSubtitle = "我未听清楚您在说什么,请您再说一遍!";
- this.lowScoreVideoSubtitles = [
- {
- startTime: 0,
- endTime: 30,
- // 假设视频长度为10秒,可根据实际情况调整
- text: "我未听清楚您在说什么,请您再说一遍!",
- translation: "I didn't quite catch what you said, could you please repeat it?"
- }
- ];
- }, 500);
- }
- });
- },
- // 添加新方法:处理重新录制按钮点击
- handleRerecordButtonClick() {
- console.log("点击重新录制按钮");
- this.retryCount++;
- console.log(`当前重试次数: ${this.retryCount}/${this.maxRetryAttempts}`);
- this.showRerecordButton = false;
- this.handleStartRecordingClick();
- },
- // 添加 onUnload 生命周期钩子,移除 WebSocket 关闭
- onUnload() {
- console.log("页面卸载");
- },
- // 修改 onHide 生命周期钩子,移除 WebSocket 关闭
- onHide() {
- console.log("页面隐藏");
- },
- // 添加新方法:阻止视频控制
- preventVideoControl(e) {
- e.preventDefault();
- e.stopPropagation();
- console.log("阻止视频控制操作");
- return false;
- },
- // 添加获取追问问题的方法
- fetchFollowUpQuestions() {
- const tenant_id = JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || "1";
- let position_id = 1;
- try {
- const selectedJob = JSON.parse(common_vendor.index.getStorageSync("selectedJob") || "{}");
- if (selectedJob && selectedJob.id) {
- position_id = selectedJob.id;
- console.log("使用选择的职位ID获取追问问题:", position_id);
- } else {
- console.warn("未找到选择的职位信息,使用默认职位ID:", position_id);
- }
- } catch (e) {
- console.error("解析职位信息失败:", e);
- }
- const timestamp = Date.now();
- const requestUrl = `${common_config.apiBaseUrl}/api/wechat/open_questions/?position_id=${position_id}&tenant_id=${tenant_id}&question_form=5&_t=${timestamp}`;
- console.log("获取追问问题的请求URL:", requestUrl);
- common_vendor.index.request({
- url: requestUrl,
- method: "GET",
- success: (res) => {
- if (res.data && res.data.code === 2e3 && res.data.data && res.data.data.items) {
- console.log("获取追问问题数据成功:", res.data.data.items);
- this.followUpQuestions = res.data.data.items.map((item) => ({
- ...item,
- question_form: 5
- // 确保每个追问问题都有正确的question_form值
- }));
- this.processFollowUpQuestions();
- } else {
- console.error("获取追问问题数据失败:", res.data);
- this.followUpQuestions = [];
- }
- },
- fail: (err) => {
- console.error("请求追问问题数据失败:", err);
- this.followUpQuestions = [];
- }
- });
- },
- // 改进处理追问问题数据的方法
- processFollowUpQuestions() {
- if (!this.followUpQuestions || this.followUpQuestions.length === 0) {
- console.log("没有追问问题数据");
- this.followUpQuestions = [];
- return;
- }
- console.log("处理追问问题数据,总数:", this.followUpQuestions.length);
- this.followUpQuestions = this.followUpQuestions.filter((q) => q.parent_question_id);
- const parentQuestionIds = /* @__PURE__ */ new Set();
- this.followUpQuestions.forEach((question) => {
- if (question.parent_question_id) {
- parentQuestionIds.add(question.parent_question_id);
- }
- });
- console.log("有追问的父问题ID:", Array.from(parentQuestionIds));
- this.hasPlayedFollowUp = {};
- },
- // 添加新方法:检查并播放追问问题
- checkAndPlayFollowUpQuestion(parentQuestionId) {
- console.log("检查是否有追问问题,父问题ID:", parentQuestionId);
- if (!parentQuestionId) {
- console.warn("没有父问题ID,无法检查追问问题");
- this.proceedToNextQuestion();
- return;
- }
- if (this.hasPlayedFollowUp[parentQuestionId]) {
- console.log("已经播放过此问题的追问,直接进入下一个问题");
- this.retryCount = 0;
- this.proceedToNextQuestion();
- return;
- }
- const followUpQuestion = this.followUpQuestions.find(
- (q) => q.parent_question_id === parentQuestionId && q.digital_human_video_url && q.question_form === 5
- );
- if (followUpQuestion) {
- console.log("找到追问问题:", followUpQuestion);
- this.hasPlayedFollowUp[parentQuestionId] = true;
- this.isFollowUpQuestion = true;
- this.currentParentQuestionId = parentQuestionId;
- this.currentFollowUpQuestion = followUpQuestion;
- this.playFollowUpQuestionVideo(followUpQuestion);
- } else {
- console.log("没有找到对应的追问问题,继续下一个问题");
- this.retryCount = 0;
- this.proceedToNextQuestion();
- }
- },
- // 添加新方法:播放追问问题视频
- playFollowUpQuestionVideo(followUpQuestion) {
- console.log("播放追问问题视频:", followUpQuestion.digital_human_video_url);
- this.videoUrl = followUpQuestion.digital_human_video_url;
- this.videoPlaying = true;
- const followUpSubtitles = [{
- startTime: 0,
- endTime: 60,
- // 延长显示时间到60秒
- text: followUpQuestion.digital_human_video_subtitle || followUpQuestion.question
- }];
- const subtitleKey = `followUpSubtitles_${followUpQuestion.id}`;
- this[subtitleKey] = followUpSubtitles;
- this.$nextTick(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo", this);
- if (videoContext) {
- videoContext.play();
- this.currentSubtitle = followUpSubtitles[0].text;
- }
- });
- }
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: $data.videoUrl,
- b: common_vendor.o((...args) => $options.handleVideoError && $options.handleVideoError(...args)),
- c: common_vendor.o((...args) => $options.handleVideoEnded && $options.handleVideoEnded(...args)),
- d: common_vendor.o((...args) => $options.handleTimeUpdate && $options.handleTimeUpdate(...args)),
- e: common_vendor.o((...args) => $options.preventVideoControl && $options.preventVideoControl(...args)),
- f: common_vendor.o((...args) => $options.preventVideoControl && $options.preventVideoControl(...args)),
- g: $data.showAnswerButton
- }, $data.showAnswerButton ? {
- h: common_vendor.o((...args) => $options.handleAnswerButtonClick && $options.handleAnswerButtonClick(...args))
- } : {}, {
- i: $data.currentSubtitle
- }, $data.currentSubtitle ? {
- j: common_vendor.t($data.currentSubtitle)
- } : {}, {
- k: $data.useMiniProgramCameraComponent
- }, $data.useMiniProgramCameraComponent ? {
- l: common_vendor.o((...args) => $options.handleCameraError && $options.handleCameraError(...args))
- } : {}, {
- m: $data.loading
- }, $data.loading ? {} : {}, {
- n: $data.showDebugInfo
- }, $data.showDebugInfo ? common_vendor.e({
- o: $data.assistantResponse
- }, $data.assistantResponse ? {
- p: common_vendor.t($data.assistantResponse)
- } : {}, {
- q: $data.audioTranscript
- }, $data.audioTranscript ? {
- r: common_vendor.t($data.audioTranscript)
- } : {}, {
- s: common_vendor.f($data.processedResponses, (item, index, i0) => {
- return common_vendor.e({
- a: item.role
- }, item.role ? {
- b: common_vendor.t(item.role)
- } : {}, {
- c: item.transcript
- }, item.transcript ? {
- d: common_vendor.t(item.transcript)
- } : {}, {
- e: index
- });
- })
- }) : {}, {
- t: $data.showStopRecordingButton
- }, $data.showStopRecordingButton ? {
- v: common_vendor.o((...args) => $options.stopRecordingAnswer && $options.stopRecordingAnswer(...args))
- } : {}, {
- w: $data.isRecording
- }, $data.isRecording ? {
- x: common_vendor.t($data.recordingTimeDisplay || "00:00 / 05:00")
- } : {}, {
- y: $data.showStartRecordingButton
- }, $data.showStartRecordingButton ? {
- z: common_vendor.o((...args) => $options.handleStartRecordingClick && $options.handleStartRecordingClick(...args))
- } : {}, {
- A: $data.showRetryButton
- }, $data.showRetryButton ? {
- B: common_vendor.o((...args) => $options.retryVideoUpload && $options.retryVideoUpload(...args))
- } : {}, {
- C: $data.showCountdown
- }, $data.showCountdown ? {
- D: common_vendor.t($data.countdownValue)
- } : {}, {
- E: $data.showRerecordButton
- }, $data.showRerecordButton ? {
- F: common_vendor.o((...args) => $options.handleRerecordButtonClick && $options.handleRerecordButtonClick(...args))
- } : {});
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-464e78c6"]]);
- wx.createPage(MiniProgramPage);
|