|
@@ -107,9 +107,13 @@ const clearMessage = () => {
|
|
|
}
|
|
|
|
|
|
// 发送消息
|
|
|
-const sendMessage = () => {
|
|
|
+const sendMessage = async () => {
|
|
|
if (!inputMessage.value.trim()) return
|
|
|
|
|
|
+ if (activeConversationId.value === undefined) { //未选中任何会话则创建新会话
|
|
|
+ await createConversationAndSetItActive()
|
|
|
+ }
|
|
|
+ await nextTick()
|
|
|
messages.value.push({
|
|
|
id: messages.value.length,
|
|
|
role: 'user',
|
|
@@ -305,7 +309,7 @@ const { loading: loadConversations, doLoading: doLoadConversations } = useLoadin
|
|
|
const data: { list: LmSession[]; total: number } = await assist.session.list({ pageNum: 1, pageSize: 30 }).catch(() => {
|
|
|
return {
|
|
|
list: [],
|
|
|
- total: 0
|
|
|
+ total: 0,
|
|
|
}
|
|
|
})
|
|
|
|
|
@@ -317,18 +321,18 @@ onMounted(doLoadConversations)
|
|
|
// 当前活跃会话
|
|
|
const activeConversationId = ref<number | undefined>(undefined)
|
|
|
|
|
|
-watch(activeConversationId,async (newVal)=> {
|
|
|
- if (newVal === undefined) {
|
|
|
- return
|
|
|
- }
|
|
|
- await doLoadingMessage(newVal)
|
|
|
-})
|
|
|
+// watch(activeConversationId, async (newVal) => {
|
|
|
+// if (newVal === undefined) {
|
|
|
+// return
|
|
|
+// }
|
|
|
+// await doLoadingMessage(newVal)
|
|
|
+// })
|
|
|
|
|
|
-const {loading: loadingMessage, doLoading: doLoadingMessage} = useLoading(async (id: number)=> {
|
|
|
+const { loading: loadingMessage, doLoading: doLoadingMessage } = useLoading(async (id: number) => {
|
|
|
const data: { messages: Message[]; total: number } = await assist.session.message.list({ sessionId: id }).catch(() => {
|
|
|
return {
|
|
|
list: [],
|
|
|
- total: 0
|
|
|
+ total: 0,
|
|
|
}
|
|
|
})
|
|
|
|
|
@@ -336,13 +340,17 @@ const {loading: loadingMessage, doLoading: doLoadingMessage} = useLoading(async
|
|
|
})
|
|
|
|
|
|
// 选择会话
|
|
|
-const selectConversation = (id: number) => {
|
|
|
+const selectConversation = async (id: number) => {
|
|
|
activeConversationId.value = id
|
|
|
+ await doLoadingMessage(id)
|
|
|
}
|
|
|
|
|
|
// 删除会话
|
|
|
const deleteConversation = async (id: number) => {
|
|
|
- const res = assist.session.del([id]).then(()=>{}).catch(()=> undefined)
|
|
|
+ const res = assist.session
|
|
|
+ .del([id])
|
|
|
+ .then(() => {})
|
|
|
+ .catch(() => undefined)
|
|
|
if (res === undefined) {
|
|
|
return
|
|
|
}
|
|
@@ -355,12 +363,15 @@ const deleteConversation = async (id: number) => {
|
|
|
}
|
|
|
|
|
|
// 创建新对话
|
|
|
-const { loading: creatingConversation, doLoading: createConversation } = useLoading(async () => {
|
|
|
+const { loading: creatingConversation, doLoading: createConversationAndSetItActive } = useLoading(async () => {
|
|
|
try {
|
|
|
// 调用API创建新对话,默认标题为"新对话"
|
|
|
- await assist.session.add('新对话')
|
|
|
+ const { id } = await assist.session.add('新对话')
|
|
|
// 刷新对话列表
|
|
|
await doLoadConversations()
|
|
|
+
|
|
|
+ await nextTick()
|
|
|
+ activeConversationId.value = id
|
|
|
} catch (error) {
|
|
|
console.error('创建对话失败:', error)
|
|
|
// 可以在这里添加错误提示
|
|
@@ -373,7 +384,7 @@ const editingConversationId = ref<number | undefined>(undefined)
|
|
|
const editingTitle = ref('')
|
|
|
// 编辑会话摘要
|
|
|
const editSummary = (id: number) => {
|
|
|
- const conversation = conversations.value.find((conv) => conv.id === id)
|
|
|
+ const conversation = conversations.value.find((conv) => conv.session_id === id)
|
|
|
if (conversation) {
|
|
|
// 设置当前编辑的会话ID
|
|
|
editingConversationId.value = id
|
|
@@ -390,7 +401,7 @@ const editSummary = (id: number) => {
|
|
|
}
|
|
|
// 确认编辑
|
|
|
const confirmEdit = (id: number) => {
|
|
|
- const conversation = conversations.value.find((conv) => conv.id === id)
|
|
|
+ const conversation = conversations.value.find((conv) => conv.session_id === id)
|
|
|
if (conversation && editingTitle.value.trim()) {
|
|
|
conversation.title = editingTitle.value.trim()
|
|
|
// 清除编辑状态
|
|
@@ -416,8 +427,8 @@ const getUserInfos = ref<{
|
|
|
userName: string
|
|
|
}>(Local.get('userInfo') || {})
|
|
|
|
|
|
-const canSendMessage = computed(()=> {
|
|
|
- return !inputMessage.value.trim() || loadingModels.value || loadConversations.value || loadingMessage.value || activeConversationId.value === undefined
|
|
|
+const canSendMessage = computed(() => {
|
|
|
+ return !inputMessage.value.trim() || loadingModels.value || loadConversations.value || loadingMessage.value
|
|
|
})
|
|
|
|
|
|
const router = useRouter()
|
|
@@ -435,29 +446,35 @@ const redirectToModelManager = () => router.push('manage/model')
|
|
|
<el-scrollbar class="conversation-list" v-loading="loadConversations">
|
|
|
<div
|
|
|
v-for="conv in conversations"
|
|
|
- :key="conv.id"
|
|
|
- @click="editingConversationId !== conv.id ? selectConversation(conv.id) : () => {}"
|
|
|
- :class="['conversation-item', { active: activeConversationId === conv.id, editing: editingConversationId === conv.id }]"
|
|
|
+ :key="conv.session_id"
|
|
|
+ @click="editingConversationId !== conv.session_id ? selectConversation(conv.session_id) : () => {}"
|
|
|
+ :class="['conversation-item', { active: activeConversationId === conv.session_id, editing: editingConversationId === conv.session_id }]"
|
|
|
>
|
|
|
<!-- 非编辑状态 -->
|
|
|
- <div v-if="editingConversationId !== conv.id" class="conversation-content">
|
|
|
+ <div v-if="editingConversationId !== conv.session_id" class="conversation-content">
|
|
|
<span class="conversation-title">{{ conv.title }}</span>
|
|
|
</div>
|
|
|
|
|
|
<!-- 编辑状态 -->
|
|
|
<div v-else class="conversation-edit-content">
|
|
|
- <el-input v-model="editingTitle" size="small" @keydown.enter="confirmEdit(conv.id)" @keydown.esc="cancelEdit" class="edit-input" />
|
|
|
+ <el-input
|
|
|
+ v-model="editingTitle"
|
|
|
+ size="small"
|
|
|
+ @keydown.enter="confirmEdit(conv.session_id)"
|
|
|
+ @keydown.esc="cancelEdit"
|
|
|
+ class="edit-input"
|
|
|
+ />
|
|
|
</div>
|
|
|
|
|
|
<!-- 操作按钮 -->
|
|
|
<div class="conversation-actions">
|
|
|
<!-- 非编辑状态的按钮 -->
|
|
|
- <template v-if="editingConversationId !== conv.id">
|
|
|
+ <template v-if="editingConversationId !== conv.session_id">
|
|
|
<el-button
|
|
|
type="primary"
|
|
|
size="small"
|
|
|
:icon="Edit"
|
|
|
- @click.stop="editSummary(conv.id)"
|
|
|
+ @click.stop="editSummary(conv.session_id)"
|
|
|
class="action-btn edit-btn"
|
|
|
title="编辑摘要"
|
|
|
plain
|
|
@@ -467,7 +484,7 @@ const redirectToModelManager = () => router.push('manage/model')
|
|
|
type="danger"
|
|
|
size="small"
|
|
|
:icon="Delete"
|
|
|
- @click.stop="deleteConversation(conv.id)"
|
|
|
+ @click.stop="deleteConversation(conv.session_id)"
|
|
|
class="action-btn delete-btn"
|
|
|
title="删除对话"
|
|
|
plain
|
|
@@ -477,12 +494,28 @@ const redirectToModelManager = () => router.push('manage/model')
|
|
|
|
|
|
<!-- 编辑状态的按钮 -->
|
|
|
<template v-else>
|
|
|
- <el-button type="success" size="small" @click.stop="confirmEdit(conv.id)" class="action-btn confirm-btn" title="确认修改" plain circle>
|
|
|
+ <el-button
|
|
|
+ type="success"
|
|
|
+ size="small"
|
|
|
+ @click.stop="confirmEdit(conv.session_id)"
|
|
|
+ class="action-btn confirm-btn"
|
|
|
+ title="确认修改"
|
|
|
+ plain
|
|
|
+ circle
|
|
|
+ >
|
|
|
<el-icon>
|
|
|
<Check />
|
|
|
</el-icon>
|
|
|
</el-button>
|
|
|
- <el-button type="info" size="small" @click.stop="cancelEdit(conv.id)" class="action-btn cancel-btn" title="取消编辑" plain circle>
|
|
|
+ <el-button
|
|
|
+ type="info"
|
|
|
+ size="small"
|
|
|
+ @click.stop="cancelEdit(conv.session_id)"
|
|
|
+ class="action-btn cancel-btn"
|
|
|
+ title="取消编辑"
|
|
|
+ plain
|
|
|
+ circle
|
|
|
+ >
|
|
|
<el-icon>
|
|
|
<Close />
|
|
|
</el-icon>
|
|
@@ -491,7 +524,9 @@ const redirectToModelManager = () => router.push('manage/model')
|
|
|
</div>
|
|
|
</div>
|
|
|
</el-scrollbar>
|
|
|
- <el-button type="primary" size="large" class="create-conversation-btn" @click="createConversation" :loading="creatingConversation">创建对话</el-button>
|
|
|
+ <el-button type="primary" size="large" class="create-conversation-btn" @click="createConversationAndSetItActive" :loading="creatingConversation"
|
|
|
+ >创建对话</el-button
|
|
|
+ >
|
|
|
</el-aside>
|
|
|
|
|
|
<!-- 右侧聊天区域 -->
|
|
@@ -624,7 +659,7 @@ const redirectToModelManager = () => router.push('manage/model')
|
|
|
resize="none"
|
|
|
@keydown.enter.ctrl="sendMessage"
|
|
|
@keydown.enter.meta="sendMessage"
|
|
|
- :disabled="isConversationActive || activeConversationId === undefined"
|
|
|
+ :disabled="isConversationActive"
|
|
|
/>
|
|
|
</div>
|
|
|
|