|
@@ -47,13 +47,16 @@
|
|
<ScrollToBottom :target="scrollbar" ref="scrollToBottomRef" />
|
|
<ScrollToBottom :target="scrollbar" ref="scrollToBottomRef" />
|
|
</div>
|
|
</div>
|
|
|
|
|
|
- <Tools @read-click="readClick" @upload-file="(file) => createFileObj(file)" @handle-capture="handleCapture" @his-records="hisRecords"
|
|
|
|
|
|
+ <Tools :upload="type === FunctionList.File_Operation || !!formInfo" @read-click="readClick" @upload-file="(file) => createFileObj(file)" @handle-capture="handleCapture" @his-records="hisRecords"
|
|
@add-new-dialogue="addNewDialogue" @handle-current-change="handleCurrentChange"
|
|
@add-new-dialogue="addNewDialogue" @handle-current-change="handleCurrentChange"
|
|
@handel-intelligent-filling-click="handelIntelligentFillingClick" />
|
|
@handel-intelligent-filling-click="handelIntelligentFillingClick" />
|
|
|
|
|
|
<div>
|
|
<div>
|
|
<!-- 输入区域 -->
|
|
<!-- 输入区域 -->
|
|
<div class="input-area">
|
|
<div class="input-area">
|
|
|
|
+ <el-icon class="closeShow" :style="{ display: isShowPage ? 'block' : 'none'}" size="16px" color="#909399" @click="closePageInfo">
|
|
|
|
+ <CircleClose />
|
|
|
|
+ </el-icon>
|
|
<div v-show="isShowPage" style="border-bottom: 1px solid #F0F0F0;">
|
|
<div v-show="isShowPage" style="border-bottom: 1px solid #F0F0F0;">
|
|
<div class="card_list">
|
|
<div class="card_list">
|
|
<div v-for="(v, i) in pageInfoList" :key="i"
|
|
<div v-for="(v, i) in pageInfoList" :key="i"
|
|
@@ -71,6 +74,7 @@
|
|
<CircleClose />
|
|
<CircleClose />
|
|
</el-icon>
|
|
</el-icon>
|
|
</div>
|
|
</div>
|
|
|
|
+ <div v-show="!pageInfoList.length && type === FunctionList.Intelligent_Form_filling">智能填表</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class="card-btn">
|
|
<div class="card-btn">
|
|
@@ -113,11 +117,8 @@ import { ElScrollbar, ElAvatar, ElInput, ElButton } from 'element-plus'
|
|
import moment from 'moment'
|
|
import moment from 'moment'
|
|
import fileLogo from '@/assets/svg/file.svg'
|
|
import fileLogo from '@/assets/svg/file.svg'
|
|
import {
|
|
import {
|
|
- buildExcelUnderstandingPrompt,
|
|
|
|
- getSummaryPrompt,
|
|
|
|
getFileContent,
|
|
getFileContent,
|
|
buildObjPrompt,
|
|
buildObjPrompt,
|
|
- modelFileUpload,
|
|
|
|
controllerList,
|
|
controllerList,
|
|
formatMessage
|
|
formatMessage
|
|
} from '@/entrypoints/sidepanel/utils/ai-service.js'
|
|
} from '@/entrypoints/sidepanel/utils/ai-service.js'
|
|
@@ -132,7 +133,7 @@ import ScrollToBottom from '@/entrypoints/sidepanel/component/ScrollToBottom.vue
|
|
import formTable from '@/entrypoints/sidepanel/component/formTable.vue'
|
|
import formTable from '@/entrypoints/sidepanel/component/formTable.vue'
|
|
import userAvatar from '@/assets/images/user.png'
|
|
import userAvatar from '@/assets/images/user.png'
|
|
import avatar from '@/public/icon/32.png'
|
|
import avatar from '@/public/icon/32.png'
|
|
-import { mockData, startMsg, mockData2, options, FunctionList } from '@/entrypoints/sidepanel/mock'
|
|
|
|
|
|
+import { options, FunctionList } from '@/entrypoints/sidepanel/mock'
|
|
import { useAutoResizeTextarea } from '@/entrypoints/sidepanel/hook/useAutoResizeTextarea.ts'
|
|
import { useAutoResizeTextarea } from '@/entrypoints/sidepanel/hook/useAutoResizeTextarea.ts'
|
|
import { getPageInfo, getXlsxValue, handleInput } from './utils/index.js'
|
|
import { getPageInfo, getXlsxValue, handleInput } from './utils/index.js'
|
|
import { useMsgStore } from '@/store/modules/msg.ts'
|
|
import { useMsgStore } from '@/store/modules/msg.ts'
|
|
@@ -140,14 +141,10 @@ import { useUserStore } from '@/store/modules/user'
|
|
import { putChat, uploadFile } from "@/api/index.js";
|
|
import { putChat, uploadFile } from "@/api/index.js";
|
|
import {askQues,getFormKey} from '@/api/modal.js'
|
|
import {askQues,getFormKey} from '@/api/modal.js'
|
|
import { debounce } from 'lodash'
|
|
import { debounce } from 'lodash'
|
|
-import request from '@/utils/request'
|
|
|
|
-import EventSourcePolyfill from 'eventsource-polyfill';
|
|
|
|
const userStore = useUserStore()
|
|
const userStore = useUserStore()
|
|
-import { getChatDetail } from '@/api/index.js'
|
|
|
|
// 在其他状态变量附近添加
|
|
// 在其他状态变量附近添加
|
|
const isLoadingMore = ref(false)
|
|
const isLoadingMore = ref(false)
|
|
import { v4 as uuidv4 } from 'uuid';
|
|
import { v4 as uuidv4 } from 'uuid';
|
|
-import content from '../content.js'
|
|
|
|
// 滚动条引用
|
|
// 滚动条引用
|
|
const scrollbar = ref(null)
|
|
const scrollbar = ref(null)
|
|
const scrollToBottomRef = ref(null)
|
|
const scrollToBottomRef = ref(null)
|
|
@@ -163,9 +160,6 @@ const {
|
|
taklToHtml,
|
|
taklToHtml,
|
|
sendLoading,
|
|
sendLoading,
|
|
type,
|
|
type,
|
|
- streamRes,
|
|
|
|
- getFormKeyAndValue,
|
|
|
|
- requestFlowFn,
|
|
|
|
fetchRes
|
|
fetchRes
|
|
} = useMsg(scrollbar)
|
|
} = useMsg(scrollbar)
|
|
const inputMessage = ref('')
|
|
const inputMessage = ref('')
|
|
@@ -259,7 +253,6 @@ async function addMessage(msg, raw, type) {
|
|
const handleSummary = async () => {
|
|
const handleSummary = async () => {
|
|
if(sendLoading.value) return
|
|
if(sendLoading.value) return
|
|
handleAsk(`请帮我总结当前${summaryHtml.value ? '页面' : '文件'}`)
|
|
handleAsk(`请帮我总结当前${summaryHtml.value ? '页面' : '文件'}`)
|
|
-
|
|
|
|
summaryHtml.value = false
|
|
summaryHtml.value = false
|
|
}
|
|
}
|
|
const handleSummaryFile = async () => {
|
|
const handleSummaryFile = async () => {
|
|
@@ -269,55 +262,42 @@ const handleSummaryFile = async () => {
|
|
const userMsg = await addMessage(JSON.stringify([...pageInfoList.value, { type: 'text', value: '抽取表单' }]), '抽取表单', 'document')
|
|
const userMsg = await addMessage(JSON.stringify([...pageInfoList.value, { type: 'text', value: '抽取表单' }]), '抽取表单', 'document')
|
|
userMsg.fileId = pageInfoList.value[0].fileId
|
|
userMsg.fileId = pageInfoList.value[0].fileId
|
|
userMsg.redisKey = pageInfoList.value[0].redisKey
|
|
userMsg.redisKey = pageInfoList.value[0].redisKey
|
|
- await putChat(userMsg)
|
|
|
|
- const msg = reactive({
|
|
|
|
- type: '',
|
|
|
|
- rawContent: '',
|
|
|
|
- senderId: -1,
|
|
|
|
- receiverId: userStore.userInfo.id, //大模型
|
|
|
|
- content: '',
|
|
|
|
- sortKey: moment().valueOf(),
|
|
|
|
- role: 'system',
|
|
|
|
- conversationId: msgUuid.value,
|
|
|
|
- })
|
|
|
|
- messages.value.push(msg)
|
|
|
|
|
|
+ await putChat(userMsg)
|
|
|
|
+ createWS(userMsg)
|
|
|
|
+ formInfo.value = ''
|
|
|
|
+ // const msg = reactive({
|
|
|
|
+ // type: '',
|
|
|
|
+ // rawContent: '',
|
|
|
|
+ // senderId: -1,
|
|
|
|
+ // receiverId: userStore.userInfo.id, //大模型
|
|
|
|
+ // content: '',
|
|
|
|
+ // sortKey: moment().valueOf(),
|
|
|
|
+ // role: 'system',
|
|
|
|
+ // conversationId: msgUuid.value,
|
|
|
|
+ // })
|
|
|
|
+ // messages.value.push(msg)
|
|
isShowPage.value = false
|
|
isShowPage.value = false
|
|
- pageInfoList.value = []
|
|
|
|
- const resForm = await askQues({
|
|
|
|
- conversationId: msgUuid.value,
|
|
|
|
- modelName: '通义千问-Max',
|
|
|
|
- question: buildObjPrompt(xlsxData.value,formInfo.value),
|
|
|
|
- id: '699637194561691650',
|
|
|
|
- // redisKey:msg.redisKey
|
|
|
|
- })
|
|
|
|
- return console.log(resForm);
|
|
|
|
|
|
+ pageInfoList.value = []
|
|
|
|
+ // const resForm = await askQues({
|
|
|
|
+ // conversationId: msgUuid.value,
|
|
|
|
+ // modelName: '通义千问-Max',
|
|
|
|
+ // question: buildObjPrompt(xlsxData.value,formInfo.value),
|
|
|
|
+ // id: '699637194561691650',
|
|
|
|
+ // // redisKey:msg.redisKey
|
|
|
|
+ // })
|
|
|
|
+ // return console.log(resForm);
|
|
|
|
|
|
- const formResult = resForm.data[0].content
|
|
|
|
- let form = null
|
|
|
|
- if (formResult.includes('json')) form = JSON.parse(formResult.split('json')[1].split('```')[0])
|
|
|
|
- else form = JSON.parse(formResult)
|
|
|
|
- msg.type = 'form'
|
|
|
|
- // 保存原始内容
|
|
|
|
- msg.rawContent = formResult
|
|
|
|
- putChat({
|
|
|
|
- ...msg
|
|
|
|
- })
|
|
|
|
- sendLoading.value = false
|
|
|
|
- handleInput(xlsxData.value, form)
|
|
|
|
- nextTick(() => {
|
|
|
|
- if (scrollbar.value && scrollbar.value.wrapRef) {
|
|
|
|
- scrollbar.value.setScrollTop(scrollbar.value.wrapRef.scrollHeight)
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
|
|
+
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
|
+ console.log(error);
|
|
|
|
|
|
} finally {
|
|
} finally {
|
|
- sendLoading.value = false
|
|
|
|
- type.value = FunctionList.File_Operation
|
|
|
|
|
|
+ // sendLoading.value = false
|
|
|
|
+ // type.value = FunctionList.File_Operation
|
|
}
|
|
}
|
|
}
|
|
}
|
|
async function handelIntelligentFillingClick() {
|
|
async function handelIntelligentFillingClick() {
|
|
- // isShowPage.value = true
|
|
|
|
|
|
+ isShowPage.value = true
|
|
// taklToHtml.value = true
|
|
// taklToHtml.value = true
|
|
// const tempPageInfo = await getPageInfo()
|
|
// const tempPageInfo = await getPageInfo()
|
|
// pageInfo.value = tempPageInfo
|
|
// pageInfo.value = tempPageInfo
|
|
@@ -343,6 +323,7 @@ function handleCurrentChange(e) {
|
|
|
|
|
|
async function handleCurrentData(e) {
|
|
async function handleCurrentData(e) {
|
|
drawerRef.value.drawer = false
|
|
drawerRef.value.drawer = false
|
|
|
|
+ isShowPage.value = false
|
|
if (!e) {
|
|
if (!e) {
|
|
addNewDialogue()
|
|
addNewDialogue()
|
|
return
|
|
return
|
|
@@ -358,7 +339,15 @@ async function handleCurrentData(e) {
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
+let SystemMsg = null
|
|
|
|
|
|
|
|
+watchEffect(() => {
|
|
|
|
+ if (!isShowPage.value) {
|
|
|
|
+ summaryHtml.value = false
|
|
|
|
+ type.value = FunctionList.File_Operation
|
|
|
|
+ SystemMsg = null
|
|
|
|
+ }
|
|
|
|
+})
|
|
async function readClick() {
|
|
async function readClick() {
|
|
if (type.value === FunctionList.Intelligent_Form_filling) {
|
|
if (type.value === FunctionList.Intelligent_Form_filling) {
|
|
pageInfoList.value = []
|
|
pageInfoList.value = []
|
|
@@ -393,6 +382,8 @@ function addNewDialogue() {
|
|
ElMessage.warning('已经是新对话')
|
|
ElMessage.warning('已经是新对话')
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ summaryHtml.value = false
|
|
|
|
+ type.value = FunctionList.File_Operation
|
|
isShowPage.value = false
|
|
isShowPage.value = false
|
|
taklToHtml.value = false
|
|
taklToHtml.value = false
|
|
messages.value = []
|
|
messages.value = []
|
|
@@ -403,18 +394,26 @@ function addNewDialogue() {
|
|
chrome.storage.local.set({ msgUuid: msgUuid.value })
|
|
chrome.storage.local.set({ msgUuid: msgUuid.value })
|
|
}
|
|
}
|
|
const disabledBtn = computed(() => {
|
|
const disabledBtn = computed(() => {
|
|
- console.log(pageInfoList.value);
|
|
|
|
-
|
|
|
|
return !!(pageInfoList.value.find(_ => _.loading ))
|
|
return !!(pageInfoList.value.find(_ => _.loading ))
|
|
})
|
|
})
|
|
|
|
+function closePageInfo() {
|
|
|
|
+ pageInfoList.value = []
|
|
|
|
+ type.value = FunctionList.File_Operation
|
|
|
|
+ isShowPage.value = false
|
|
|
|
+ formInfo.value = null
|
|
|
|
+}
|
|
async function handleAsk(value) {
|
|
async function handleAsk(value) {
|
|
const str = value ?? inputMessage.value.trim()
|
|
const str = value ?? inputMessage.value.trim()
|
|
inputMessage.value = ''
|
|
inputMessage.value = ''
|
|
if (type.value === FunctionList.Intelligent_Form_filling) {
|
|
if (type.value === FunctionList.Intelligent_Form_filling) {
|
|
- await addMessage(str)
|
|
|
|
- const res = await fetchRes(str)
|
|
|
|
|
|
+ const msg = await addMessage(str)
|
|
|
|
+ await putChat(msg)
|
|
|
|
+ const [res,obj] = await fetchRes(str)
|
|
if (res.status === 'ok') {
|
|
if (res.status === 'ok') {
|
|
|
|
+ console.log(obj);
|
|
|
|
+
|
|
formInfo.value = res.data
|
|
formInfo.value = res.data
|
|
|
|
+ SystemMsg = obj
|
|
} else {
|
|
} else {
|
|
type.value = FunctionList.File_Operation
|
|
type.value = FunctionList.File_Operation
|
|
}
|
|
}
|
|
@@ -430,9 +429,17 @@ async function handleAsk(value) {
|
|
pageInfoList.value = []
|
|
pageInfoList.value = []
|
|
isShowPage.value = false
|
|
isShowPage.value = false
|
|
await putChat(msg)
|
|
await putChat(msg)
|
|
- sendLoading.value = true
|
|
|
|
|
|
+ createWS(msg)
|
|
|
|
+}
|
|
|
|
+/**
|
|
|
|
+ *
|
|
|
|
+ * @param msg 用户消息对象,调用askQues时需要
|
|
|
|
+ */
|
|
|
|
+function createWS(msg) {
|
|
|
|
+ try {
|
|
|
|
+ sendLoading.value = true
|
|
const obj = reactive({
|
|
const obj = reactive({
|
|
- type: type || '',
|
|
|
|
|
|
+ type: type.value === FunctionList.Intelligent_Form_filling ? 'form' : '',
|
|
rawContent: '',
|
|
rawContent: '',
|
|
senderId: -1,
|
|
senderId: -1,
|
|
receiverId: userStore.userInfo.id, //大模型
|
|
receiverId: userStore.userInfo.id, //大模型
|
|
@@ -447,172 +454,74 @@ async function handleAsk(value) {
|
|
scrollbar.value.setScrollTop(scrollbar.value.wrapRef.scrollHeight)
|
|
scrollbar.value.setScrollTop(scrollbar.value.wrapRef.scrollHeight)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
- // request.post('/ai/model/question',{
|
|
|
|
- // conversationId: msgUuid.value,
|
|
|
|
- // modelName: '通义千问-Max',
|
|
|
|
- // question: msg.rawContent,
|
|
|
|
- // id: '699637194561691650',
|
|
|
|
- // // redisKey:msg.redisKey
|
|
|
|
- // }, {
|
|
|
|
- // onDownloadProgress: progressEvent => {
|
|
|
|
- // console.log('progressEvent', progressEvent)
|
|
|
|
- // let { responseText } = progressEvent.event.target
|
|
|
|
- // const newData = responseText.slice(buffer.length)
|
|
|
|
- // buffer += newData
|
|
|
|
- // // const events = buffer.split('\n\n')
|
|
|
|
- // const events = buffer.split('\n\n').map(item => {
|
|
|
|
- // const data = item.replace(/^data: /, '').trim()
|
|
|
|
- // // return data
|
|
|
|
- // try {
|
|
|
|
- // return JSON.parse(data)
|
|
|
|
- // } catch (error) {
|
|
|
|
- // return ''
|
|
|
|
- // }
|
|
|
|
- // })
|
|
|
|
- // debugger
|
|
|
|
- // buffer = events.pop() // 剩余部分保留到下一次
|
|
|
|
- // // events.forEach(event => {
|
|
|
|
- // // if (event.trim()) {
|
|
|
|
- // // const data = event.replace(/^data: /, '').trim();
|
|
|
|
- // // const infoData = JSON.parse(data);
|
|
|
|
- // // console.log('Received event:', infoData.message);
|
|
|
|
- // // }
|
|
|
|
- // // });
|
|
|
|
- // console.log('Received data:', events, 'aaa', buffer)
|
|
|
|
- // }
|
|
|
|
- // })
|
|
|
|
- // 使用 WebSocket 替代 EventSource
|
|
|
|
- try {
|
|
|
|
- // 创建 WebSocket 连接
|
|
|
|
-
|
|
|
|
- const res = await askQues({
|
|
|
|
|
|
+ const wsUrl = `${import.meta.env.VITE_API_WS_URL}/webSocket/clue/${msgUuid.value}`;
|
|
|
|
+ const socket = new WebSocket(wsUrl);
|
|
|
|
+ askQues({
|
|
conversationId: msgUuid.value,
|
|
conversationId: msgUuid.value,
|
|
modelName: '通义千问-Max',
|
|
modelName: '通义千问-Max',
|
|
- question: msg.rawContent,
|
|
|
|
|
|
+ question: type.value === FunctionList.File_Operation ? msg.rawContent : buildObjPrompt(xlsxData.value,formInfo.value),
|
|
id: '699637194561691650',
|
|
id: '699637194561691650',
|
|
redisKey:msg.redisKey
|
|
redisKey:msg.redisKey
|
|
})
|
|
})
|
|
- const eventSource = new EventSource(`${import.meta.env.VITE_APP_BASE_API}/ai/model/createSse?uid=${msgUuid.value}`);
|
|
|
|
- eventSource.onopen = function (event) {
|
|
|
|
- console.log('SSE链接成功');
|
|
|
|
- }
|
|
|
|
- eventSource.onmessage = function (event) {
|
|
|
|
- console.log(event);
|
|
|
|
|
|
+ socket.onmessage = (event) => {
|
|
|
|
+ try {
|
|
|
|
+ if (event.data === '') {
|
|
|
|
+ socket.close()
|
|
|
|
+ if (type.value === FunctionList.Intelligent_Form_filling) {
|
|
|
|
+ const formResult = obj.rawContent
|
|
|
|
+ let form = null
|
|
|
|
+ if (formResult.includes('json')) form = JSON.parse(formResult.split('json')[1].split('```')[0])
|
|
|
|
+ else form = JSON.parse(formResult)
|
|
|
|
+ sendLoading.value = false
|
|
|
|
+ console.log(xlsxData.value, form);
|
|
|
|
+
|
|
|
|
+ handleInput(xlsxData.value, form)
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ obj.rawContent += event.data;
|
|
|
|
+ console.log( obj.rawContent );
|
|
|
|
|
|
- if(event.data){
|
|
|
|
- chat.innerHTML += event.data + '<br/>';
|
|
|
|
- //console.log('后端返回的数据:', data.value);
|
|
|
|
|
|
+ obj.content = obj.type === 'form' ? obj.rawContent : formatMessage(obj.rawContent);
|
|
|
|
+ // 滚动到底部
|
|
|
|
+ nextTick(() => {
|
|
|
|
+ if (scrollbar.value && scrollbar.value.wrapRef) {
|
|
|
|
+ scrollbar.value.setScrollTop(scrollbar.value.wrapRef.scrollHeight);
|
|
}
|
|
}
|
|
|
|
+ });
|
|
}
|
|
}
|
|
- eventSource.onerror = (error) => {
|
|
|
|
- console.log('SSE链接失败',error);
|
|
|
|
- };
|
|
|
|
- // obj.content = formatMessage(res.data[res.data.length - 1].content)
|
|
|
|
- // obj.rawContent = res.data[res.data.length - 1].content;
|
|
|
|
- // const wsUrl = `${import.meta.env.VITE_API_WS_URL}/webSocket/${msgUuid.value}`;
|
|
|
|
- // console.log(wsUrl,12312);
|
|
|
|
-
|
|
|
|
- // const socket = new WebSocket(wsUrl);
|
|
|
|
- // // 连接建立时发送消息
|
|
|
|
- // socket.onopen = () => {
|
|
|
|
- // console.log('WebSocket 连接已建立');
|
|
|
|
- // // 发送请求数据
|
|
|
|
- // socket.send(JSON.stringify({
|
|
|
|
- // session:msgUuid.value
|
|
|
|
- // }));
|
|
|
|
- // };
|
|
|
|
-
|
|
|
|
- // 接收消息
|
|
|
|
- // socket.onmessage = (event) => {
|
|
|
|
- // try {
|
|
|
|
- // console.log('收到数据:', event);
|
|
|
|
-
|
|
|
|
- // // const data = JSON.parse(event.data);
|
|
|
|
- // // console.log('收到数据:', data);
|
|
|
|
- // return
|
|
|
|
- // // 追加内容
|
|
|
|
- // if (data.content) {
|
|
|
|
- // obj.content += data.content;
|
|
|
|
- // obj.rawContent += data.content;
|
|
|
|
-
|
|
|
|
- // // 滚动到底部
|
|
|
|
- // nextTick(() => {
|
|
|
|
- // if (scrollbar.value && scrollbar.value.wrapRef) {
|
|
|
|
- // scrollbar.value.setScrollTop(scrollbar.value.wrapRef.scrollHeight);
|
|
|
|
- // }
|
|
|
|
- // });
|
|
|
|
- // }
|
|
|
|
-
|
|
|
|
- // // 如果是最后一条消息,关闭连接
|
|
|
|
- // if (data.done) {
|
|
|
|
- // socket.close();
|
|
|
|
- // sendLoading.value = false;
|
|
|
|
-
|
|
|
|
- // // 保存到数据库
|
|
|
|
- // putChat({
|
|
|
|
- // ...obj,
|
|
|
|
- // content: obj.content
|
|
|
|
- // });
|
|
|
|
-
|
|
|
|
- // isShowPage.value = false;
|
|
|
|
- // pageInfoList.value = [];
|
|
|
|
- // }
|
|
|
|
- // } catch (error) {
|
|
|
|
- // console.error('解析消息出错:', error);
|
|
|
|
- // }
|
|
|
|
- // };
|
|
|
|
-
|
|
|
|
- // 处理错误
|
|
|
|
- // socket.onerror = (error) => {
|
|
|
|
- // console.error('WebSocket 错误:', error);
|
|
|
|
- // socket.close();
|
|
|
|
- // sendLoading.value = false;
|
|
|
|
-
|
|
|
|
- // // 如果没有收到任何内容,显示错误消息
|
|
|
|
- // if (!obj.content) {
|
|
|
|
- // obj.content = '连接出错,请重试';
|
|
|
|
- // // 保存到数据库
|
|
|
|
- // putChat({
|
|
|
|
- // ...obj,
|
|
|
|
- // content: obj.content
|
|
|
|
- // });
|
|
|
|
- // }
|
|
|
|
- // };
|
|
|
|
-
|
|
|
|
- // // 连接关闭
|
|
|
|
- // socket.onclose = () => {
|
|
|
|
- // console.log('WebSocket 连接已关闭');
|
|
|
|
- // sendLoading.value = false;
|
|
|
|
- // };
|
|
|
|
-
|
|
|
|
- // // 添加到控制器列表,以便可以在需要时中断连接
|
|
|
|
- // controllerList.value.push({
|
|
|
|
- // abort: () => {
|
|
|
|
- // socket.close();
|
|
|
|
- // }
|
|
|
|
- // });
|
|
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error('解析消息出错:', error);
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ socket.onerror = (error) => {
|
|
|
|
+ console.error('WebSocket 错误:', error);
|
|
|
|
+ socket.close();
|
|
|
|
+ };
|
|
|
|
+ socket.onclose = () => {
|
|
|
|
+ console.log('WebSocket 连接已关闭');
|
|
|
|
+ sendLoading.value = false;
|
|
|
|
+ putChat({
|
|
|
|
+ ...obj,
|
|
|
|
+ content:''
|
|
|
|
+ });
|
|
|
|
+ sendLoading.value = false
|
|
|
|
+ controllerList.value = []
|
|
|
|
+ type.value = FunctionList.File_Operation
|
|
|
|
+ };
|
|
|
|
+ // 添加到控制器列表,以便可以在需要时中断连接
|
|
|
|
+ controllerList.value.push({
|
|
|
|
+ abort: () => {
|
|
|
|
+ socket.close();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- // console.error('创建 WebSocket 失败:', error);
|
|
|
|
|
|
+ console.error( error);
|
|
sendLoading.value = false;
|
|
sendLoading.value = false;
|
|
- console.log(error);
|
|
|
|
-
|
|
|
|
// 显示错误消息
|
|
// 显示错误消息
|
|
obj.content = '连接失败,请重试';
|
|
obj.content = '连接失败,请重试';
|
|
-
|
|
|
|
- // 保存到数据库
|
|
|
|
-
|
|
|
|
} finally {
|
|
} finally {
|
|
- putChat({
|
|
|
|
- ...obj,
|
|
|
|
- content:''
|
|
|
|
- });
|
|
|
|
- sendLoading.value = false
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
- // 移除原有的 EventSource 代码
|
|
|
|
- // const params = new URLSearchParams({...});
|
|
|
|
- // const eventSource = new EventSource(...);
|
|
|
|
- // ...
|
|
|
|
}
|
|
}
|
|
function handleCapture() {
|
|
function handleCapture() {
|
|
ElMessage({
|
|
ElMessage({
|
|
@@ -654,20 +563,25 @@ const handleUpload = async (file) => {
|
|
obj.redisKey = res.data.redisKey
|
|
obj.redisKey = res.data.redisKey
|
|
obj.id = res.data.file.id
|
|
obj.id = res.data.file.id
|
|
obj.url = res.data.file.url
|
|
obj.url = res.data.file.url
|
|
- const fileExtension = file.name.split('.').pop().toLowerCase()
|
|
|
|
- if (fileExtension === 'xlsx') {
|
|
|
|
- const readData = await getXlsxValue(file)
|
|
|
|
- readData[0].forEach((header, i) => {
|
|
|
|
- // if (!xlsxData.value[header]) xlsxData.value[header] = []
|
|
|
|
- xlsxData.value[header] = readData[1][i]
|
|
|
|
- })
|
|
|
|
- } else {
|
|
|
|
- const result = await getFormKey({
|
|
|
|
|
|
+ // const fileExtension = file.name.split('.').pop().toLowerCase()
|
|
|
|
+ const result = await getFormKey({
|
|
body: formInfo.value,
|
|
body: formInfo.value,
|
|
input_data:res.data.data
|
|
input_data:res.data.data
|
|
})
|
|
})
|
|
xlsxData.value = JSON.parse(result.data)
|
|
xlsxData.value = JSON.parse(result.data)
|
|
- }
|
|
|
|
|
|
+ // if (fileExtension === 'xlsx') {
|
|
|
|
+ // const readData = await getXlsxValue(file)
|
|
|
|
+ // readData[0].forEach((header, i) => {
|
|
|
|
+ // // if (!xlsxData.value[header]) xlsxData.value[header] = []
|
|
|
|
+ // xlsxData.value[header] = readData[1][i]
|
|
|
|
+ // })
|
|
|
|
+ // } else {
|
|
|
|
+ // const result = await getFormKey({
|
|
|
|
+ // body: formInfo.value,
|
|
|
|
+ // input_data:res.data.data
|
|
|
|
+ // })
|
|
|
|
+ // xlsxData.value = JSON.parse(result.data)
|
|
|
|
+ // }
|
|
}
|
|
}
|
|
|
|
|
|
nextTick(() => {
|
|
nextTick(() => {
|
|
@@ -682,13 +596,24 @@ const handleUpload = async (file) => {
|
|
obj.fileId = res.data.file.id
|
|
obj.fileId = res.data.file.id
|
|
obj.url = res.data.file.url
|
|
obj.url = res.data.file.url
|
|
}
|
|
}
|
|
- obj.loading = false
|
|
|
|
|
|
+ obj.loading = false
|
|
|
|
+ console.log(SystemMsg);
|
|
|
|
+
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
|
+ if (SystemMsg) {
|
|
|
|
+ SystemMsg.content = '数据上传出错,请重试'
|
|
|
|
+ SystemMsg.rawContent = '数据上传出错,请重试'
|
|
|
|
+ }
|
|
console.log(error);
|
|
console.log(error);
|
|
-
|
|
|
|
ElMessage.error('上传出错')
|
|
ElMessage.error('上传出错')
|
|
pageInfoList.value = []
|
|
pageInfoList.value = []
|
|
isShowPage.value = false
|
|
isShowPage.value = false
|
|
|
|
+ } finally {
|
|
|
|
+ SystemMsg && putChat({
|
|
|
|
+ ...SystemMsg,
|
|
|
|
+ content: '',
|
|
|
|
+ })
|
|
|
|
+ SystemMsg = null
|
|
}
|
|
}
|
|
}
|
|
}
|
|
async function getFileValue(file) {
|
|
async function getFileValue(file) {
|