Ver Fonte

refactor(sidepanel): 优化聊天面板的代码结构和功能

- 添加了多个 console.log 语句,用于调试和查看消息内容
- 优化了消息发送和处理的逻辑,提高了代码可读性
- 改进了文件上传和处理功能,增加了进度显示
- 调整了消息历史的记录方式,提高了性能
chd há 5 meses atrás
pai
commit
57b03a7dd6

+ 17 - 4
src/entrypoints/sidepanel/Chat.vue

@@ -180,6 +180,8 @@ function handleScroll({ scrollTop }) {
  * @param {string} type 发送的类型 document 、text
  * **/
 async function addMessage(msg, raw, type) {
+  console.log(msg);
+  
   // 添加indexDB Store配置
   if (msgUuid.value === '') {
     msgUuid.value = 'D' + Date.now().toString()
@@ -341,14 +343,14 @@ async function handleAsk() {
   const str = inputMessage.value.trim()
   inputMessage.value = ''
   if (sendLoading.value) return
-  addMessage(inputMessage.value.trim())
+  addMessage(str)
   if (type.value === FunctionList.Intelligent_Form_filling) {
     const res = await fetchRes(str)
     console.log(res);
 
     if (res.status === 'ok') {
       formInfo.value = res.data
-      console.log(res)
+      console.log(res,55558)
     } else {
       type.value = FunctionList.File_Operation
       isShowPage.value = false
@@ -406,7 +408,12 @@ const handleUpload = async (file) => {
        const res2 = await getFormKeyAndValue(data, formInfo.value)
        xlsxData.value = res2.data
        msg.rawContent = buildObjPrompt(res2.data, formInfo.value)
-       const { rawContent,status } = await streamRes()
+       console.log(msg.rawContent);
+       console.log(messages);
+       
+       const { rawContent, status } = await streamRes()
+       console.log(22555);
+       
        if (status === 'ok') {
          let form = []
          if (rawContent.includes('json')) form = JSON.parse(rawContent.split('json')[1].split('```')[0])
@@ -442,13 +449,19 @@ const handleUpload = async (file) => {
 }
 
 async function getFileValue(file) {
-  const msg = addMessage(`文件上传中`)
+  const msg = await addMessage(`文件上传中`)
+  console.log(msg,messages);
+  
   sendLoading.value = true
   let formData = new FormData()
   formData.append('file', file)
   const res = await getFileContent(formData)
+  console.log(res,5555);
+  
   sendLoading.value = false
   msg.content = `已上传文件:${file.name}`
+  console.log(msg.content);
+  
   msg.rawContent = res.data
   return {
     data: res.data,

+ 3 - 0
src/entrypoints/sidepanel/hook/useMsg.ts

@@ -233,6 +233,9 @@ export function useMsg(scrollbar?: any) {
       addToHistory: !taklToHtml.value
     })
     let history = []
+    console.log(taklToHtml.value);
+    console.log(messages.value);
+    
     if (taklToHtml.value) {
       if (addHtml) {
         history.push({