|
|
|
@ -12,11 +12,13 @@ import type { SubMenuItem } from '@/components/AppSubMenuList/index.d'
|
|
|
|
|
|
|
|
|
|
import { AppTextarea } from '@/components/AppTextarea' |
|
|
|
|
import { AppMessage } from '@/components/AppMessage' |
|
|
|
|
import { AppModelSelect } from '@/components/AppModelSelect' |
|
|
|
|
import type { ModelSelect } from '@/components/AppModelSelect/index.d' |
|
|
|
|
import type { RoleData, RoleInfoAppModel } from '@/components/AppRoleDefault/index.d' |
|
|
|
|
import type { MessageItem } from '@/components/AppMessage/index.d' |
|
|
|
|
import { useMessageStore } from '@/store/moules/messageStore/index' |
|
|
|
|
import { MenuTypeEnum } from '@/enums/menuEnum' |
|
|
|
|
import { MessageStatusEnum, MessageTypeEnum } from '@/enums/messageEnum' |
|
|
|
|
import { MessageStatusEnum, MessageTypeEnum, ModelTypeEnum } from '@/enums/messageEnum' |
|
|
|
|
import { addMessage, conversationList, conversationToTop, historyMessage, removeMessage, sendTextToText, updateMessage } from '@/api/base/message' |
|
|
|
|
import { getRoleDecs } from '@/api/base/role' |
|
|
|
|
import { useMqtt } from '@/hooks/useMqtt' |
|
|
|
@ -27,11 +29,24 @@ const { createConfirm } = useMessage()
|
|
|
|
|
const messageStore = useMessageStore() |
|
|
|
|
|
|
|
|
|
const sendBtnLoading = ref(false) |
|
|
|
|
const subMenuActiveIndex = ref(0) // 当前会话索引 |
|
|
|
|
const subMenuActiveIndex = ref(-1) // 当前会话索引 |
|
|
|
|
const subMenuActionIndex = ref(-1) // 会话操作索引 |
|
|
|
|
const subMenuList = ref<SubMenuItem[]>([]) |
|
|
|
|
const subMenuInputValue = ref<string>('') |
|
|
|
|
const appMessageRef = ref() |
|
|
|
|
|
|
|
|
|
const modelOptions: ModelSelect[] = [ |
|
|
|
|
{ |
|
|
|
|
label: '同聪3.5', |
|
|
|
|
value: ModelTypeEnum.GPT3, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
label: '同聪4.0', |
|
|
|
|
value: ModelTypeEnum.GPT4, |
|
|
|
|
}, |
|
|
|
|
] |
|
|
|
|
const modelIndex = ref(0) |
|
|
|
|
|
|
|
|
|
const messageList = computed(() => messageStore.getMessageList) |
|
|
|
|
const messageStatus = computed(() => messageStore.getMessageStatus) |
|
|
|
|
const conversationData = computed(() => messageStore.getConversationData) |
|
|
|
@ -105,11 +120,20 @@ async function handleSubMenuChange(index: number, item?: SubMenuItem) {
|
|
|
|
|
message.warn('请先结束对话') |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if (!subMenuList.value.length) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
subMenuActiveIndex.value = index |
|
|
|
|
historyMessageParams.value.current = 1 |
|
|
|
|
historyMessageParams.value.total = 0 |
|
|
|
|
messageStore.setConversationData(subMenuList.value[subMenuActiveIndex.value]) |
|
|
|
|
messageStore.setMessageClear() |
|
|
|
|
const modelIdx = modelOptions.findIndex(v => v.value === Number(subMenuList.value[subMenuActiveIndex.value].modelType)) |
|
|
|
|
if (modelIdx === -1) { |
|
|
|
|
message.warn('未找到该对话下的模型信息') |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
modelIndex.value = modelIdx |
|
|
|
|
useMqtt().end() |
|
|
|
|
useMqtt().connect() |
|
|
|
|
|
|
|
|
@ -125,26 +149,11 @@ async function handleSubMenuChange(index: number, item?: SubMenuItem) {
|
|
|
|
|
async function handleSend(value: string) { |
|
|
|
|
sendBtnLoading.value = true |
|
|
|
|
conversationDefaultShow.value = false |
|
|
|
|
|
|
|
|
|
if (!conversationData.value) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (subMenuActiveIndex.value === -1) { |
|
|
|
|
try { |
|
|
|
|
spinning.value = true |
|
|
|
|
await addMessage({ type: MenuTypeEnum.ROLE, title: '新的对话', roleId: String(conversationData.value.roleId), sort: subMenuList.value.length + 1 }) |
|
|
|
|
await getConversationList() |
|
|
|
|
await nextTick() |
|
|
|
|
sendMessage(conversationData.value.id, value) |
|
|
|
|
spinning.value = false |
|
|
|
|
} |
|
|
|
|
catch (error) { |
|
|
|
|
message.error('新建对话失败,请稍后重试!') |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
sendMessage(conversationData.value.id, value) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -164,6 +173,8 @@ async function getConversationList() {
|
|
|
|
|
*/ |
|
|
|
|
async function getHistoryMessage() { |
|
|
|
|
if (!conversationData.value) { |
|
|
|
|
spinning.value = false |
|
|
|
|
conversationDefaultShow.value = true |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
spinning.value = true |
|
|
|
@ -252,6 +263,7 @@ async function sendMessage(conversationId: string, question: string): Promise<vo
|
|
|
|
|
sendTextToText({ |
|
|
|
|
conversationId, |
|
|
|
|
question, |
|
|
|
|
modelType: modelOptions[modelIndex.value].value, |
|
|
|
|
}).catch(() => { |
|
|
|
|
messageStore.getMessageList.splice(-2) |
|
|
|
|
messageStore.setMessageStatus(MessageStatusEnum.END) |
|
|
|
@ -293,7 +305,7 @@ async function handleRole(item: RoleData) {
|
|
|
|
|
getHistoryMessage() |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
await addMessage({ type: MenuTypeEnum.ROLE, title: item.roleName, roleId: item.id, sort: subMenuList.value.length + 1 }) |
|
|
|
|
await addMessage({ type: MenuTypeEnum.ROLE, title: item.roleName, roleId: item.id, sort: subMenuList.value.length + 1, modelType: modelOptions[modelIndex.value].value }) |
|
|
|
|
await getConversationList() |
|
|
|
|
await nextTick() |
|
|
|
|
const index = subMenuList.value.findIndex(v => String(v.roleId) === item.id) |
|
|
|
@ -314,7 +326,7 @@ async function handleApply(item: RoleInfoAppModel) {
|
|
|
|
|
getHistoryMessage() |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
await addMessage({ type: MenuTypeEnum.ROLE, title: item.roleName, roleId: String(item.id), sort: subMenuList.value.length + 1 }) |
|
|
|
|
await addMessage({ type: MenuTypeEnum.ROLE, title: item.roleName, roleId: String(item.id), sort: subMenuList.value.length + 1, modelType: modelOptions[modelIndex.value].value }) |
|
|
|
|
await getConversationList() |
|
|
|
|
await nextTick() |
|
|
|
|
const index = subMenuList.value.findIndex(v => v.roleId === item.id) |
|
|
|
@ -324,6 +336,13 @@ async function handleApply(item: RoleInfoAppModel) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @description: gpt模型切换 |
|
|
|
|
*/ |
|
|
|
|
function handleModel(index: number) { |
|
|
|
|
modelIndex.value = index |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 下面是子菜单操作项 |
|
|
|
|
function handleSubMenuInputAffirm(index: number, item: SubMenuItem, inputValue: string) { |
|
|
|
|
updateMessage({ ...item, title: inputValue }).then(() => { |
|
|
|
@ -342,6 +361,9 @@ function handleSubMenuInputBlur(index: number, item: SubMenuItem, inputValue: st
|
|
|
|
|
|
|
|
|
|
onMounted(async () => { |
|
|
|
|
await getConversationList() |
|
|
|
|
if (subMenuList.value.length) { |
|
|
|
|
subMenuActiveIndex.value = 0 |
|
|
|
|
} |
|
|
|
|
await handleSubMenuChange(subMenuActiveIndex.value) |
|
|
|
|
getHistoryMessage() |
|
|
|
|
}) |
|
|
|
@ -390,6 +412,13 @@ onBeforeRouteLeave(() => {
|
|
|
|
|
</template> |
|
|
|
|
<template #content> |
|
|
|
|
<Spin :spinning="spinning" wrapper-class-name="app-content-spin"> |
|
|
|
|
<AppModelSelect |
|
|
|
|
v-if="conversationDefaultShow" |
|
|
|
|
:active-index="modelIndex" |
|
|
|
|
:options="modelOptions" |
|
|
|
|
@change="handleModel" |
|
|
|
|
> |
|
|
|
|
</AppModelSelect> |
|
|
|
|
<!-- 默认导语 --> |
|
|
|
|
<AppRoleDefault |
|
|
|
|
v-if="conversationDefaultShow" |
|
|
|
|