|
@@ -121,22 +121,19 @@ export default {
|
|
|
|
|
|
}
|
|
|
},
|
|
|
- chat_id(val){
|
|
|
+ chat_id(val,oldval){
|
|
|
this.conversationId = val
|
|
|
if(val){
|
|
|
- this.chatHistory = []
|
|
|
this.queryChatHistory.has_more = true
|
|
|
- this.getChatHistory()
|
|
|
+ this.getChatHistory(1)
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
- projectId(){
|
|
|
- return this.$route.query.projectId
|
|
|
- },
|
|
|
+
|
|
|
},
|
|
|
created() {
|
|
|
- this.init()
|
|
|
+ this.getChatHistory()
|
|
|
},
|
|
|
mounted() {
|
|
|
// 添加滚动事件监听
|
|
@@ -164,7 +161,7 @@ export default {
|
|
|
this.scrollLock = !isNearBottom;
|
|
|
if(messageBox.scrollTop == 0 && this.queryChatHistory.has_more){
|
|
|
//获取会话历史
|
|
|
- let firstId = this.chatHistory[0].id
|
|
|
+ let firstId = this.chatHistory[0]?.id
|
|
|
this.queryChatHistory.firstId = firstId
|
|
|
await this.getChatHistory()
|
|
|
// this.$nextTick(()=>{
|
|
@@ -197,34 +194,13 @@ export default {
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
- },
|
|
|
- async init(){
|
|
|
- //获取会话id
|
|
|
- await this.getConversationId()
|
|
|
- //获取会话历史
|
|
|
- this.getChatHistory()
|
|
|
- },
|
|
|
- //获取会话id
|
|
|
- async getConversationId(){
|
|
|
- if(this.conversationId){
|
|
|
+ },
|
|
|
+ //获取会话历史
|
|
|
+ async getChatHistory(type){
|
|
|
+ if(!this.queryChatHistory.has_more){
|
|
|
return
|
|
|
}
|
|
|
- var params = {
|
|
|
- projectId:this.projectId
|
|
|
- }
|
|
|
- await this.$api.querySessionId(params).then(response=>{
|
|
|
- if(response.code == 200){
|
|
|
- this.conversationId = response.data
|
|
|
- if(!this.conversationId){
|
|
|
- this.$emit('noChatId')
|
|
|
- this.queryChatHistory.has_more = false
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
- //获取会话历史
|
|
|
- async getChatHistory(){
|
|
|
- if(!this.conversationId || !this.queryChatHistory.has_more){
|
|
|
+ if(!this.conversationId){
|
|
|
return
|
|
|
}
|
|
|
var params = {
|
|
@@ -234,7 +210,11 @@ export default {
|
|
|
await this.$api.queryHistoryMessage(params).then(response=>{
|
|
|
if(response.code == 200){
|
|
|
let data = response.data
|
|
|
- this.chatHistory.unshift(...(data.data.reverse()))
|
|
|
+ if(type){
|
|
|
+ this.chatHistory = data.data.reverse()
|
|
|
+ }else{
|
|
|
+ this.chatHistory.unshift(...(data.data.reverse()))
|
|
|
+ }
|
|
|
this.queryChatHistory['has_more'] = data.has_more
|
|
|
}
|
|
|
})
|
|
@@ -298,7 +278,7 @@ export default {
|
|
|
this.resetCurrentMessage();
|
|
|
this.controller = null;
|
|
|
if(!this.conversationId){
|
|
|
- this.getConversationId()
|
|
|
+ this.$emit('getConversationId')
|
|
|
}
|
|
|
this.currentTaskId = null
|
|
|
},
|
|
@@ -308,8 +288,8 @@ export default {
|
|
|
try {
|
|
|
let data = {
|
|
|
query:message,
|
|
|
- projectId:this.projectId,
|
|
|
- conversationId:this.conversationId
|
|
|
+ conversationId:this.conversationId,
|
|
|
+ ...this.params
|
|
|
}
|
|
|
const response = await fetch('/api/xiaoshi/dify/chatMessage', {
|
|
|
method: 'POST',
|
|
@@ -320,17 +300,8 @@ export default {
|
|
|
body: JSON.stringify(data),
|
|
|
signal: this.controller.signal
|
|
|
});
|
|
|
- // var params = {
|
|
|
- // query:message,
|
|
|
- // inputs:{
|
|
|
-
|
|
|
- // },
|
|
|
- // user:'1',
|
|
|
-
|
|
|
- // }
|
|
|
if (!response.ok) throw new Error('AI API 调用失败');
|
|
|
|
|
|
-
|
|
|
const reader = response.body.getReader();
|
|
|
const decoder = new TextDecoder('utf-8');
|
|
|
var messageId = ''
|
|
@@ -359,6 +330,8 @@ export default {
|
|
|
}
|
|
|
if(json.event == 'message'){
|
|
|
this.currentMessage.answer += json.answer;
|
|
|
+ }else if(json.event == 'message_replace'){
|
|
|
+ this.currentMessage.answer = json.answer
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
@@ -378,6 +351,8 @@ export default {
|
|
|
}
|
|
|
if(json.event == 'message'){
|
|
|
this.currentMessage.answer += json.answer;
|
|
|
+ }else if(json.event == 'message_replace'){
|
|
|
+ this.currentMessage.answer = json.answer
|
|
|
}
|
|
|
}
|
|
|
catch(e){
|
|
@@ -426,26 +401,6 @@ export default {
|
|
|
},
|
|
|
//复制
|
|
|
async copy(chat){
|
|
|
- // let arr = this.formateAIAnswer(chat)
|
|
|
- // if(!arr.length){
|
|
|
- // return
|
|
|
- // }
|
|
|
- // let content = ''
|
|
|
- // let index = arr.findIndex(item=>{
|
|
|
- // return item.type == 'think'
|
|
|
- // })
|
|
|
- // if(index == -1){
|
|
|
- // content = arr[0].content
|
|
|
- // }else{
|
|
|
- // if(arr[index + 1]){
|
|
|
- // content = arr[index + 1].content
|
|
|
- // }
|
|
|
- // }
|
|
|
- // if(!content){
|
|
|
- // return
|
|
|
- // }
|
|
|
- // let content2 = renderMarkdown(content)
|
|
|
-
|
|
|
let answerDomList = document.querySelectorAll('#answer_'+chat.id)
|
|
|
|
|
|
if(answerDomList.length == 0){
|