feat: 优化侧边会话

This commit is contained in:
ChenZhaoYu
2023-02-14 16:21:41 +08:00
parent cf8e2dd7b6
commit d2ae2c4f54
3 changed files with 11 additions and 7 deletions

View File

@@ -5,14 +5,17 @@ import { getLocalHistory, setLocalHistory } from './helper'
export const useHistoryStore = defineStore('history-store', {
state: (): HistoryState => getLocalHistory(),
getters: {
getCurrentChat(state): Chat.Chat[] {
getCurrentHistory(state): Chat.HistoryChat {
if (state.historyChat.length) {
if (state.active === null || state.active >= state.historyChat.length || state.active < 0)
state.active = 0
return state.historyChat[state.active].data ?? []
return state.historyChat[state.active] ?? { title: '', isEdit: false, data: [] }
}
state.active = null
return []
return { title: '', isEdit: false, data: [] }
},
getCurrentChat(): Chat.Chat[] {
return this.getCurrentHistory.data ?? []
},
},
actions: {
@@ -23,7 +26,7 @@ export const useHistoryStore = defineStore('history-store', {
}
else {
const active = uuid !== null ? uuid : this.active
if (this.historyChat[active].title === '')
if (this.historyChat[active].title === 'New Chat')
this.historyChat[active].title = data.message
this.historyChat[active].data.push(data)
}