wzg 6 månader sedan
förälder
incheckning
99c7dd5570
3 ändrade filer med 33 tillägg och 17 borttagningar
  1. 3 2
      css/chat.css
  2. 6 5
      js/ai-service.js
  3. 24 10
      js/chat-ui.js

+ 3 - 2
css/chat.css

@@ -505,6 +505,7 @@
 }
 
 /* 复制按钮样式 */
+.fill-button,
 .copy-button {
   display: flex;
   align-items: center;
@@ -519,12 +520,12 @@
   cursor: pointer;
   transition: all 0.2s ease;
 }
-
+.fill-button:hover,
 .copy-button:hover {
   background: rgba(0, 0, 0, 0.05);
   color: #1a73e8;
 }
-
+.fill-button svg, 
 .copy-button svg {
   width: 14px;
   height: 14px;

+ 6 - 5
js/ai-service.js

@@ -66,7 +66,7 @@ class AIService {
         messages: this.formatMessages(message),
         stream: true
       });
-
+      
       return response;
 
 
@@ -99,11 +99,12 @@ class AIService {
 
       // return aiResponse;
     } catch (error) {
-      if (error.name === "AbortError") {
-        throw new Error("REQUEST_ABORTED");
-      }
+      // if (error.name === "AbortError") {
+      //   throw new Error("REQUEST_ABORTED");
+      // }
       console.error("API call failed:", error);
-      throw error;
+      // throw error;
+      return '[FILE]'
     } finally {
       this.controller = null;
     }

+ 24 - 10
js/chat-ui.js

@@ -327,8 +327,13 @@ ${this.iframeInfo}`;
     if (type === "assistant" && !isInterrupted) {
       const copyButton = this.createCopyButton(content);
       actionsDiv.appendChild(copyButton);
-      actionsDiv.appendChild(this.createFillButton());
+      console.log(content);
 
+      console.log(Object.prototype.toString.call(content));
+
+      if (Object.prototype.toString.call(content) === "[object Object]") {
+        actionsDiv.appendChild(this.createFillButton(paragraph));
+      }
     }
 
     // 添加时间戳
@@ -344,14 +349,11 @@ ${this.iframeInfo}`;
     if (typing) {
       messageContent.classList.add("typing");
       if (typeof content !== 'string') {
-        console.log(content);
-        console.log(content.controller);
         const signal = content.controller.signal;
         try {
           const iterator = content.iterator();
           for await (const chunk of iterator) {
             if (chunk) {
-              console.log(chunk);
               const decodedChunk = chunk.choices[0].delta.content;
               if (decodedChunk) {
                 paragraph.innerHTML += decodedChunk;
@@ -567,12 +569,24 @@ ${this.iframeInfo}`;
         .replace(/^>\s+(.+)$/gm, "<blockquote>$1</blockquote>")
     );
   }
-  createFillButton() {
+
+  createFillButton(paragraph) {
     const button = document.createElement("button");
-    button.id = 'fill-button'
     button.className = "fill-button";
-    button.innerHTML = `填充`;
-  
+    button.innerHTML = `
+      <svg viewBox="0 0 24 24" fill="currentColor">
+        <path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z"/>
+      </svg>
+      <span>填充</span>
+    `;
+    button.addEventListener("click", () => {
+      window.parent.postMessage({
+        type: "HANDLE_FILL_INPUT", data: {
+          formData: JSON.parse(paragraph.innerHTML.split('json')[1].split('```')[0])  //根据不同返回修改res
+        }
+      }, "*");
+    });
+
     return button;
   }
   /**
@@ -799,7 +813,7 @@ ${this.iframeInfo}`;
         if (this.excelTypes[extension]) {
           try {
             this.setInputState(true);
-            this.loadingDiv = ''
+            this.loadingDiv = this.createLoadingMessage();
 
             // 读取Excel文件
             const data = await this.readExcelFile(file);
@@ -871,7 +885,7 @@ ${this.iframeInfo}`;
         excelData: this.excelData,
       }
     }, "*");
-   
+
     return `我将向你展示一个通过SheetJS库读取的Excel文件内容和一个form表单。请帮我理解这些数据:
 
 文件名:${fileName}