|
|
|
@ -68,18 +68,6 @@
|
|
|
|
isShowRightLogo: false
|
|
|
|
isShowRightLogo: false
|
|
|
|
};
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// onPageScroll(e) {
|
|
|
|
|
|
|
|
// if (!this.getAiLogoMsg) {
|
|
|
|
|
|
|
|
// this.aiLogoRect = this.$refs.front.getAiLogoMsg();
|
|
|
|
|
|
|
|
// this.getAiLogoMsg = true
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (!this.aiLogoRect) return;
|
|
|
|
|
|
|
|
// if (e.scrollTop > (this.aiLogoRect.top + 12)) {
|
|
|
|
|
|
|
|
// this.isShowRightLogo = true;
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// this.isShowRightLogo = false;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
async mounted() {
|
|
|
|
async mounted() {
|
|
|
|
this.loadChatHistory();
|
|
|
|
this.loadChatHistory();
|
|
|
|
uni.onKeyboardHeightChange((res) => {
|
|
|
|
uni.onKeyboardHeightChange((res) => {
|
|
|
|
@ -141,8 +129,6 @@
|
|
|
|
let items = this.messages.find(item => item.src && item.src === this.audioContext.src);
|
|
|
|
let items = this.messages.find(item => item.src && item.src === this.audioContext.src);
|
|
|
|
if (!items) return;
|
|
|
|
if (!items) return;
|
|
|
|
items.duration = this.audioContext.duration;
|
|
|
|
items.duration = this.audioContext.duration;
|
|
|
|
// this.isPlayingVoice = true;
|
|
|
|
|
|
|
|
// this.audioContext.play()
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.audioContext.onEnded(res => {
|
|
|
|
this.audioContext.onEnded(res => {
|
|
|
|
this.isPlayingVoice = false
|
|
|
|
this.isPlayingVoice = false
|
|
|
|
@ -212,11 +198,6 @@
|
|
|
|
requestId: this.requestId
|
|
|
|
requestId: this.requestId
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
if (this.textToVoiceLoading) {
|
|
|
|
|
|
|
|
this.speechIdList.push({
|
|
|
|
|
|
|
|
speedId: this.speedId
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
if (this.isPlayingVoice) {
|
|
|
|
if (this.isPlayingVoice) {
|
|
|
|
this.isPlayingVoice = false;
|
|
|
|
this.isPlayingVoice = false;
|
|
|
|
this.audioContext.stop();
|
|
|
|
this.audioContext.stop();
|
|
|
|
@ -375,46 +356,30 @@
|
|
|
|
const reply = await getAIResponse({
|
|
|
|
const reply = await getAIResponse({
|
|
|
|
message: text,
|
|
|
|
message: text,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
let speechResult;
|
|
|
|
|
|
|
|
if(this.$store.state.set.replyPattern === '1'){
|
|
|
|
|
|
|
|
speechResult = await this.getSpeech(reply.errMsg || reply);
|
|
|
|
|
|
|
|
}
|
|
|
|
this.isLoading = false;
|
|
|
|
this.isLoading = false;
|
|
|
|
let requestIndex = this.breakRequestList.findIndex(item => item.requestId === requestId)
|
|
|
|
// 查询是否新建对话
|
|
|
|
|
|
|
|
let requestIndex = this.breakRequestList.findIndex(item => item.requestId === requestId);
|
|
|
|
if (requestIndex > -1) {
|
|
|
|
if (requestIndex > -1) {
|
|
|
|
this.breakRequestList = this.breakRequestList.splice(requestIndex, -1)
|
|
|
|
this.breakRequestList = this.breakRequestList.splice(requestIndex, -1)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.replyData = reply;
|
|
|
|
this.replyData = reply;
|
|
|
|
|
|
|
|
// 是否中断对话
|
|
|
|
if (this.breakReplying) {
|
|
|
|
if (this.breakReplying) {
|
|
|
|
this.breakReplying = false;
|
|
|
|
this.breakReplying = false;
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.replyAction(reply)
|
|
|
|
if(speechResult){
|
|
|
|
},
|
|
|
|
|
|
|
|
async replyAction(reply, isContinue) {
|
|
|
|
|
|
|
|
let content = ''
|
|
|
|
|
|
|
|
// 判断请求是否出错
|
|
|
|
|
|
|
|
if (reply.errMsg) {
|
|
|
|
|
|
|
|
content = `请求出错: 系统异常`
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
content = reply;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
let result;
|
|
|
|
|
|
|
|
let speechId = Date.now();
|
|
|
|
|
|
|
|
this.speechId = speechId;
|
|
|
|
|
|
|
|
if (this.$store.state.set.replyPattern === '1' && !this.messages[this.messages.length - 1].src && !
|
|
|
|
|
|
|
|
reply.errMsg) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = await this.getSpeech(reply);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
|
|
|
|
let speechIndex = this.speechIdList.findIndex(item => item.speechId === speechId)
|
|
|
|
|
|
|
|
if (speechIndex > -1) {
|
|
|
|
|
|
|
|
this.speechIdList = this.speechIdList.splice(speechIndex, -1)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
|
|
|
|
this.isPlayingVoice = true;
|
|
|
|
this.isPlayingVoice = true;
|
|
|
|
this.audioContext.play();
|
|
|
|
this.audioContext.play();
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.replyAction(reply)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
async replyAction(reply, isContinue) {
|
|
|
|
// 4. 移除 loading
|
|
|
|
// 4. 移除 loading
|
|
|
|
const loadingIdx = this.messages.findIndex((m) => m.id === this.loadingId);
|
|
|
|
const loadingIdx = this.messages.findIndex((m) => m.id === this.loadingId);
|
|
|
|
if (loadingIdx > -1) this.messages.splice(loadingIdx, 1);
|
|
|
|
if (loadingIdx > -1) this.messages.splice(loadingIdx, 1);
|
|
|
|
@ -425,18 +390,22 @@
|
|
|
|
id: replyId,
|
|
|
|
id: replyId,
|
|
|
|
role: "assistant",
|
|
|
|
role: "assistant",
|
|
|
|
type: "text",
|
|
|
|
type: "text",
|
|
|
|
content,
|
|
|
|
content : reply,
|
|
|
|
displayText: "",
|
|
|
|
displayText: "",
|
|
|
|
src: (this.audioContext.src && this.$store.state.set.replyPattern === '1') ? JSON
|
|
|
|
src: (this.audioContext.src && this.$store.state.set.replyPattern === '1') ? JSON
|
|
|
|
.parse(JSON.stringify(this.audioContext.src)) : null,
|
|
|
|
.parse(JSON.stringify(this.audioContext.src)) : null,
|
|
|
|
duration: null
|
|
|
|
duration: null
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if(this.$store.state.set.replyPattern === '1'){
|
|
|
|
|
|
|
|
this.messages[this.messages.length - 1].src = this.audioContext.src;
|
|
|
|
|
|
|
|
this.messages[this.messages.length - 1].duration = this.audioContext.duration || 0;
|
|
|
|
this.audioContext.play();
|
|
|
|
this.audioContext.play();
|
|
|
|
this.isPlayingVoice = true;
|
|
|
|
this.isPlayingVoice = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
this.$nextTick(() => this.scrollToBottom());
|
|
|
|
this.$nextTick(() => this.scrollToBottom());
|
|
|
|
this.typewriter(replyId, content);
|
|
|
|
this.typewriter(replyId, reply);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// 打印机效果,并清除加载动画
|
|
|
|
// 打印机效果,并清除加载动画
|
|
|
|
typewriter(messageId, fullText) {
|
|
|
|
typewriter(messageId, fullText) {
|
|
|
|
|