|
@@ -24,7 +24,6 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
</el-scrollbar>
|
|
|
-
|
|
|
<Tools @read-click="readClick" @upload-file="handleUpload" @handle-capture="handleCapture" />
|
|
|
|
|
|
<div>
|
|
@@ -73,14 +72,13 @@
|
|
|
<script setup>
|
|
|
import { ref, onMounted, nextTick, inject, useTemplateRef } from 'vue'
|
|
|
import { ElScrollbar, ElAvatar, ElInput, ElButton } from 'element-plus'
|
|
|
-import { buildExcelUnderstandingPrompt } from '@/utils/ai-service.js'
|
|
|
+import { buildExcelUnderstandingPrompt ,getFileContent} from '@/utils/ai-service.js'
|
|
|
import * as XLSX from "xlsx";
|
|
|
import { ElMessage } from 'element-plus';
|
|
|
import { useMsg } from '@/entrypoints/sidepanel/hook/useMsg.ts';
|
|
|
import Tools from "@/entrypoints/sidepanel/component/tools.vue";
|
|
|
import { useSummary } from '@/entrypoints/sidepanel/hook/useSummary.ts'
|
|
|
-import { mockData } from "@/entrypoints/sidepanel/mock"
|
|
|
-import {upload} from '@/utils/ai-service'
|
|
|
+import { mockData,mockData2 } from "@/entrypoints/sidepanel/mock"
|
|
|
import { useAutoResizeTextarea } from '@/entrypoints/sidepanel/hook/useAutoResizeTextarea.ts';
|
|
|
|
|
|
// 滚动条引用
|
|
@@ -100,17 +98,14 @@ const {
|
|
|
sendRequese,
|
|
|
getPageInfo,
|
|
|
streamRes,
|
|
|
- handleInput
|
|
|
+ handleInput,
|
|
|
+ getFileValue
|
|
|
} = useMsg(scrollbar, xlsxData, fetchDataAndProcess);
|
|
|
const { handleCardButtonClick } = useSummary(addMessage, sendRequese);
|
|
|
|
|
|
function handelIntelligentFillingClick() {
|
|
|
- if (type.value !== '2') {
|
|
|
- inputMessage.value = '/智能填表 '
|
|
|
- type.value = '2'
|
|
|
- } else {
|
|
|
- type.value = ''
|
|
|
- }
|
|
|
+ inputMessage.value = '/智能填表 '
|
|
|
+ type.value = '2'
|
|
|
}
|
|
|
|
|
|
async function readClick() {
|
|
@@ -142,9 +137,8 @@ let formInfo = []
|
|
|
const flag = ref(false) //true调用算法接口
|
|
|
|
|
|
const handleUpload = (file) => {
|
|
|
- console.log(upload);
|
|
|
-
|
|
|
- chrome.runtime.sendMessage({
|
|
|
+ if (type.value === '2') {
|
|
|
+ chrome.runtime.sendMessage({
|
|
|
type: 'FROM_SIDE_PANEL_TO_GET_PAGE_FORM',
|
|
|
}, async (response) => {
|
|
|
if (chrome.runtime.lastError) {
|
|
@@ -153,9 +147,9 @@ const handleUpload = (file) => {
|
|
|
console.log(file);
|
|
|
addMessage(`已上传文件:${file.name}`, false)
|
|
|
const fileExtension = file.name.split('.').pop().toLowerCase();
|
|
|
- formInfo = response.data
|
|
|
+ if (response.status === 'error') return ElMessage({message:response.message,type: 'error', duration: 4 * 1000, grouping: true})
|
|
|
+ formInfo = response.data
|
|
|
if (fileExtension === 'xlsx') {
|
|
|
-
|
|
|
const reader = new FileReader();
|
|
|
reader.readAsArrayBuffer(file);
|
|
|
reader.onload = async (e) => {
|
|
@@ -181,29 +175,33 @@ const handleUpload = (file) => {
|
|
|
console.log(readData, 58);
|
|
|
|
|
|
readData[0].forEach((header, i) => {
|
|
|
- if (!xlsxData.value[header]) xlsxData.value[header] = []
|
|
|
- xlsxData.value[header].push(readData[1][i])
|
|
|
+ // if (!xlsxData.value[header]) xlsxData.value[header] = []
|
|
|
+ xlsxData.value[header] = readData[1][i]
|
|
|
})
|
|
|
if (type.value === '2') {
|
|
|
await streamRes(buildExcelUnderstandingPrompt(readData, file?.name, response), false)
|
|
|
}
|
|
|
};
|
|
|
} else {
|
|
|
- let formData = new FormData();
|
|
|
- formData.append("file", file);
|
|
|
- const res = await upload(formData)
|
|
|
- const keys = Object.keys(res)
|
|
|
- const values = Object.values(res)
|
|
|
- readData[0].forEach((header, i) => {
|
|
|
- if (!xlsxData.value[header]) xlsxData.value[header] = []
|
|
|
- xlsxData.value[header].push(readData[1][i])
|
|
|
- })
|
|
|
- console.log(res);
|
|
|
+ await getFileValue(file, response.data)
|
|
|
+
|
|
|
+ // const keys = Object.keys(res)
|
|
|
+ // const values = Object.values(res)
|
|
|
+ // readData[0].forEach((header, i) => {
|
|
|
+ // if (!xlsxData.value[header]) xlsxData.value[header] = []
|
|
|
+ // xlsxData.value[header].push(readData[1][i])
|
|
|
+ // })
|
|
|
+ // console.log(res);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
return true
|
|
|
});
|
|
|
|
|
|
+ }
|
|
|
+ if (type.value === '') {
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
let str = ''
|
|
|
async function fetchDataAndProcess(input, obj) {
|
|
@@ -212,69 +210,70 @@ async function fetchDataAndProcess(input, obj) {
|
|
|
}
|
|
|
str = input
|
|
|
console.log(str);
|
|
|
-
|
|
|
const pageInfo = await getPageInfo();
|
|
|
await new Promise(res => setTimeout(() => {
|
|
|
res()
|
|
|
- }, 1000))
|
|
|
- const res = await hepl({
|
|
|
- input_data: input,
|
|
|
- body:pageInfo.content.mainContent
|
|
|
- })
|
|
|
- // const res = await new Promise((resolve, reject) => {
|
|
|
- // setTimeout(() => {
|
|
|
- // resolve({ data: mockData[indexTemp.value] })
|
|
|
- // }, 1000)
|
|
|
+ }, 2000))
|
|
|
+ // const res = await hepl({
|
|
|
+ // input_data: input,
|
|
|
+ // body: pageInfo.content.mainContent
|
|
|
// })
|
|
|
+ console.log(pageInfo.title);
|
|
|
+
|
|
|
+ const res = 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: '未找到标签,请重试', type: 'error', duration: 4 * 1000, grouping: true })
|
|
|
+ obj.content = '未找到标签,请重试'
|
|
|
+ type.value = ''
|
|
|
+ return
|
|
|
+ }
|
|
|
await handleClick(res.data, obj);
|
|
|
}
|
|
|
|
|
|
|
|
|
async function handleClick(res, msgObj) {
|
|
|
await new Promise(resolve => setTimeout(resolve, 2000))
|
|
|
- msgObj.content = `点击${res.tag}元素`
|
|
|
- chrome.runtime.sendMessage({
|
|
|
- type: 'FROM_SIDE_PANEL_TO_ACTION',
|
|
|
- data: res
|
|
|
- }, async (response) => {
|
|
|
- if (chrome.runtime.lastError) {
|
|
|
- console.error("消息发送错误:", chrome.runtime.lastError);
|
|
|
- rej(chrome.runtime.lastError)
|
|
|
+ msgObj.content = `点击${res.tag}元素`
|
|
|
+ chrome.runtime.sendMessage({
|
|
|
+ type: 'FROM_SIDE_PANEL_TO_ACTION',
|
|
|
+ data: res
|
|
|
+ }, async ({ data, status }) => {
|
|
|
+ if (chrome.runtime.lastError) {
|
|
|
+ console.error("消息发送错误:", chrome.runtime.lastError);
|
|
|
+ rej(chrome.runtime.lastError)
|
|
|
+ } else {
|
|
|
+ if (status === 'error') {
|
|
|
+ msgObj.content = data
|
|
|
+ type.value = ''
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (res.next === '是') {
|
|
|
+ const arr = str.split(',')
|
|
|
+ arr.shift()
|
|
|
+ str = arr.join(',')
|
|
|
+ indexTemp.value++
|
|
|
+ fetchDataAndProcess(str, msgObj)
|
|
|
} else {
|
|
|
- if (res.next === '是') {
|
|
|
- indexTemp.value++
|
|
|
- const arr = str.split(',')
|
|
|
- arr.shift()
|
|
|
- str = arr.join(',')
|
|
|
- fetchDataAndProcess(str, msgObj)
|
|
|
- } else {
|
|
|
+ if (type.value === '2') {
|
|
|
+ await new Promise((resolve, reject) => {
|
|
|
+ setTimeout(() => {
|
|
|
+ resolve()
|
|
|
+ }, 2000)
|
|
|
+ })
|
|
|
msgObj.content = `请上传数据`
|
|
|
ElMessage({ message: '请上传数据', type: 'success', duration: 4 * 1000, grouping: true })
|
|
|
+ } else {
|
|
|
+ msgObj.content = `执行完毕`
|
|
|
}
|
|
|
}
|
|
|
- return true
|
|
|
- });
|
|
|
-
|
|
|
- // chrome.runtime.sendMessage({
|
|
|
- // type: 'FROM_SIDE_PANEL_TO_ACTION',
|
|
|
- // data:obj
|
|
|
- // }, async (response) => {
|
|
|
- // if (chrome.runtime.lastError) {
|
|
|
- // console.error("消息发送错误:", chrome.runtime.lastError);
|
|
|
- // rej(chrome.runtime.lastError)
|
|
|
- // } else {
|
|
|
- // if (obj.next === '是') {
|
|
|
- // console.log(strArr[index]);
|
|
|
-
|
|
|
- // index++
|
|
|
- // fetchDataAndProcess(strArr[index])
|
|
|
- // } else {
|
|
|
- // ElMessage({ message: '操作执行完成', type: 'success', duration: 2 * 1000, grouping: true })
|
|
|
- // index = 0
|
|
|
- // }
|
|
|
- // }
|
|
|
- // return true
|
|
|
- // });
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ });
|
|
|
+
|
|
|
}
|
|
|
|
|
|
const isHoveringTitle = ref(false)
|