chd 5 月之前
父节点
当前提交
5fcee97279

+ 4 - 4
src/entrypoints/content.js

@@ -88,7 +88,7 @@ export default defineContentScript({
                 form.removeEventListener('click', handleClick, true)
               }
               form = this
-              console.log(form,5855);
+              console.log(form, 5855)
               const cloneForm = this.cloneNode(true)
               cloneForm.querySelectorAll('svg').forEach((el) => el.remove())
               formChildren = [...form.elements]
@@ -259,15 +259,15 @@ export default defineContentScript({
             if (item.type === 'textarea') {
               input = findLabelForTextarea(label)
             } else input = findLabelForInput(label)
-            console.log(input,7585);
-            
+            console.log(input, 7585)
+
             if (input) {
               if (input.value) continue
               console.log(excelDataA[item.excelColumn])
               await simulateUserInput(input, excelDataA[item.excelColumn])
             }
           }
-          if (item.type === 'select' || item.type === "cascader") {
+          if (item.type === 'select' || item.type === 'cascader') {
             const input = findLabelForInput(label)
             if (input) {
               await simulateUserInput(input, excelDataA[item.excelColumn])

+ 1 - 2
src/entrypoints/sidepanel/Chat.vue

@@ -343,7 +343,7 @@ async function handleAsk() {
   const str = inputMessage.value.trim()
   inputMessage.value = ''
   if (sendLoading.value) return
-  addMessage(str)
+ await addMessage(str)
   if (type.value === FunctionList.Intelligent_Form_filling) {
     const res = await fetchRes(str)
     console.log(res);
@@ -358,7 +358,6 @@ async function handleAsk() {
       pageInfoList.value = []
     }
   } else streamRes(taklToHtml.value)
-  inputMessage.value = ''
 }
 
 function handleCapture() {

+ 53 - 54
src/entrypoints/sidepanel/hook/useMsg.ts

@@ -126,26 +126,26 @@ export function useMsg(scrollbar?: any) {
       const res = await awaitFindForm(obj)
       return res
     }
-   try {
-     const res = await fetchDataAndProcess(msg, obj)
-     sendLoading.value = false
-     if (res.status === 'ok') {
-       await new Promise((res: any) =>
-         setTimeout(() => {
-           res()
-         }, 2000)
-       )
-       const res = await awaitFindForm(obj)
-       console.log(res,34444);
+    try {
+      const res = await fetchDataAndProcess(msg, obj)
+      sendLoading.value = false
+      if (res.status === 'ok') {
+        await new Promise((res: any) =>
+          setTimeout(() => {
+            res()
+          }, 2000)
+        )
+        const res = await awaitFindForm(obj)
+        console.log(res, 34444)
 
-       return res
-     }
-   } catch (error) {
-     obj.content = '流程链执行出错'
-     return {status: 'error'}
-   } finally {
-     sendLoading.value = false
-   }
+        return res
+      }
+    } catch (error) {
+      obj.content = '流程链执行出错'
+      return { status: 'error' }
+    } finally {
+      sendLoading.value = false
+    }
   }
   let str = ''
   async function fetchDataAndProcess(input: any, obj: any) {
@@ -196,8 +196,7 @@ export function useMsg(scrollbar?: any) {
             if (status === 'error') {
               obj.content = data
               resolve({ data, status })
-              console.log(222);
-
+              console.log(222)
             }
             if (res.data.next === '是') {
               const arr = str.split(',')
@@ -233,9 +232,9 @@ export function useMsg(scrollbar?: any) {
       addToHistory: !taklToHtml.value
     })
     let history = []
-    console.log(taklToHtml.value);
-    console.log(messages.value);
-    
+    console.log(taklToHtml.value)
+    console.log(messages.value)
+
     if (taklToHtml.value) {
       if (addHtml) {
         history.push({
@@ -261,36 +260,36 @@ export function useMsg(scrollbar?: any) {
     nextTick(() => {
       scrollbar.value?.setScrollTop(99999)
     })
-   try {
-     const iterator = await sendMessage(history)
-     for await (const chunk of iterator) {
-       if (chunk) {
-         const decodedChunk = chunk.choices[0].delta.content
-         if (decodedChunk) {
-           // 保存原始内容
-           obj.rawContent += decodedChunk
-           // 实时格式化显示内容
-           obj.content = formatMessage(obj.rawContent)
-         }
-       }
-       scrollbar.value?.setScrollTop(99999)
-     }
-     if (type.value === FunctionList.Intelligent_Form_filling) {
-       obj.type = 'form' //
-     }
-     return {rawContent:obj.rawContent,status:'ok'}
-   } catch (error) {
-     obj.content = '网络出错'
-     return { rawContent: obj.rawContent, status: 'error' }
-   } finally {
-     //添加到存储历史
-    useStore(msgUuid.value).add(cloneDeep(obj))
-     // 处理最终内容
-     sendLoading.value = false
-     nextTick(() => {
-       scrollbar.value?.setScrollTop(99999)
-     })
-   }
+    try {
+      const iterator = await sendMessage(history)
+      for await (const chunk of iterator) {
+        if (chunk) {
+          const decodedChunk = chunk.choices[0].delta.content
+          if (decodedChunk) {
+            // 保存原始内容
+            obj.rawContent += decodedChunk
+            // 实时格式化显示内容
+            obj.content = formatMessage(obj.rawContent)
+          }
+        }
+        scrollbar.value?.setScrollTop(99999)
+      }
+      if (type.value === FunctionList.Intelligent_Form_filling) {
+        obj.type = 'form' //
+      }
+      return { rawContent: obj.rawContent, status: 'ok' }
+    } catch (error) {
+      obj.content = '网络出错'
+      return { rawContent: obj.rawContent, status: 'error' }
+    } finally {
+      //添加到存储历史
+      useStore(msgUuid.value).add(cloneDeep(obj))
+      // 处理最终内容
+      sendLoading.value = false
+      nextTick(() => {
+        scrollbar.value?.setScrollTop(99999)
+      })
+    }
   }
 
   /**

+ 12 - 13
src/entrypoints/sidepanel/utils/ai-service.js

@@ -5,7 +5,6 @@ import { getActivePinia } from 'pinia'
 import { useMsgStore } from '@/store/modules/msg.ts'
 import { ref } from 'vue'
 
-
 // 创建新的 AbortController
 export const controllerList = ref([])
 
@@ -19,12 +18,15 @@ export async function sendMessage(message) {
   try {
     const controller = new AbortController()
     controllerList.value.push(controller)
-    return await openai.chat.completions.create({
-      //模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
-      model: AIModel.value,
-      messages: message,
-      stream: true
-    }, { signal: controller.signal })
+    return await openai.chat.completions.create(
+      {
+        //模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
+        model: AIModel.value,
+        messages: message,
+        stream: true
+      },
+      { signal: controller.signal }
+    )
   } catch (error) {
     return { error: error }
   } finally {
@@ -38,8 +40,7 @@ export async function getFileContent(data) {
       body: data
     }).then((res) => res.json())
     return res
-  } catch (error) {
-  }
+  } catch (error) {}
 }
 
 export async function getFormKey(data) {
@@ -49,8 +50,7 @@ export async function getFormKey(data) {
       body: JSON.stringify(data)
     }).then((res) => res.json())
     return res
-  } catch (error) {
-  }
+  } catch (error) {}
 }
 
 export async function hepl(data) {
@@ -60,8 +60,7 @@ export async function hepl(data) {
       body: JSON.stringify(data)
     }).then((res) => res.json())
     return res
-  } catch (error) {
-  }
+  } catch (error) {}
 }
 
 function formatMessages(currentMessage, Summary, html) {

+ 90 - 87
src/utils/contentUtils.js

@@ -1,111 +1,114 @@
 export function formatDate(date) {
   // 检查日期是否为空
   if (!date) {
-    return '';
+    return ''
   }
-  
-  let d;
-  
+
+  let d
+
   // 处理各种日期格式
   if (typeof date === 'string') {
     // 处理中文年月日格式:YYYY年M月D日 或 YYYY年M月
     if (date.includes('年')) {
-      const yearMatch = date.match(/(\d+)年/);
-      const monthMatch = date.match(/(\d+)月/);
-      const dayMatch = date.match(/(\d+)日/);
-      
+      const yearMatch = date.match(/(\d+)年/)
+      const monthMatch = date.match(/(\d+)月/)
+      const dayMatch = date.match(/(\d+)日/)
+
       if (yearMatch && monthMatch) {
-        const year = yearMatch[1];
-        const month = String(parseInt(monthMatch[1])).padStart(2, '0');
+        const year = yearMatch[1]
+        const month = String(parseInt(monthMatch[1])).padStart(2, '0')
         // 如果有日,使用日,否则默认为1日
-        const day = dayMatch ? String(parseInt(dayMatch[1])).padStart(2, '0') : '01';
-        d = new Date(`${year}-${month}-${day}`);
+        const day = dayMatch
+          ? String(parseInt(dayMatch[1])).padStart(2, '0')
+          : '01'
+        d = new Date(`${year}-${month}-${day}`)
       } else {
-        d = new Date(date);
+        d = new Date(date)
       }
     }
     // 处理特殊格式:YYYY.M.D 或 YYYY.M
     else if (date.includes('.')) {
-      const parts = date.split('.');
+      const parts = date.split('.')
       if (parts.length >= 2) {
         // 将 YYYY.M.D 或 YYYY.M 转换为 YYYY-MM-DD 格式
-        const year = parts[0];
-        const month = String(parseInt(parts[1])).padStart(2, '0');
+        const year = parts[0]
+        const month = String(parseInt(parts[1])).padStart(2, '0')
         // 如果有日,使用日,否则默认为1日
-        const day = parts.length > 2 ? String(parseInt(parts[2])).padStart(2, '0') : '01';
-        d = new Date(`${year}-${month}-${day}`);
+        const day =
+          parts.length > 2 ? String(parseInt(parts[2])).padStart(2, '0') : '01'
+        d = new Date(`${year}-${month}-${day}`)
       } else {
-        d = new Date(date);
+        d = new Date(date)
       }
     }
     // 处理斜杠分隔格式:YYYY/M/D 或 D/M/YYYY
     else if (date.includes('/')) {
-      const parts = date.split('/');
+      const parts = date.split('/')
       if (parts.length === 3) {
         // 判断是 YYYY/MM/DD 还是 DD/MM/YYYY
         if (parts[0].length === 4) {
           // YYYY/MM/DD
-          const year = parts[0];
-          const month = String(parseInt(parts[1])).padStart(2, '0');
-          const day = String(parseInt(parts[2])).padStart(2, '0');
-          d = new Date(`${year}-${month}-${day}`);
+          const year = parts[0]
+          const month = String(parseInt(parts[1])).padStart(2, '0')
+          const day = String(parseInt(parts[2])).padStart(2, '0')
+          d = new Date(`${year}-${month}-${day}`)
         } else if (parts[2].length === 4) {
           // DD/MM/YYYY
-          const year = parts[2];
-          const month = String(parseInt(parts[1])).padStart(2, '0');
-          const day = String(parseInt(parts[0])).padStart(2, '0');
-          d = new Date(`${year}-${month}-${day}`);
+          const year = parts[2]
+          const month = String(parseInt(parts[1])).padStart(2, '0')
+          const day = String(parseInt(parts[0])).padStart(2, '0')
+          d = new Date(`${year}-${month}-${day}`)
         } else {
-          d = new Date(date);
+          d = new Date(date)
         }
       } else {
-        d = new Date(date);
+        d = new Date(date)
       }
     }
     // 处理短横线分隔格式:YYYY-M-D
     else if (date.includes('-')) {
-      const parts = date.split('-');
+      const parts = date.split('-')
       if (parts.length === 3) {
-        const year = parts[0];
-        const month = String(parseInt(parts[1])).padStart(2, '0');
-        const day = String(parseInt(parts[2])).padStart(2, '0');
-        d = new Date(`${year}-${month}-${day}`);
+        const year = parts[0]
+        const month = String(parseInt(parts[1])).padStart(2, '0')
+        const day = String(parseInt(parts[2])).padStart(2, '0')
+        d = new Date(`${year}-${month}-${day}`)
       } else {
-        d = new Date(date);
+        d = new Date(date)
       }
     }
     // 处理纯数字格式:YYYYMMDD
     else if (/^\d{8}$/.test(date)) {
-      const year = date.substring(0, 4);
-      const month = date.substring(4, 6);
-      const day = date.substring(6, 8);
-      d = new Date(`${year}-${month}-${day}`);
+      const year = date.substring(0, 4)
+      const month = date.substring(4, 6)
+      const day = date.substring(6, 8)
+      d = new Date(`${year}-${month}-${day}`)
     }
     // 其他字符串格式
     else {
-      d = new Date(date);
+      d = new Date(date)
     }
-  } 
+  }
   // 处理时间戳(数字)
   else if (typeof date === 'number') {
     // 判断是否为13位时间戳(毫秒)或10位时间戳(秒)
-    d = date > 10000000000 ? new Date(date) : new Date(date * 1000);
+    d = date > 10000000000 ? new Date(date) : new Date(date * 1000)
   }
   // 其他类型(如Date对象)
   else {
-    d = new Date(date);
+    d = new Date(date)
   }
-  
+
   // 检查日期是否有效
   if (isNaN(d.getTime())) {
-    return '';  // 如果日期无效,返回空字符串
+    return '' // 如果日期无效,返回空字符串
   }
-  
+
   // 获取年、月、日
-  const year = d.getFullYear();
-  const month = String(d.getMonth() + 1).padStart(2, '0'); // 月份从0开始,需要加1
-  const day = String(d.getDate()).padStart(2, '0');
-  return `${year}-${month}-${day}`;
+  const year = d.getFullYear()
+  const month = String(d.getMonth() + 1).padStart(2, '0') // 月份从0开始,需要加1
+  const day = String(d.getDate()).padStart(2, '0')
+  return `${year}-${month}-${day}`
 }
 
 export async function simulateCompleteUserAction(
@@ -240,48 +243,48 @@ export async function simulateUserInput(element, value) {
     element.value = value
     element.blur()
     return
-    }
-    const simulateTyping = async (element, text, delay = 50) => {
-        element.focus()
-        for (let char of text) {
-            await new Promise((resolve) => setTimeout(resolve, delay))
-
-            // 按键按下
-            const keydownEvent = new KeyboardEvent('keydown', {
-                key: char,
-                code: `Key${char.toUpperCase()}`,
-                bubbles: true,
-                cancelable: true
-            })
-            element.dispatchEvent(keydownEvent)
+  }
+  const simulateTyping = async (element, text, delay = 50) => {
+    element.focus()
+    for (let char of text) {
+      await new Promise((resolve) => setTimeout(resolve, delay))
 
-            // 更新输入值
-            element.value += char
+      // 按键按下
+      const keydownEvent = new KeyboardEvent('keydown', {
+        key: char,
+        code: `Key${char.toUpperCase()}`,
+        bubbles: true,
+        cancelable: true
+      })
+      element.dispatchEvent(keydownEvent)
 
-            // 触发输入事件
-            const inputEvent = new InputEvent('input', {
-                bubbles: true,
-                cancelable: true,
-                data: char,
-                inputType: 'insertText'
-            })
-            element.dispatchEvent(inputEvent)
+      // 更新输入值
+      element.value += char
 
-            // 按键弹起
-            const keyupEvent = new KeyboardEvent('keyup', {
-                key: char,
-                code: `Key${char.toUpperCase()}`,
-                bubbles: true,
-                cancelable: true
-            })
-            element.dispatchEvent(keyupEvent)
-        }
+      // 触发输入事件
+      const inputEvent = new InputEvent('input', {
+        bubbles: true,
+        cancelable: true,
+        data: char,
+        inputType: 'insertText'
+      })
+      element.dispatchEvent(inputEvent)
 
-        // 触发change事件
-        element.dispatchEvent(new Event('change', { bubbles: true }))
+      // 按键弹起
+      const keyupEvent = new KeyboardEvent('keyup', {
+        key: char,
+        code: `Key${char.toUpperCase()}`,
+        bubbles: true,
+        cancelable: true
+      })
+      element.dispatchEvent(keyupEvent)
     }
+
+    // 触发change事件
+    element.dispatchEvent(new Event('change', { bubbles: true }))
+  }
   element.value = value
-    // simulateTyping(element,value,50)
+  // simulateTyping(element,value,50)
   // 创建并触发 input 事件
   const inputEvent = new Event('input', { bubbles: true })
   element.dispatchEvent(inputEvent)

+ 1 - 1
wxt.config.ts

@@ -30,7 +30,7 @@ export default defineConfig({
       'sidePanel'
     ],
     content_security_policy: {
-      extension_pages: 'script-src \'self\'; object-src \'self\';'
+      extension_pages: "script-src 'self'; object-src 'self';"
     },
     action: {
       default_title: '派维斯智能体助手'