|
|
|
@ -22,7 +22,7 @@ import type { ModelSelect } from '@/components/AppModelSelect/index.d'
|
|
|
|
|
import { useMessageStore } from '@/store/moules/messageStore/index' |
|
|
|
|
import { MenuTypeEnum } from '@/enums/menuEnum' |
|
|
|
|
import { MessageStatusEnum, MessageTypeEnum, ModelTypeEnum } from '@/enums/messageEnum' |
|
|
|
|
import { addMessage, conversationList, conversationToTop, historyMessage, removeMessage, sendVisualAnalysis, stopMessage, updateMessage } from '@/api/base/message' |
|
|
|
|
import { addMessage, conversationList, conversationToTop, historyMessage, removeMessage, sendVisualAnalysis, updateMessage } from '@/api/base/message' |
|
|
|
|
import { uploadApi } from '@/api/base/file' |
|
|
|
|
import { useMqtt } from '@/hooks/useMqtt' |
|
|
|
|
import { useMessage } from '@/hooks/useMessage' |
|
|
|
@ -61,6 +61,7 @@ const historyMessageParams = ref({
|
|
|
|
|
const conversationDefaultShow = ref(false) |
|
|
|
|
const appMessageShow = ref(true) |
|
|
|
|
const spinning = ref(true) |
|
|
|
|
const elIndex = ref(0) // 新分页数据的数量 |
|
|
|
|
|
|
|
|
|
watch( |
|
|
|
|
() => messageStatus.value, |
|
|
|
@ -201,13 +202,13 @@ async function getHistoryMessage() {
|
|
|
|
|
spinning.value = true |
|
|
|
|
historyMessageParams.value.conversationId = conversationData.value.id |
|
|
|
|
const res = await historyMessage(historyMessageParams.value) |
|
|
|
|
messageStore.setMessageClear() |
|
|
|
|
spinning.value = false |
|
|
|
|
if (!res || !res.records || !res.records.length) { |
|
|
|
|
conversationDefaultShow.value = true |
|
|
|
|
if (!res.records.length && historyMessageParams.value.total === 0) { |
|
|
|
|
conversationDefaultShow.value = true |
|
|
|
|
} |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
console.log(res.records) |
|
|
|
|
|
|
|
|
|
res.records.forEach((item: any) => { |
|
|
|
|
const itemData: MessageItem = { |
|
|
|
@ -220,14 +221,9 @@ async function getHistoryMessage() {
|
|
|
|
|
historyMessageParams.value.total = res.total |
|
|
|
|
messageStore.setMessageUnshiftItem(itemData) |
|
|
|
|
}) |
|
|
|
|
elIndex.value = res.records.length |
|
|
|
|
|
|
|
|
|
conversationDefaultShow.value = false |
|
|
|
|
|
|
|
|
|
// 因为会话切换时滚动底部有问题,所以重新加载下 |
|
|
|
|
// appMessageShow.value = false |
|
|
|
|
// setTimeout(() => { |
|
|
|
|
// appMessageShow.value = true |
|
|
|
|
// }, 0) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -238,7 +234,7 @@ async function onScrollTop(scrollTop: number) {
|
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (historyMessageParams.value.current * historyMessageParams.value.size > historyMessageParams.value.total) { |
|
|
|
|
if (historyMessageParams.value.current * historyMessageParams.value.size >= historyMessageParams.value.total) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -247,7 +243,8 @@ async function onScrollTop(scrollTop: number) {
|
|
|
|
|
await getHistoryMessage() |
|
|
|
|
|
|
|
|
|
// 无缝滚动 |
|
|
|
|
appMessageRef.value.seamlessScrollToTop() |
|
|
|
|
await appMessageRef.value.getElementOffsetTop() |
|
|
|
|
await appMessageRef.value.seamlessScrollToTop() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -322,26 +319,25 @@ function handleModel(index: number) {
|
|
|
|
|
modelIndex.value = index |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function handleUploadChange(info: UploadChangeParam) { |
|
|
|
|
const status = info.file.status |
|
|
|
|
if (status !== 'uploading') { |
|
|
|
|
console.log(info.file, info.fileList) |
|
|
|
|
} |
|
|
|
|
if (status === 'done') { |
|
|
|
|
message.success(`${info.file.name} file uploaded successfully.`) |
|
|
|
|
/** |
|
|
|
|
* @description: 图片上传前的处理 |
|
|
|
|
*/ |
|
|
|
|
function handleBeforeUpload(file: File) { |
|
|
|
|
const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png' |
|
|
|
|
if (!isJpgOrPng) { |
|
|
|
|
message.error('只能上传JPG、PNG格式图片!') |
|
|
|
|
} |
|
|
|
|
else if (status === 'error') { |
|
|
|
|
message.error(`${info.file.name} file upload failed.`) |
|
|
|
|
const isLt10M = file.size / 1024 / 1024 < 10 |
|
|
|
|
if (!isLt10M) { |
|
|
|
|
message.error('图片尺寸不能超过10MB!') |
|
|
|
|
} |
|
|
|
|
return isJpgOrPng && isLt10M |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function handleUploadDrop(e: DragEvent) { |
|
|
|
|
console.log('drop', e) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @description: 自定义图片上传服务器 |
|
|
|
|
*/ |
|
|
|
|
async function handleCustomRequest(option: any) { |
|
|
|
|
console.log(option) |
|
|
|
|
|
|
|
|
|
const formData = new FormData() |
|
|
|
|
formData.append('file', option.file) |
|
|
|
|
|
|
|
|
@ -445,6 +441,7 @@ onBeforeRouteLeave(() => {
|
|
|
|
|
ref="appMessageRef" |
|
|
|
|
class="pl-27 pr-5" |
|
|
|
|
height="calc(100% - 160px)" |
|
|
|
|
:el-index="elIndex" |
|
|
|
|
:list="messageList" |
|
|
|
|
@on-scroll-top="onScrollTop" |
|
|
|
|
@reload-message="reloadMessage" |
|
|
|
@ -460,8 +457,7 @@ onBeforeRouteLeave(() => {
|
|
|
|
|
:max-count="1" |
|
|
|
|
:show-upload-list="false" |
|
|
|
|
:custom-request="handleCustomRequest" |
|
|
|
|
@change="handleUploadChange" |
|
|
|
|
@drop="handleUploadDrop" |
|
|
|
|
:before-upload="handleBeforeUpload" |
|
|
|
|
> |
|
|
|
|
<SvgIcon class="upload-icon" name="image"></SvgIcon> |
|
|
|
|
<p class="ant-upload-text"> |
|
|
|
|