Skip to content

Commit 4eb5961

Browse files
author
Kerwin
committed
fix: 最后一个对话被删除之后无法聊天
1 parent 3dd55c8 commit 4eb5961

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/store/modules/chat/index.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,21 @@ export const useChatStore = defineStore('chat-store', {
3939
this.chat.unshift({ uuid: r.uuid, data: [] })
4040
}
4141
if (uuid == null) {
42-
uuid = Date.now()
43-
this.addHistory({ title: 'New Chat', uuid: Date.now(), isEdit: false })
42+
await this.addHistory({ title: 'New Chat', uuid: Date.now(), isEdit: false })
43+
}
44+
else {
45+
this.active = uuid
46+
this.reloadRoute(uuid)
4447
}
45-
this.active = uuid
46-
this.reloadRoute(uuid)
4748
callback && callback()
4849
},
4950

5051
async syncChat(h: Chat.History, callback: () => void) {
52+
if (!h.uuid) {
53+
callback && callback()
54+
return
55+
}
56+
5157
const chatIndex = this.chat.findIndex(item => item.uuid === h.uuid)
5258
if (chatIndex <= -1 || this.chat[chatIndex].data.length <= 0) {
5359
const chatData = (await fetchGetChatHistory(h.uuid)).data
@@ -61,8 +67,8 @@ export const useChatStore = defineStore('chat-store', {
6167
this.recordState()
6268
},
6369

64-
addHistory(history: Chat.History, chatData: Chat.Chat[] = []) {
65-
fetchCreateChatRoom(history.title, history.uuid)
70+
async addHistory(history: Chat.History, chatData: Chat.Chat[] = []) {
71+
await fetchCreateChatRoom(history.title, history.uuid)
6672
this.history.unshift(history)
6773
this.chat.unshift({ uuid: history.uuid, data: chatData })
6874
this.active = history.uuid
@@ -80,13 +86,12 @@ export const useChatStore = defineStore('chat-store', {
8086
},
8187

8288
async deleteHistory(index: number) {
83-
fetchDeleteChatRoom(this.history[index].uuid)
89+
await fetchDeleteChatRoom(this.history[index].uuid)
8490
this.history.splice(index, 1)
8591
this.chat.splice(index, 1)
8692

8793
if (this.history.length === 0) {
88-
this.active = null
89-
this.reloadRoute()
94+
await this.addHistory({ title: 'New Chat', uuid: Date.now(), isEdit: false })
9095
return
9196
}
9297

src/views/chat/layout/sider/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const show = ref(false)
1616
1717
const collapsed = computed(() => appStore.siderCollapsed)
1818
19-
function handleAdd() {
20-
chatStore.addHistory({ title: 'New Chat', uuid: Date.now(), isEdit: false })
19+
async function handleAdd() {
20+
await chatStore.addHistory({ title: 'New Chat', uuid: Date.now(), isEdit: false })
2121
if (isMobile.value)
2222
appStore.setSiderCollapsed(true)
2323
}

0 commit comments

Comments
 (0)