|
|
@ -6,22 +6,27 @@ export const useHistoryStore = defineStore('history-store', {
|
|
|
|
state: (): HistoryState => getLocalHistory(),
|
|
|
|
state: (): HistoryState => getLocalHistory(),
|
|
|
|
getters: {
|
|
|
|
getters: {
|
|
|
|
getCurrentChat(state): Chat.Chat[] {
|
|
|
|
getCurrentChat(state): Chat.Chat[] {
|
|
|
|
if (state.historyChat.length === 0)
|
|
|
|
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 ?? []
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
state.active = null
|
|
|
|
return []
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
|
|
if (state.active === null)
|
|
|
|
|
|
|
|
state.active = state.historyChat.length - 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return state.historyChat[state.active].data
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
actions: {
|
|
|
|
addChat(data: Chat.Chat) {
|
|
|
|
addChat(data: Chat.Chat) {
|
|
|
|
if (this.active !== null) {
|
|
|
|
if (this.active === null) {
|
|
|
|
this.historyChat[this.active].data.push(data)
|
|
|
|
this.historyChat.push({ title: data.message, isEdit: false, data: [data] })
|
|
|
|
this.active = this.historyChat.length - 1
|
|
|
|
this.active = this.historyChat.length - 1
|
|
|
|
setLocalHistory(this.$state)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
if (this.historyChat[this.active].title === '')
|
|
|
|
|
|
|
|
this.historyChat[this.active].title = data.message
|
|
|
|
|
|
|
|
this.historyChat[this.active].data.push(data)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
setLocalHistory(this.$state)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
clearChat() {
|
|
|
|
clearChat() {
|
|
|
@ -31,11 +36,6 @@ export const useHistoryStore = defineStore('history-store', {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
chooseHistory(index: number) {
|
|
|
|
|
|
|
|
this.active = index
|
|
|
|
|
|
|
|
setLocalHistory(this.$state)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addHistory(data: Chat.HistoryChat) {
|
|
|
|
addHistory(data: Chat.HistoryChat) {
|
|
|
|
this.historyChat.push(data)
|
|
|
|
this.historyChat.push(data)
|
|
|
|
this.active = this.historyChat.length - 1
|
|
|
|
this.active = this.historyChat.length - 1
|
|
|
@ -49,6 +49,19 @@ export const useHistoryStore = defineStore('history-store', {
|
|
|
|
|
|
|
|
|
|
|
|
removeHistory(index: number) {
|
|
|
|
removeHistory(index: number) {
|
|
|
|
this.historyChat.splice(index, 1)
|
|
|
|
this.historyChat.splice(index, 1)
|
|
|
|
|
|
|
|
if (this.active === index) {
|
|
|
|
|
|
|
|
if (this.historyChat.length === 0)
|
|
|
|
|
|
|
|
this.active = null
|
|
|
|
|
|
|
|
else if (this.active === this.historyChat.length)
|
|
|
|
|
|
|
|
this.active--
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
this.active = 0
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
setLocalHistory(this.$state)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chooseHistory(index: number) {
|
|
|
|
|
|
|
|
this.active = index
|
|
|
|
setLocalHistory(this.$state)
|
|
|
|
setLocalHistory(this.$state)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|