整体优化

main
xushilin 3 months ago
parent 477ec111c0
commit c4014183fa

@ -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;
} }
if(speechResult){
this.isPlayingVoice = true;
this.audioContext.play();
}
this.replyAction(reply) this.replyAction(reply)
}, },
async replyAction(reply, isContinue) { 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.audioContext.play();
};
}
// 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 {
this.audioContext.play(); if(this.$store.state.set.replyPattern === '1'){
this.isPlayingVoice = true; 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.isPlayingVoice = true;
}
} }
this.$nextTick(() => this.scrollToBottom()); this.$nextTick(() => this.scrollToBottom());
this.typewriter(replyId, content); this.typewriter(replyId, reply);
}, },
// //
typewriter(messageId, fullText) { typewriter(messageId, fullText) {

@ -41,7 +41,7 @@ const request = (config) => {
if (res.success) { if (res.success) {
resolve(res.data); resolve(res.data);
} else { } else {
resolve({errMsg : res.error}); resolve({errMsg : '请求出错: 系统异常'});
} }
}) })
.catch((error) => { .catch((error) => {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save