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

+ 6 - 5
src/entrypoints/content.js

@@ -141,9 +141,9 @@ export default defineContentScript({
             item.type === 'number'
           ) {
             if (!input) {
-              if (item.item) {
+              if (item.label) {
                 const label = [...form.getElementsByTagName('label')].find(
-                  (label) => label.innerText.includes(item.item)
+                  (label) => label.innerText.includes(item.label)
                 )
                 console.log(item,label)
                 if (label) {
@@ -159,9 +159,9 @@ export default defineContentScript({
             }
           }
           if (item.type === 'radio' || item.type === 'checkbox') {
-            if (item.item) {
+            if (item.label) {
               const label = [...form.getElementsByTagName('label')].find(
-                (label) => label.innerText.includes(item.item)
+                (label) => label.innerText.includes(item.label)
               )
               if (label) {
                 const span = findLabelForSpan(label)
@@ -250,10 +250,11 @@ export default defineContentScript({
             if (item.type === 'textarea') {
               input = findLabelForTextarea(label)
             } else input = findLabelForInput(label)
+            console.log(input,7585);
+            
             if (input) {
               if (input.value) continue
               console.log(excelDataA[item.excelColumn])
-
               await simulateUserInput(input, excelDataA[item.excelColumn])
             }
           }

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

@@ -267,6 +267,8 @@ function addNewDialogue() {
 }
 
 async function handleAsk() {
+  const str = inputMessage.value.trim()
+  inputMessage.value = ''
   if (sendLoading.value) return
   // 添加indexDB Store配置
   if (msgUuid.value === '') {
@@ -276,9 +278,9 @@ async function handleAsk() {
       keyPath: 'id'
     })
   }
-  addMessage(inputMessage.value.trim())
+  addMessage(str)
   if (type.value === '2') {
-    const res = await fetchRes(inputMessage.value.trim())
+    const res = await fetchRes(str)
     if (res.status === 'ok') {
       formInfo.value = res.data
       console.log(res);

+ 17 - 50
src/entrypoints/sidepanel/hook/useMsg.ts

@@ -5,8 +5,7 @@ import avator from '@/public/icon/32.png'
 import moment from 'moment'
 import {
   getFormKey,
-  buildObjPrompt,
-  getFileSummaryPrompt,
+  hepl,
   formatMessage,
   sendMessage
 } from '../utils/ai-service.js'
@@ -22,7 +21,6 @@ export function useMsg(scrollbar?: any) {
   const sendLoading = ref(false)
   const pageInfo = ref<any>({})
   const type = ref('')
-  const formMap = ref([])
   // 获取父组件提供的 Hook 实例
   const { useStore } = inject('indexedDBHook') as any
 
@@ -145,6 +143,7 @@ export function useMsg(scrollbar?: any) {
       return res
     }
     const res = await fetchDataAndProcess(msg, obj)
+    type.value = ''
     sendLoading.value = false
     if (res.status === 'ok') {
       await new Promise((res: any) =>
@@ -167,20 +166,20 @@ export function useMsg(scrollbar?: any) {
         res()
       }, 2000)
     )
-    // const res = await hepl({
-    //   input_data: input,
-    //   body: pageInfo.content.mainContent
-    // })
-    const res: any = await new Promise((resolve, reject) => {
-      setTimeout(() => {
-        resolve({
-          data:
-            pageInfo.title === '智能招采'
-              ? mockData[indexTemp.value]
-              : mockData2[indexTemp.value]
-        })
-      }, 1000)
+    const res = await hepl({
+      input_data: input,
+      body: pageInfo.content.mainContent
     })
+    // const res: any = await new Promise((resolve, reject) => {
+    //   setTimeout(() => {
+    //     resolve({
+    //       data:
+    //         pageInfo.title === '智能招采'
+    //           ? mockData[indexTemp.value]
+    //           : mockData2[indexTemp.value]
+    //     })
+    //   }, 1000)
+    // })
     if (!res.data.tag || res.data.tag === 'undefined') {
       ElMessage({
         message: '未找到标签,请重试',
@@ -206,6 +205,8 @@ export function useMsg(scrollbar?: any) {
             if (status === 'error') {
               obj.content = data
               resolve({ data, status })
+              console.log(222);
+              
             }
             if (res.data.next === '是') {
               const arr = str.split(',')
@@ -215,23 +216,6 @@ export function useMsg(scrollbar?: any) {
               const res = await fetchDataAndProcess(str, obj)
               resolve(res)
             } else resolve({ status: 'ok' })
-            // else {
-            //   await new Promise((resolve, reject) => {
-            //     setTimeout(() => {
-            //       resolve(1)
-            //     }, 2000)
-            //   })
-            //   obj.content = `请选择表单`
-            //   ElMessage({
-            //     message: '请选择表单',
-            //     type: 'success',
-            //     duration: 4 * 1000,
-            //     grouping: true
-            //   })
-            //   chrome.runtime.sendMessage({
-            //     type: 'FROM_SIDE_PANEL_TO_GET_PAGE_FORM'
-            //   })
-            // }
           }
         }
       )
@@ -296,8 +280,6 @@ export function useMsg(scrollbar?: any) {
       }
       scrollbar.value?.setScrollTop(99999)
     }
-    console.log(obj.rawContent);
-
     //添加到存储历史
     useStore(msgUuid.value).add({ ...obj })
     // 处理最终内容
@@ -305,20 +287,6 @@ export function useMsg(scrollbar?: any) {
     nextTick(() => {
       scrollbar.value?.setScrollTop(99999)
     })
-    if (type.value === '2') {
-      const arr = JSON.parse(obj.rawContent.split('json')[1].split('```')[0])
-      const newArr = arr.map(obj => {
-        return `| ${[
-          `“findBy”: \` "label",`,
-          `"findByValue" \` “${obj.findByValue}”,`,
-          `"数据来源字段" \` “${obj.excelColumn}”,`,
-          `"表单项" \` “${obj.item}"`
-        ].join(' ')} |`;
-      }).join('\n');
-      obj.content = formatMessage('```json' + JSON.stringify(newArr) + '```')
-      console.log(formatMessage('```json' + JSON.stringify(newArr) + '```'));
-
-    }
     return obj.rawContent
   }
 
@@ -367,7 +335,6 @@ export function useMsg(scrollbar?: any) {
     indexTemp,
     taklToHtml,
     sendLoading,
-    formMap,
     type,
     fetchRes,
     streamRes,

+ 4 - 4
src/entrypoints/sidepanel/utils/ai-service.js

@@ -232,8 +232,8 @@ ${pageInfo}
 2. 生成表单项与列标题对应的数组,并使用findBy告诉我通过表单项的什么字段信息匹配到的,使用findByValue告诉我匹配到的表单项字段值,使用excelColumn字段告诉我excel文件中列标题的值。
 3. 表单项有id根据id匹配,findBy是id,并通过findByValue告诉我id的值,没有id根据label匹配,findBy是label,并通过findByValue给我label元素的值,没有label根据placeholder匹配,findBy是placeholder,并通过findByValue告诉我placeholder的值,没有placeholder,再根据其他内容匹配
 3. 并去除没有匹配到的表单项和excel文件中没有匹配到的列,
-4. 通过type字段告诉我输入项的类型,表单项有label,通过item字段返回label的值。
-5. 返回json格式数组,不要返回任何其他内容`
+4. 通过type字段告诉我输入项的类型,表单项有label,通过label字段返回label的值。
+5. 返回json格式数组,不要返回其他任何内容`
 }
 
 
@@ -251,8 +251,8 @@ ${pageInfo}
 3. 并根据实际可操作的表单项的所有信息与上传的对象的key进行匹配,生成表单项与key的数组,并使用findBy告诉我通过表单项的什么字段信息匹配到的,使用findByValue告诉我匹配到的表单项字段值,使用excelColumn字段告诉我对应的key值。在一个字段内返回
 4. 并去除没有匹配到的表单项和对象中没有匹配到的key,
 5. 通过type字段告诉我输入项的类型,如果对象中key对应的是日期,type统一返回date。
-6. 表单项有label,通过item字段返回label的值。
-7. 返回json格式返回数组,不要返回任何其他内容`
+6. 表单项有label,通过label字段返回label的值。
+7. 返回json格式返回数组,不要返回其他任何内容`
 }
 
 function escapeHtml(html) {

+ 3 - 3
src/utils/page-analyzer.js

@@ -64,9 +64,9 @@ export default class PageAnalyzer {
         content.textContent = form.outerHTML
       }
     } else {
-      // const content = document.body.cloneNode(true)
-      // return cleanPage(content)
-      return document.documentElement.outerHTML
+      const content = document.body.cloneNode(true)
+      return cleanPage(content)
+      // return document.documentElement.outerHTML
       // .trim().replace(/\s+/g, " ")
       // content
       //     .querySelectorAll("script, style, iframe, nav, header, footer,svg")