|
@@ -87,14 +87,14 @@ import {ref, onMounted, nextTick, inject, useTemplateRef} from 'vue'
|
|
|
import {ElScrollbar, ElAvatar, ElInput, ElButton} from 'element-plus'
|
|
|
import moment from "moment";
|
|
|
import { buildExcelUnderstandingPrompt ,getFileSummaryPrompt,getSummaryPrompt,getFileContent,buildObjPrompt } 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 historyComponent from '@/entrypoints/sidepanel/component/historyComponent.vue';
|
|
|
import {mockData, startMsg, mockData2} from "@/entrypoints/sidepanel/mock"
|
|
|
import { useAutoResizeTextarea } from '@/entrypoints/sidepanel/hook/useAutoResizeTextarea.ts';
|
|
|
-import {getPageInfo} from './utils/index.js'
|
|
|
+import {getPageInfo,getXlsxValue,handleInput} from './utils/index.js'
|
|
|
|
|
|
// 滚动条引用
|
|
|
const scrollbar = ref(null);
|
|
@@ -109,9 +109,10 @@ const {
|
|
|
messages,
|
|
|
taklToHtml,
|
|
|
sendLoading,
|
|
|
+ type,
|
|
|
streamRes,
|
|
|
- handleInput,
|
|
|
- getFormKeyAndValue
|
|
|
+ getFormKeyAndValue,
|
|
|
+ handleSend
|
|
|
} = useMsg(scrollbar, xlsxData);
|
|
|
const inputMessage = ref('')
|
|
|
const pageInfo = ref('')
|
|
@@ -129,24 +130,20 @@ const addMessage = (msg, raw) => {
|
|
|
})
|
|
|
messages.value.push(newMessage)
|
|
|
useStore(msgUuid.value).add(newMessage)
|
|
|
- // 滚动到底部
|
|
|
nextTick(() => {
|
|
|
scrollbar.value?.setScrollTop(99999);
|
|
|
})
|
|
|
return newMessage
|
|
|
-
|
|
|
}
|
|
|
const handleSummary = async () => {
|
|
|
const res = await getPageInfo()
|
|
|
addMessage('总结页面',getSummaryPrompt(res.content))
|
|
|
- streamRes()
|
|
|
+ handleSend()
|
|
|
}
|
|
|
-const type = ref('')
|
|
|
function handelIntelligentFillingClick() {
|
|
|
inputMessage.value = '/智能填表 '
|
|
|
type.value = '2'
|
|
|
}
|
|
|
-
|
|
|
function handleCurrentData(e) {
|
|
|
drawerRef.value.drawer = false;
|
|
|
if (!e) {
|
|
@@ -162,11 +159,10 @@ function handleCurrentData(e) {
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
-
|
|
|
async function readClick() {
|
|
|
isShowPage.value = true;
|
|
|
taklToHtml.value = true;
|
|
|
- await getPageInfo()
|
|
|
+ pageInfo.value = await getPageInfo()
|
|
|
}
|
|
|
|
|
|
function addNewDialogue() {
|
|
@@ -179,14 +175,13 @@ function addNewDialogue() {
|
|
|
messages.value.push(startMsg);
|
|
|
useStore(msgUuid.value).add(startMsg);
|
|
|
}
|
|
|
-
|
|
|
async function handleAsk() {
|
|
|
if (sendLoading.value) return;
|
|
|
addMessage(inputMessage.value.trim());
|
|
|
+ handleSend(inputMessage.value.trim())
|
|
|
inputMessage.value = '';
|
|
|
- streamRes(taklToHtml)
|
|
|
+ // streamRes(taklToHtml)
|
|
|
}
|
|
|
-
|
|
|
function handleCapture() {
|
|
|
ElMessage({
|
|
|
message: '开发中...',
|
|
@@ -194,17 +189,13 @@ function handleCapture() {
|
|
|
showClose: true
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
function hisRecords() {
|
|
|
drawerRef.value.drawer = true;
|
|
|
}
|
|
|
-
|
|
|
// 计算标题是否需要滚动
|
|
|
const titleScroll = computed(() => {
|
|
|
return pageInfo.value?.title?.length > 20 // 当标题超过20个字符时触发滚动
|
|
|
})
|
|
|
-
|
|
|
-
|
|
|
const handleUpload =async (file) => {
|
|
|
if (type.value === '2') {
|
|
|
chrome.runtime.sendMessage({
|
|
@@ -215,74 +206,52 @@ const handleUpload =async (file) => {
|
|
|
} else {
|
|
|
const fileExtension = file.name.split('.').pop().toLowerCase();
|
|
|
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) => {
|
|
|
- const data = new Uint8Array(e.target.result);
|
|
|
- const workbook = XLSX.read(data, {
|
|
|
- type: "array",
|
|
|
- cellDates: false,
|
|
|
- cellNF: true,
|
|
|
- cellText: true,
|
|
|
- dateNF: 'yyyy-mm-dd'
|
|
|
- });
|
|
|
-
|
|
|
- // 修复日期处理
|
|
|
- const firstSheet = workbook.Sheets[workbook.SheetNames[0]];
|
|
|
-
|
|
|
- // 转换为JSON数据
|
|
|
- const readData = XLSX.utils.sheet_to_json(firstSheet, {
|
|
|
- header: 1,
|
|
|
- raw: false,
|
|
|
- defval: "",
|
|
|
- dateNF: 'yyyy-mm-dd'
|
|
|
- });
|
|
|
- console.log(readData, 58);
|
|
|
-
|
|
|
- readData[0].forEach((header, i) => {
|
|
|
+ const readData = await getXlsxValue(file)
|
|
|
+ readData[0].forEach((header, i) => {
|
|
|
// if (!xlsxData.value[header]) xlsxData.value[header] = []
|
|
|
xlsxData.value[header] = readData[1][i]
|
|
|
})
|
|
|
- addMessage(`已上传文件:${file.name}`,buildExcelUnderstandingPrompt(readData, file?.name, response.data))
|
|
|
- await streamRes()
|
|
|
- };
|
|
|
+ addMessage(`已上传文件:${file.name}`,buildExcelUnderstandingPrompt(readData[0], file?.name, response.data))
|
|
|
+ const a = await streamRes()
|
|
|
+ handleInput(xlsxData.value,JSON.parse(a.split('json')[1].split('```')[0]))
|
|
|
} else {
|
|
|
- const msg = addMessage(`文件上传中`,)
|
|
|
- sendLoading.value = true
|
|
|
- let formData = new FormData();
|
|
|
- formData.append("file", file);
|
|
|
- const res = await getFileContent(formData)
|
|
|
- sendLoading.value = false
|
|
|
- msg.content = `已上传文件:${file.name}`
|
|
|
- msg.rawContent = getFileSummaryPrompt(res.data, file.name)
|
|
|
- const res2 = await getFormKeyAndValue(res.data,response.data)
|
|
|
- xlsxData.value = res2.data
|
|
|
- console.log(xlsxData.value);
|
|
|
- console.log(type.value);
|
|
|
+ const {data,msg} = await getFileValue(file)
|
|
|
+ const res2 = await getFormKeyAndValue(data,response.data)
|
|
|
+ xlsxData.value = res2.data
|
|
|
+ msg.rawContent = buildObjPrompt(res2.data, response.data)
|
|
|
+ console.log();
|
|
|
+
|
|
|
+ const a = await streamRes()
|
|
|
+ handleInput(xlsxData.value,JSON.parse(a.split('json')[1].split('```')[0]))
|
|
|
+ console.log(xlsxData.value);
|
|
|
+ console.log(type.value);
|
|
|
}
|
|
|
}
|
|
|
return true
|
|
|
});
|
|
|
}
|
|
|
if (type.value === '') {
|
|
|
+ const fileVaue = await getFileValue(file)
|
|
|
+ // streamRes()
|
|
|
+ }
|
|
|
+}
|
|
|
+let str = ''
|
|
|
+async function getFileValue(file) {
|
|
|
const msg = addMessage(`文件上传中`,)
|
|
|
sendLoading.value = true
|
|
|
- let formData = new FormData();
|
|
|
+ let formData = new FormData();
|
|
|
formData.append("file", file);
|
|
|
const res = await getFileContent(formData)
|
|
|
sendLoading.value = false
|
|
|
msg.content = `已上传文件:${file.name}`
|
|
|
- msg.rawContent = getFileSummaryPrompt(res.data, file.name)
|
|
|
- streamRes()
|
|
|
- }
|
|
|
+ msg.rawContent = res.data
|
|
|
+ return {
|
|
|
+ data: res.data,
|
|
|
+ msg
|
|
|
+ }
|
|
|
}
|
|
|
-let str = ''
|
|
|
-
|
|
|
-
|
|
|
const isHoveringTitle = ref(false)
|
|
|
-
|
|
|
// 组件挂载时滚动到底部
|
|
|
onMounted(() => {
|
|
|
useAutoResizeTextarea(tareRef, inputMessage);
|
|
@@ -299,11 +268,9 @@ onMounted(() => {
|
|
|
pageInfo.value = message.data
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
nextTick(() => {
|
|
|
scrollbar.value?.setScrollTop(99999)
|
|
|
})
|
|
|
-
|
|
|
// 添加标题悬停事件监听
|
|
|
nextTick(() => {
|
|
|
const titleWrapper = document.querySelector('.title-wrapper')
|
|
@@ -317,7 +284,6 @@ onMounted(() => {
|
|
|
}
|
|
|
scrollbar.value?.setScrollTop(99999)
|
|
|
})
|
|
|
-
|
|
|
// 添加indexDB Store配置
|
|
|
msgUuid.value = 'D' + Date.now().toString();
|
|
|
registerStore({
|