|
@@ -330,6 +330,10 @@ export default {
|
|
|
subtitleText: '', // 字幕文本
|
|
|
isAudioPlaying: false,
|
|
|
isWaitingForAnswer: false, // 添加新的状态来控制是否在等待用户回答
|
|
|
+ currentRecordingDuration: 0, // 添加当前录制时长
|
|
|
+ parentJobPositionQuestionId: null, // 添加父问题的job_position_question_id
|
|
|
+ isFollowUpMode: false, // 是否处于追问模式
|
|
|
+ mainQuestionIndex: 0, // 当前主问题的索引
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|
|
@@ -433,6 +437,8 @@ export default {
|
|
|
|
|
|
// 处理追问问题
|
|
|
async handleFollowUpQuestion(questionData) {
|
|
|
+ console.log('处理追问:', questionData);
|
|
|
+ this.enterFollowUpMode();
|
|
|
console.log('处理追问问题数据:', questionData);
|
|
|
|
|
|
// 检查数据完整性
|
|
@@ -526,6 +532,7 @@ export default {
|
|
|
async callInterviewInteraction(questionId) {
|
|
|
const userInfo = JSON.parse(uni.getStorageSync('userInfo'));
|
|
|
const appId = uni.getStorageSync('appId');
|
|
|
+ const positionConfigId = JSON.parse(uni.getStorageSync('configData')).id;
|
|
|
|
|
|
try {
|
|
|
console.log('开始调用面试互动接口', { questionId, appId });
|
|
@@ -535,7 +542,7 @@ export default {
|
|
|
data: {
|
|
|
tenant_id: userInfo.tenant_id || 1,
|
|
|
question_id: questionId,
|
|
|
- position_config_id: 6,
|
|
|
+ position_config_id: positionConfigId,
|
|
|
application_id: appId
|
|
|
},
|
|
|
header: {
|
|
@@ -726,7 +733,7 @@ export default {
|
|
|
|
|
|
// 设置等待回答状态
|
|
|
this.isWaitingForAnswer = true;
|
|
|
- // 显示开始作答按钮和倒计时
|
|
|
+ // 显示开始回答按钮和倒计时
|
|
|
this.handleAudioEnd();
|
|
|
},
|
|
|
// 初始化相机
|
|
@@ -1428,14 +1435,14 @@ export default {
|
|
|
// 重置等待回答状态
|
|
|
this.isWaitingForAnswer = false;
|
|
|
|
|
|
- // 重置等待回答状态
|
|
|
- this.isWaitingForAnswer = false;
|
|
|
-
|
|
|
// 检查录制时长
|
|
|
const recordingDuration = this.getRecordingDuration();
|
|
|
const minimumDuration = 3; // 最小录制时长(秒),改为3秒
|
|
|
const lowScoreDuration = 7; // 低分阈值时长(秒),少于7秒视为低分
|
|
|
|
|
|
+ // 保存录制时长,用于上传
|
|
|
+ this.currentRecordingDuration = recordingDuration;
|
|
|
+
|
|
|
if (recordingDuration < minimumDuration) {
|
|
|
// 录制时间过短,显示提示
|
|
|
uni.showToast({
|
|
@@ -2156,7 +2163,8 @@ export default {
|
|
|
questionForm: questionForm,
|
|
|
attempts: 0,
|
|
|
maxAttempts: 3,
|
|
|
- parentQuestionId: this.currentParentQuestionId
|
|
|
+ parentQuestionId: this.currentParentQuestionId,
|
|
|
+ videoDuration: this.currentRecordingDuration || 0 // 添加视频时长
|
|
|
};
|
|
|
|
|
|
// 如果不是追问问题,记录当前问题ID作为父问题ID
|
|
@@ -2274,7 +2282,7 @@ export default {
|
|
|
formData.append('tenant_id', tenant_id);
|
|
|
formData.append('application_id', uni.getStorageSync('appId'));
|
|
|
formData.append('question_id', task.questionId);
|
|
|
- formData.append('video_duration', 0);
|
|
|
+ formData.append('video_duration', task.videoDuration);
|
|
|
formData.append('has_audio', 'true');
|
|
|
|
|
|
// 创建XMLHttpRequest
|
|
@@ -2450,55 +2458,111 @@ export default {
|
|
|
console.log('提交视频到面试接口', requestData);
|
|
|
|
|
|
// 发送请求到面试接口
|
|
|
- uni.request({
|
|
|
- url: `${apiBaseUrl}/api/job/upload_video`,
|
|
|
- method: 'POST',
|
|
|
- data: requestData,
|
|
|
- header: {
|
|
|
- 'content-type': 'application/x-www-form-urlencoded'
|
|
|
- },
|
|
|
- success: async (res) => {
|
|
|
- if (res.data.code === 200 || res.data.code === 2000) {
|
|
|
- console.log('视频提交成功,准备调用面试互动接口');
|
|
|
-
|
|
|
- // 如果不是追问回答,才调用面试互动接口获取追问
|
|
|
- if (!task.isFollowUp) {
|
|
|
+ if (task.isFollowUp) {
|
|
|
+ // 追问视频上传
|
|
|
+ const followUpRequestData = {
|
|
|
+ application_id: uni.getStorageSync('appId'),
|
|
|
+ tenant_id: JSON.parse(uni.getStorageSync('userInfo')).tenant_id || '1',
|
|
|
+ video_url: videoUrl,
|
|
|
+ original_question_id: this.parentJobPositionQuestionId, // 使用保存的job_position_question_id
|
|
|
+ follow_up_question: task.questionText,
|
|
|
+ video_duration: task.videoDuration,
|
|
|
+ openid: JSON.parse(uni.getStorageSync('userInfo')).openid || ''
|
|
|
+ };
|
|
|
+
|
|
|
+ console.log('准备提交追问视频:', followUpRequestData);
|
|
|
+
|
|
|
+ uni.request({
|
|
|
+ url: `${apiBaseUrl}/voice_interview/upload_follow_up_video/`,
|
|
|
+ method: 'POST',
|
|
|
+ data: followUpRequestData,
|
|
|
+ header: {
|
|
|
+ 'content-type': 'application/x-www-form-urlencoded'
|
|
|
+ },
|
|
|
+ success: async (res) => {
|
|
|
+ try {
|
|
|
+ if (res.data.code === 200 || res.data.code === 2000) {
|
|
|
+ console.log('追问视频提交成功');
|
|
|
+ // 不直接调用proceedToNextQuestion,而是恢复到主问题序列
|
|
|
+ this.isFollowUpMode = false;
|
|
|
+ // 恢复到当前主问题的索引
|
|
|
+ this.currentVideoIndex = this.mainQuestionIndex;
|
|
|
+
|
|
|
+ uni.showToast({
|
|
|
+ title: '回答已提交',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 1500
|
|
|
+ });
|
|
|
+
|
|
|
+ this.uploadQueue.shift();
|
|
|
+ this.processUploadQueue();
|
|
|
+
|
|
|
+ // 继续播放主问题序列
|
|
|
+ this.$nextTick(() => {
|
|
|
+ if (this.currentVideoIndex < this.videoList.length) {
|
|
|
+ this.videoUrl = this.videoList[this.currentVideoIndex];
|
|
|
+ this.videoPlaying = true;
|
|
|
+ const videoContext = uni.createVideoContext('myVideo', this);
|
|
|
+ if (videoContext) {
|
|
|
+ videoContext.play();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.handleSubmitFailure(task, '提交失败: ' + (res.data.msg || '未知错误'));
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ this.handleSubmitFailure(task, '解析响应失败: ' + e.message);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ console.error('提交视频失败:', err);
|
|
|
+ //this.handleSubmitFailure(task, '提交失败: ' + err.errMsg);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ // 原有的视频上传逻辑
|
|
|
+ uni.request({
|
|
|
+ url: `${apiBaseUrl}/api/job/upload_video`,
|
|
|
+ method: 'POST',
|
|
|
+ data: requestData,
|
|
|
+ header: {
|
|
|
+ 'content-type': 'application/x-www-form-urlencoded'
|
|
|
+ },
|
|
|
+ success: async (res) => {
|
|
|
+ if (res.data.code === 200 || res.data.code === 2000) {
|
|
|
+ console.log('视频提交成功,准备调用面试互动接口');
|
|
|
+
|
|
|
try {
|
|
|
- // 调用面试互动接口
|
|
|
+ // 保存job_position_question_id用于后续追问
|
|
|
+ this.parentJobPositionQuestionId = res.data.data.job_position_question_id;
|
|
|
+ console.log('保存父问题ID:', this.parentJobPositionQuestionId);
|
|
|
+
|
|
|
await this.callInterviewInteraction(res.data.data.job_position_question_id);
|
|
|
console.log('面试互动接口调用成功');
|
|
|
} catch (error) {
|
|
|
console.error('面试互动接口调用失败:', error);
|
|
|
- // 如果获取追问失败,继续处理下一个问题
|
|
|
this.proceedToNextQuestion();
|
|
|
}
|
|
|
+
|
|
|
+ uni.showToast({
|
|
|
+ title: '回答已提交',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 1500
|
|
|
+ });
|
|
|
+
|
|
|
+ this.uploadQueue.shift();
|
|
|
+ this.processUploadQueue();
|
|
|
} else {
|
|
|
- // 如果是追问回答,直接继续下一个问题
|
|
|
- console.log('追问回答上传完成,继续下一个问题');
|
|
|
- this.proceedToNextQuestion();
|
|
|
+ this.handleSubmitFailure(task, '提交失败: ' + (res.data.msg || '未知错误'));
|
|
|
}
|
|
|
-
|
|
|
- // 显示成功提示
|
|
|
- uni.showToast({
|
|
|
- title: '回答已提交',
|
|
|
- icon: 'success',
|
|
|
- duration: 1500
|
|
|
- });
|
|
|
-
|
|
|
- // 从队列中移除已完成的任务
|
|
|
- this.uploadQueue.shift();
|
|
|
-
|
|
|
- // 继续处理队列中的下一个任务
|
|
|
- this.processUploadQueue();
|
|
|
- } else {
|
|
|
- this.handleUploadError(task, '提交失败: ' + (res.data.msg || '未知错误'));
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ console.error('提交视频失败:', err);
|
|
|
+ this.handleSubmitFailure(task, '提交失败: ' + err.errMsg);
|
|
|
}
|
|
|
- },
|
|
|
- fail: (err) => {
|
|
|
- console.error('提交视频失败:', err);
|
|
|
- this.handleUploadError(task, '提交失败: ' + err.errMsg);
|
|
|
- }
|
|
|
- });
|
|
|
+ });
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
// 添加新方法:处理提交失败
|
|
@@ -4005,219 +4069,228 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- // 添加新方法:处理追问问题
|
|
|
- async handleFollowUpQuestion(questionData) {
|
|
|
- console.log('处理追问问题数据:', questionData);
|
|
|
+ // 进入追问模式
|
|
|
+ enterFollowUpMode() {
|
|
|
+ this.isFollowUpMode = true;
|
|
|
+ this.mainQuestionIndex = this.currentVideoIndex; // 保存当前主问题的索引
|
|
|
+ console.log('进入追问模式,保存主问题索引:', this.mainQuestionIndex);
|
|
|
+ },
|
|
|
+
|
|
|
+ // 修改 handleFollowUpQuestion 方法
|
|
|
+ async handleFollowUpQuestion(questionData) {
|
|
|
+ console.log('处理追问:', questionData);
|
|
|
+ this.enterFollowUpMode();
|
|
|
+ console.log('处理追问问题数据:', questionData);
|
|
|
+
|
|
|
+ // 检查数据完整性
|
|
|
+ if (!questionData || !questionData.follow_up_voice_url || !questionData.follow_up_question) {
|
|
|
+ console.error('追问数据不完整:', questionData);
|
|
|
+ uni.showToast({
|
|
|
+ title: '获取追问数据失败',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存父问题
|
|
|
+ this.parentQuestion = questionData.original_question || '';
|
|
|
+
|
|
|
+ // 确保音频URL正确
|
|
|
+ let audioUrl = '';
|
|
|
+ if (questionData.follow_up_voice_url.direct_url) {
|
|
|
+ audioUrl = questionData.follow_up_voice_url.direct_url;
|
|
|
+ } else if (questionData.follow_up_voice_url.file_url) {
|
|
|
+ audioUrl = questionData.follow_up_voice_url.file_url;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 确保音频URL是完整的
|
|
|
+ if (!audioUrl.startsWith('http')) {
|
|
|
+ audioUrl = apiBaseUrl + audioUrl;
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('处理后的音频URL:', audioUrl);
|
|
|
+
|
|
|
+ // 创建追问问题对象
|
|
|
+ const followUpQuestionObj = {
|
|
|
+ id: Date.now(),
|
|
|
+ question: questionData.follow_up_question.trim(), // 去除可能的空白字符
|
|
|
+ audioUrl: audioUrl,
|
|
|
+ originalQuestion: questionData.original_question,
|
|
|
+ sessionId: questionData.session_id
|
|
|
+ };
|
|
|
+
|
|
|
+ console.log('创建的追问问题对象:', followUpQuestionObj);
|
|
|
+
|
|
|
+ // 添加到追问问题列表
|
|
|
+ this.followUpQuestions.push(followUpQuestionObj);
|
|
|
+ this.currentFollowUpIndex = this.followUpQuestions.length - 1;
|
|
|
+
|
|
|
+ // 更新当前追问问题
|
|
|
+ this.followUpQuestion = followUpQuestionObj.question;
|
|
|
+ this.followUpAudioUrl = followUpQuestionObj.audioUrl;
|
|
|
+
|
|
|
+ // 标记当前是追问问题
|
|
|
+ this.isFollowUpQuestion = true;
|
|
|
+ this.currentFollowUpQuestion = followUpQuestionObj;
|
|
|
+
|
|
|
+ // 显示字幕
|
|
|
+ this.showSubtitle(followUpQuestionObj.question, true);
|
|
|
+
|
|
|
+ // 等待音频播放完成
|
|
|
+ try {
|
|
|
+ await this.playFollowUpAudio();
|
|
|
+ console.log('音频播放完成,准备录制回答');
|
|
|
+ // 开始准备录制回答
|
|
|
+ this.prepareToAnswer(true, followUpQuestionObj);
|
|
|
+ } catch (error) {
|
|
|
+ console.error('音频播放失败:', error);
|
|
|
+ // 即使音频播放失败,也继续准备录制回答
|
|
|
+ this.prepareToAnswer(true, followUpQuestionObj);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 播放追问音频
|
|
|
+ async playFollowUpAudio() {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ console.log('开始播放追问音频, URL:', this.followUpAudioUrl);
|
|
|
|
|
|
- // 检查数据完整性
|
|
|
- if (!questionData || !questionData.follow_up_voice_url || !questionData.follow_up_question) {
|
|
|
- console.error('追问数据不完整:', questionData);
|
|
|
- uni.showToast({
|
|
|
- title: '获取追问数据失败',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
+ // 检查音频URL
|
|
|
+ if (!this.followUpAudioUrl) {
|
|
|
+ console.error('没有音频URL');
|
|
|
+ reject(new Error('没有音频URL'));
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 保存父问题
|
|
|
- this.parentQuestion = questionData.original_question || '';
|
|
|
-
|
|
|
- // 确保音频URL正确
|
|
|
- let audioUrl = '';
|
|
|
- if (questionData.follow_up_voice_url.direct_url) {
|
|
|
- audioUrl = questionData.follow_up_voice_url.direct_url;
|
|
|
- } else if (questionData.follow_up_voice_url.file_url) {
|
|
|
- audioUrl = questionData.follow_up_voice_url.file_url;
|
|
|
- }
|
|
|
-
|
|
|
- // 确保音频URL是完整的
|
|
|
- if (!audioUrl.startsWith('http')) {
|
|
|
- audioUrl = apiBaseUrl + audioUrl;
|
|
|
- }
|
|
|
-
|
|
|
- console.log('处理后的音频URL:', audioUrl);
|
|
|
-
|
|
|
- // 创建追问问题对象
|
|
|
- const followUpQuestionObj = {
|
|
|
- id: Date.now(),
|
|
|
- question: questionData.follow_up_question.trim(), // 去除可能的空白字符
|
|
|
- audioUrl: audioUrl,
|
|
|
- originalQuestion: questionData.original_question,
|
|
|
- sessionId: questionData.session_id
|
|
|
- };
|
|
|
-
|
|
|
- console.log('创建的追问问题对象:', followUpQuestionObj);
|
|
|
-
|
|
|
- // 添加到追问问题列表
|
|
|
- this.followUpQuestions.push(followUpQuestionObj);
|
|
|
- this.currentFollowUpIndex = this.followUpQuestions.length - 1;
|
|
|
-
|
|
|
- // 更新当前追问问题
|
|
|
- this.followUpQuestion = followUpQuestionObj.question;
|
|
|
- this.followUpAudioUrl = followUpQuestionObj.audioUrl;
|
|
|
-
|
|
|
- // 标记当前是追问问题
|
|
|
- this.isFollowUpQuestion = true;
|
|
|
- this.currentFollowUpQuestion = followUpQuestionObj;
|
|
|
+ // 显示加载提示
|
|
|
+ uni.showLoading({
|
|
|
+ title: '加载音频中...'
|
|
|
+ });
|
|
|
|
|
|
- // 显示字幕
|
|
|
- this.showSubtitle(followUpQuestionObj.question, true);
|
|
|
+ // 停止并销毁之前的音频实例
|
|
|
+ this.stopAndDestroyAudio();
|
|
|
|
|
|
- // 等待音频播放完成
|
|
|
try {
|
|
|
- await this.playFollowUpAudio();
|
|
|
- console.log('音频播放完成,准备录制回答');
|
|
|
- // 开始准备录制回答
|
|
|
- this.prepareToAnswer(true, followUpQuestionObj);
|
|
|
- } catch (error) {
|
|
|
- console.error('音频播放失败:', error);
|
|
|
- // 即使音频播放失败,也继续准备录制回答
|
|
|
- this.prepareToAnswer(true, followUpQuestionObj);
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
- // 播放追问音频
|
|
|
- async playFollowUpAudio() {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- console.log('开始播放追问音频, URL:', this.followUpAudioUrl);
|
|
|
+ // 创建新的音频上下文
|
|
|
+ const innerAudioContext = uni.createInnerAudioContext();
|
|
|
+ this.audioContext = innerAudioContext;
|
|
|
|
|
|
- // 检查音频URL
|
|
|
- if (!this.followUpAudioUrl) {
|
|
|
- console.error('没有音频URL');
|
|
|
- reject(new Error('没有音频URL'));
|
|
|
- return;
|
|
|
- }
|
|
|
+ // 设置音频属性
|
|
|
+ innerAudioContext.autoplay = true;
|
|
|
+ innerAudioContext.obeyMuteSwitch = false;
|
|
|
+ innerAudioContext.volume = 1.0;
|
|
|
|
|
|
- // 显示加载提示
|
|
|
- uni.showLoading({
|
|
|
- title: '加载音频中...'
|
|
|
+ // 监听音频加载状态
|
|
|
+ innerAudioContext.onCanplay(() => {
|
|
|
+ console.log('音频可以播放');
|
|
|
+ uni.hideLoading();
|
|
|
+ this.isAudioPlaying = true;
|
|
|
+ uni.showToast({
|
|
|
+ title: '正在播放追问',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 2000
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
- // 停止并销毁之前的音频实例
|
|
|
- this.stopAndDestroyAudio();
|
|
|
-
|
|
|
- try {
|
|
|
- // 创建新的音频上下文
|
|
|
- const innerAudioContext = uni.createInnerAudioContext();
|
|
|
- this.audioContext = innerAudioContext;
|
|
|
-
|
|
|
- // 设置音频属性
|
|
|
- innerAudioContext.autoplay = true;
|
|
|
- innerAudioContext.obeyMuteSwitch = false;
|
|
|
- innerAudioContext.volume = 1.0;
|
|
|
-
|
|
|
- // 监听音频加载状态
|
|
|
- innerAudioContext.onCanplay(() => {
|
|
|
- console.log('音频可以播放');
|
|
|
- uni.hideLoading();
|
|
|
- this.isAudioPlaying = true;
|
|
|
- uni.showToast({
|
|
|
- title: '正在播放追问',
|
|
|
- icon: 'none',
|
|
|
- duration: 2000
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- // 监听音频播放完成
|
|
|
- innerAudioContext.onEnded(() => {
|
|
|
- console.log('追问音频播放完成');
|
|
|
- this.isAudioPlaying = false;
|
|
|
- resolve();
|
|
|
- // 延迟清理资源,确保不会影响播放完成的回调
|
|
|
- setTimeout(() => {
|
|
|
- this.stopAndDestroyAudio();
|
|
|
- // 音频播放完成后,自动准备录制回答
|
|
|
- this.prepareToAnswer(true, this.currentFollowUpQuestion);
|
|
|
- }, 100);
|
|
|
- });
|
|
|
-
|
|
|
- // 监听音频播放错误
|
|
|
- innerAudioContext.onError((res) => {
|
|
|
- console.error('音频播放错误:', res);
|
|
|
- this.isAudioPlaying = false;
|
|
|
- uni.hideLoading();
|
|
|
- uni.showToast({
|
|
|
- title: '音频播放失败',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- reject(res);
|
|
|
+ // 监听音频播放完成
|
|
|
+ innerAudioContext.onEnded(() => {
|
|
|
+ console.log('追问音频播放完成');
|
|
|
+ this.isAudioPlaying = false;
|
|
|
+ resolve();
|
|
|
+ // 延迟清理资源,确保不会影响播放完成的回调
|
|
|
+ setTimeout(() => {
|
|
|
this.stopAndDestroyAudio();
|
|
|
- });
|
|
|
-
|
|
|
- // 设置音频源
|
|
|
- console.log('设置音频源:', this.followUpAudioUrl);
|
|
|
- innerAudioContext.src = this.followUpAudioUrl;
|
|
|
-
|
|
|
- } catch (error) {
|
|
|
- console.error('创建或播放音频失败:', error);
|
|
|
+ // 音频播放完成后,自动准备录制回答
|
|
|
+ this.prepareToAnswer(true, this.currentFollowUpQuestion);
|
|
|
+ }, 100);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 监听音频播放错误
|
|
|
+ innerAudioContext.onError((res) => {
|
|
|
+ console.error('音频播放错误:', res);
|
|
|
this.isAudioPlaying = false;
|
|
|
uni.hideLoading();
|
|
|
uni.showToast({
|
|
|
title: '音频播放失败',
|
|
|
icon: 'none'
|
|
|
});
|
|
|
+ reject(res);
|
|
|
this.stopAndDestroyAudio();
|
|
|
- reject(error);
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
-
|
|
|
- // 停止并销毁音频
|
|
|
- stopAndDestroyAudio() {
|
|
|
- if (!this.audioContext) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- const ctx = this.audioContext;
|
|
|
- this.audioContext = null; // 先清除引用
|
|
|
-
|
|
|
- try {
|
|
|
- if (this.isAudioPlaying) {
|
|
|
- ctx.stop();
|
|
|
- }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 设置音频源
|
|
|
+ console.log('设置音频源:', this.followUpAudioUrl);
|
|
|
+ innerAudioContext.src = this.followUpAudioUrl;
|
|
|
+
|
|
|
} catch (error) {
|
|
|
- console.error('停止音频播放失败:', error);
|
|
|
+ console.error('创建或播放音频失败:', error);
|
|
|
+ this.isAudioPlaying = false;
|
|
|
+ uni.hideLoading();
|
|
|
+ uni.showToast({
|
|
|
+ title: '音频播放失败',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ this.stopAndDestroyAudio();
|
|
|
+ reject(error);
|
|
|
}
|
|
|
-
|
|
|
- try {
|
|
|
- ctx.destroy();
|
|
|
- } catch (error) {
|
|
|
- console.error('销毁音频实例失败:', error);
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // 停止并销毁音频
|
|
|
+ stopAndDestroyAudio() {
|
|
|
+ if (!this.audioContext) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const ctx = this.audioContext;
|
|
|
+ this.audioContext = null; // 先清除引用
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (this.isAudioPlaying) {
|
|
|
+ ctx.stop();
|
|
|
}
|
|
|
-
|
|
|
- this.isAudioPlaying = false;
|
|
|
- },
|
|
|
+ } catch (error) {
|
|
|
+ console.error('停止音频播放失败:', error);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ ctx.destroy();
|
|
|
+ } catch (error) {
|
|
|
+ console.error('销毁音频实例失败:', error);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.isAudioPlaying = false;
|
|
|
+ },
|
|
|
|
|
|
- // 显示字幕
|
|
|
- showSubtitle(text, isFollowUp = true) {
|
|
|
- console.log('显示字幕:', text);
|
|
|
- this.subtitleText = text;
|
|
|
- this.showSubtitleText = true;
|
|
|
- this.isFollowUpQuestion = isFollowUp;
|
|
|
-
|
|
|
- // 确保字幕显示在界面上
|
|
|
- this.$nextTick(() => {
|
|
|
- // 如果需要,可以添加字幕动画效果
|
|
|
- setTimeout(() => {
|
|
|
- this.showSubtitleText = false;
|
|
|
- }, 8000); // 8秒后隐藏字幕
|
|
|
- });
|
|
|
- },
|
|
|
+ // 显示字幕
|
|
|
+ showSubtitle(text, isFollowUp = true) {
|
|
|
+ console.log('显示字幕:', text);
|
|
|
+ this.subtitleText = text;
|
|
|
+ this.showSubtitleText = true;
|
|
|
+ this.isFollowUpQuestion = isFollowUp;
|
|
|
+
|
|
|
+ // 确保字幕显示在界面上
|
|
|
+ this.$nextTick(() => {
|
|
|
+ // 如果需要,可以添加字幕动画效果
|
|
|
+ setTimeout(() => {
|
|
|
+ this.showSubtitleText = false;
|
|
|
+ }, 8000); // 8秒后隐藏字幕
|
|
|
+ });
|
|
|
+ },
|
|
|
|
|
|
- // 显示问题对话框
|
|
|
- showQuestionDialog() {
|
|
|
- if (this.followUpQuestion) {
|
|
|
- uni.showModal({
|
|
|
- title: '追问问题',
|
|
|
- content: this.followUpQuestion,
|
|
|
- showCancel: false,
|
|
|
- success: () => {
|
|
|
- // 准备开始回答
|
|
|
- this.prepareToAnswer(true, this.followUpQuestions[this.currentFollowUpIndex]);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- },
|
|
|
+ // 显示问题对话框
|
|
|
+ showQuestionDialog() {
|
|
|
+ if (this.followUpQuestion) {
|
|
|
+ uni.showModal({
|
|
|
+ title: '追问问题',
|
|
|
+ content: this.followUpQuestion,
|
|
|
+ showCancel: false,
|
|
|
+ success: () => {
|
|
|
+ // 准备开始回答
|
|
|
+ this.prepareToAnswer(true, this.followUpQuestions[this.currentFollowUpIndex]);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
},
|
|
|
computed: {
|
|
|
// 计算进度比例
|