|
@@ -9,10 +9,11 @@
|
|
|
<el-scrollbar ref="scrollbar" @scroll="handleScroll">
|
|
<el-scrollbar ref="scrollbar" @scroll="handleScroll">
|
|
|
<div class="messages">
|
|
<div class="messages">
|
|
|
<div v-for="(message, index) in messages" :key="index"
|
|
<div v-for="(message, index) in messages" :key="index"
|
|
|
- :class="['message-item', message.isSelf ? 'self' : 'other']">
|
|
|
|
|
- <el-avatar :size="32" :src="message.avatar" />
|
|
|
|
|
|
|
+ :class="['message-item', message.role === 'user' ? 'self' : 'other']">
|
|
|
|
|
+ <el-avatar :size="32" :src="message.role === 'user' ? userAvatar : avatar" />
|
|
|
<div class="message-content">
|
|
<div class="message-content">
|
|
|
- <div class="content" v-if="!message.isSelf" :class="{ 'loading-content': message.content === '' }">
|
|
|
|
|
|
|
+ <div class="content" v-if="message.role ==='system'"
|
|
|
|
|
+ :class="{ 'loading-content': message.content === '' }">
|
|
|
<formTable v-if="message.type === 'form'" :content="message.rawContent" />
|
|
<formTable v-if="message.type === 'form'" :content="message.rawContent" />
|
|
|
<span v-else v-html="message.content"></span>
|
|
<span v-else v-html="message.content"></span>
|
|
|
<span class="loading-indicator" v-if="sendLoading && index === messages.length - 1">
|
|
<span class="loading-indicator" v-if="sendLoading && index === messages.length - 1">
|
|
@@ -21,7 +22,7 @@
|
|
|
<span class="dot"></span>
|
|
<span class="dot"></span>
|
|
|
</span>
|
|
</span>
|
|
|
</div>
|
|
</div>
|
|
|
- <document v-else-if="message.type === 'document' && message.isSelf" :content="message.content"
|
|
|
|
|
|
|
+ <document v-else-if="message.type === 'document' && message.role === 'user'" :content="message.content"
|
|
|
:rawContent="message.rawContent" />
|
|
:rawContent="message.rawContent" />
|
|
|
<div v-else class="content">
|
|
<div v-else class="content">
|
|
|
<span v-if="message.type === ''">{{ message.content }}</span>
|
|
<span v-if="message.type === ''">{{ message.content }}</span>
|
|
@@ -118,11 +119,13 @@ import document from '@/entrypoints/sidepanel/component/document.vue'
|
|
|
import pageMask from '@/entrypoints/sidepanel/component/pageMask.vue'
|
|
import pageMask from '@/entrypoints/sidepanel/component/pageMask.vue'
|
|
|
import ScrollToBottom from '@/entrypoints/sidepanel/component/ScrollToBottom.vue'
|
|
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 avatar from '@/public/icon/32.png'
|
|
|
import { mockData, startMsg, mockData2, options, FunctionList } from '@/entrypoints/sidepanel/mock'
|
|
import { mockData, startMsg, mockData2, 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'
|
|
|
|
|
+import { getChatDetail } from '@/api/index.js'
|
|
|
|
|
|
|
|
// 滚动条引用
|
|
// 滚动条引用
|
|
|
const scrollbar = ref(null)
|
|
const scrollbar = ref(null)
|
|
@@ -148,8 +151,6 @@ const {
|
|
|
} = useMsg(scrollbar)
|
|
} = useMsg(scrollbar)
|
|
|
const inputMessage = ref('')
|
|
const inputMessage = ref('')
|
|
|
const pageInfo = ref('')
|
|
const pageInfo = ref('')
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
function handleStopAsk() {
|
|
function handleStopAsk() {
|
|
|
if (type.value === FunctionList.Intelligent_Form_filling) {
|
|
if (type.value === FunctionList.Intelligent_Form_filling) {
|
|
|
inputMessage.value = ''
|
|
inputMessage.value = ''
|
|
@@ -187,14 +188,11 @@ async function addMessage(msg, raw, type) {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
const newMessage = reactive({
|
|
const newMessage = reactive({
|
|
|
- id: messages.value.length + 1,
|
|
|
|
|
type: type || '',
|
|
type: type || '',
|
|
|
- username: '我',
|
|
|
|
|
rawContent: raw ?? msg,
|
|
rawContent: raw ?? msg,
|
|
|
content: msg,
|
|
content: msg,
|
|
|
timestamp: moment().format('YYYY-MM-DD HH:mm:ss'),
|
|
timestamp: moment().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
- isSelf: true,
|
|
|
|
|
- avatar: 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png',
|
|
|
|
|
|
|
+ role:'user',
|
|
|
addToHistory: !taklToHtml.value
|
|
addToHistory: !taklToHtml.value
|
|
|
})
|
|
})
|
|
|
if (type === 'document') {
|
|
if (type === 'document') {
|
|
@@ -243,7 +241,11 @@ const handleSummary = async () => {
|
|
|
6. 对这几段内容进行综合分析及联想`
|
|
6. 对这几段内容进行综合分析及联想`
|
|
|
}]
|
|
}]
|
|
|
}
|
|
}
|
|
|
- await addMessage(pageInfoList.value, '总结', 'document')
|
|
|
|
|
|
|
+ const msg = await addMessage(JSON.stringify(pageInfoList.value), JSON.stringify(params.map(_ => _.content)), 'document')
|
|
|
|
|
+ // putChat({
|
|
|
|
|
+ // id: msgUuid.value,
|
|
|
|
|
+ // msg: msg
|
|
|
|
|
+ // })
|
|
|
if (requestFlowFn) {
|
|
if (requestFlowFn) {
|
|
|
isShowPage.value = false
|
|
isShowPage.value = false
|
|
|
taklToHtml.value = false
|
|
taklToHtml.value = false
|
|
@@ -285,6 +287,14 @@ function handleCurrentData(e) {
|
|
|
}
|
|
}
|
|
|
// 添加indexDB Store配置
|
|
// 添加indexDB Store配置
|
|
|
msgUuid.value = e
|
|
msgUuid.value = e
|
|
|
|
|
+ // getChatDetail(e).then(res => {
|
|
|
|
|
+ // messages.value = reds
|
|
|
|
|
+ // nextTick(() => {
|
|
|
|
|
+ // scrollbar.value?.setScrollTop(99999)
|
|
|
|
|
+ // })
|
|
|
|
|
+ // }).finally(res => {
|
|
|
|
|
+
|
|
|
|
|
+ // })
|
|
|
useStore(e).getAll().then((res) => {
|
|
useStore(e).getAll().then((res) => {
|
|
|
messages.value = res
|
|
messages.value = res
|
|
|
nextTick(() => {
|
|
nextTick(() => {
|
|
@@ -304,7 +314,11 @@ async function readClick() {
|
|
|
ElMessage.warning(`最多添加${import.meta.env.VITE_MAX_FILE_NUMBER}个文件`)
|
|
ElMessage.warning(`最多添加${import.meta.env.VITE_MAX_FILE_NUMBER}个文件`)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
+ console.log(45454);
|
|
|
|
|
+
|
|
|
const tempPageInfo = await getPageInfo()
|
|
const tempPageInfo = await getPageInfo()
|
|
|
|
|
+ console.log(tempPageInfo);
|
|
|
|
|
+
|
|
|
if (AIModel.value.file === true) {
|
|
if (AIModel.value.file === true) {
|
|
|
const blob = new Blob([tempPageInfo.content.mainContent], { type: 'text/plain' })
|
|
const blob = new Blob([tempPageInfo.content.mainContent], { type: 'text/plain' })
|
|
|
const file = new File([blob], tempPageInfo.title + '.txt', { type: 'text/plain' })
|
|
const file = new File([blob], tempPageInfo.title + '.txt', { type: 'text/plain' })
|
|
@@ -324,6 +338,10 @@ function deletePageInfo(i) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function addNewDialogue() {
|
|
function addNewDialogue() {
|
|
|
|
|
+ // if (messages.value.length === 0) {
|
|
|
|
|
+ // ElMessage.warning('已经是新对话')
|
|
|
|
|
+ // return
|
|
|
|
|
+ // }
|
|
|
if (msgUuid.value === '') {
|
|
if (msgUuid.value === '') {
|
|
|
ElMessage.warning('已经是新对话')
|
|
ElMessage.warning('已经是新对话')
|
|
|
return
|
|
return
|
|
@@ -339,7 +357,11 @@ async function handleAsk() {
|
|
|
const str = inputMessage.value.trim()
|
|
const str = inputMessage.value.trim()
|
|
|
inputMessage.value = ''
|
|
inputMessage.value = ''
|
|
|
if (sendLoading.value) return
|
|
if (sendLoading.value) return
|
|
|
- await addMessage(str)
|
|
|
|
|
|
|
+ const msg = await addMessage(str)
|
|
|
|
|
+ // putChat({
|
|
|
|
|
+ // id: msgUuid.value,
|
|
|
|
|
+ // msg: msg
|
|
|
|
|
+ // })
|
|
|
if (type.value === FunctionList.Intelligent_Form_filling) {
|
|
if (type.value === FunctionList.Intelligent_Form_filling) {
|
|
|
const res = await fetchRes(str)
|
|
const res = await fetchRes(str)
|
|
|
console.log(res);
|
|
console.log(res);
|
|
@@ -367,7 +389,6 @@ function handleCapture() {
|
|
|
function hisRecords() {
|
|
function hisRecords() {
|
|
|
drawerRef.value.drawer = true
|
|
drawerRef.value.drawer = true
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
const handleUpload = async (file) => {
|
|
const handleUpload = async (file) => {
|
|
|
if (AIModel.value.file === true) {
|
|
if (AIModel.value.file === true) {
|
|
|
const id = await modelFileUpload(file)
|
|
const id = await modelFileUpload(file)
|
|
@@ -389,7 +410,11 @@ const handleUpload = async (file) => {
|
|
|
// if (!xlsxData.value[header]) xlsxData.value[header] = []
|
|
// if (!xlsxData.value[header]) xlsxData.value[header] = []
|
|
|
xlsxData.value[header] = readData[1][i]
|
|
xlsxData.value[header] = readData[1][i]
|
|
|
})
|
|
})
|
|
|
- addMessage(`已上传文件:${file.name}`, buildExcelUnderstandingPrompt(readData[0], file?.name, formInfo.value))
|
|
|
|
|
|
|
+ const msg = addMessage(`已上传文件:${file.name}`, buildExcelUnderstandingPrompt(readData[0], file?.name, formInfo.value))
|
|
|
|
|
+ // putChat({
|
|
|
|
|
+ // id: msgUuid.value,
|
|
|
|
|
+ // msg: msg
|
|
|
|
|
+ // })
|
|
|
const { rawContent, status } = await streamRes()
|
|
const { rawContent, status } = await streamRes()
|
|
|
if (status === 'ok') {
|
|
if (status === 'ok') {
|
|
|
let form = []
|
|
let form = []
|
|
@@ -399,16 +424,15 @@ const handleUpload = async (file) => {
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
try {
|
|
try {
|
|
|
- const { data, msg } = await getFileValue(file)
|
|
|
|
|
|
|
+ sendLoading.value = true
|
|
|
|
|
+ const msg = await addMessage(`文件上传中`)
|
|
|
|
|
+ const data = await getFileValue(file)
|
|
|
|
|
+ msg.content = `已上传文件:${file.name}`
|
|
|
|
|
+ msg.rawContent = data
|
|
|
const res2 = await getFormKeyAndValue(data, formInfo.value)
|
|
const res2 = await getFormKeyAndValue(data, formInfo.value)
|
|
|
xlsxData.value = res2.data
|
|
xlsxData.value = res2.data
|
|
|
msg.rawContent = buildObjPrompt(res2.data, formInfo.value)
|
|
msg.rawContent = buildObjPrompt(res2.data, formInfo.value)
|
|
|
- console.log(msg.rawContent);
|
|
|
|
|
- console.log(messages);
|
|
|
|
|
-
|
|
|
|
|
const { rawContent, status } = await streamRes()
|
|
const { rawContent, status } = await streamRes()
|
|
|
- console.log(22555);
|
|
|
|
|
-
|
|
|
|
|
if (status === 'ok') {
|
|
if (status === 'ok') {
|
|
|
let form = []
|
|
let form = []
|
|
|
if (rawContent.includes('json')) form = JSON.parse(rawContent.split('json')[1].split('```')[0])
|
|
if (rawContent.includes('json')) form = JSON.parse(rawContent.split('json')[1].split('```')[0])
|
|
@@ -419,6 +443,10 @@ const handleUpload = async (file) => {
|
|
|
msg.content = '文件解析出错'
|
|
msg.content = '文件解析出错'
|
|
|
} finally {
|
|
} finally {
|
|
|
sendLoading.value = false
|
|
sendLoading.value = false
|
|
|
|
|
+ // putChat({
|
|
|
|
|
+ // id: msgUuid.value,
|
|
|
|
|
+ // msg: msg
|
|
|
|
|
+ // })
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
type.value = FunctionList.File_Operation
|
|
type.value = FunctionList.File_Operation
|
|
@@ -442,28 +470,12 @@ const handleUpload = async (file) => {
|
|
|
isShowPage.value = true
|
|
isShowPage.value = true
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
async function getFileValue(file) {
|
|
async function getFileValue(file) {
|
|
|
- const msg = await addMessage(`文件上传中`)
|
|
|
|
|
- console.log(msg, messages);
|
|
|
|
|
-
|
|
|
|
|
- sendLoading.value = true
|
|
|
|
|
let formData = new FormData()
|
|
let formData = new FormData()
|
|
|
formData.append('file', file)
|
|
formData.append('file', file)
|
|
|
const res = await getFileContent(formData)
|
|
const res = await getFileContent(formData)
|
|
|
- console.log(res, 5555);
|
|
|
|
|
-
|
|
|
|
|
- sendLoading.value = false
|
|
|
|
|
- msg.content = `已上传文件:${file.name}`
|
|
|
|
|
- console.log(msg.content);
|
|
|
|
|
-
|
|
|
|
|
- msg.rawContent = res.data
|
|
|
|
|
- return {
|
|
|
|
|
- data: res.data,
|
|
|
|
|
- msg
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return res.data
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// 组件挂载时滚动到底部
|
|
// 组件挂载时滚动到底部
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
|
msgStore.updateAIModel(options[0].options[0])
|
|
msgStore.updateAIModel(options[0].options[0])
|
|
@@ -481,7 +493,6 @@ onMounted(() => {
|
|
|
pageInfo.value = message.data
|
|
pageInfo.value = message.data
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
-
|
|
|
|
|
nextTick(() => {
|
|
nextTick(() => {
|
|
|
scrollbar.value?.setScrollTop(99999)
|
|
scrollbar.value?.setScrollTop(99999)
|
|
|
})
|
|
})
|