zhuliu пре 5 месеци
родитељ
комит
78fb220775

+ 22 - 67
src/components/xiaoshi_AI/index.vue

@@ -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){

+ 32 - 9
src/views/noveltySearch/components/technicalDisclosure/technicalDisclosure.vue

@@ -22,7 +22,7 @@
         </div>
         <div class></div>
         <div class="AIChat" v-if="showChat">
-            <xiaoshiAI :chat_id="chat_id" @noChatId="generateInventionPoint"></xiaoshiAI>
+            <xiaoshiAI :chat_id="chat_id" :params="AIParams" @getConversationId="getConversationId"></xiaoshiAI>
         </div>
     </div>
   </div>
@@ -60,13 +60,17 @@ export default {
         loading:false,
         chat_id:'',
         loading2:false,
-        showChat:false,
-        showInventionPoint:true
+        showChat:true,
+        showInventionPoint:true,
+        AIParams:{
+          projectId:this.projectId
+        }
     };
   },
   watch: {
     projectId(){
-        this.getInit()
+      this.AIParams.projectId = this.projectId
+      this.getInit()
     },
   },
   computed: {},
@@ -82,14 +86,34 @@ export default {
             this.technicalCase={
                 inventionPoint:'',
             }
-            this.$message.warning('网页参数错误')
+            // this.$message.warning('网页参数错误')
+            // this.showChat = true
             return
         }
         //获取技术交底书
         this.getConfession()
         //获取发明点
         await this.getTechnicalCase()
-        this.showChat = true
+        //获取会话id
+        this.getConversationId()
+        // this.showChat = true
+    },
+    //获取会话id
+    async getConversationId(){
+        if(this.chat_id){
+            return
+        }
+        var params = {
+            projectId:this.projectId
+        }
+        await this.$api.querySessionId(params).then(response=>{
+            if(response.code == 200){
+                this.chat_id = response.data
+                if(!this.chat_id){
+                  this.generateInventionPoint()
+                }
+            }
+        })
     },
     //生成发明点
     generateInventionPoint(){
@@ -107,9 +131,6 @@ export default {
             let invention_point = response.data.invention_point
             this.$set(this.technicalCase,'inventionPoint',invention_point)
           }
-          // if(response.data.conversation_id){
-          //   this.$set(this,'chat_id',response.data.conversation_id)
-          // }
           this.loading2 = false
         }
       }).catch(error=>{
@@ -154,6 +175,7 @@ export default {
       })
     },
     
+    //获取技术交底书
     getConfession(){
       var params = {
         projectId:this.projectId
@@ -170,6 +192,7 @@ export default {
         this.loading = false
       })
     },
+    //获取onlyoffice需要的内容
     getOption(){
         if(!this.confession.guid){
             this.$message.warning('技术交底书不存在')