mirror of
https://github.com/Chanzhaoyu/chatgpt-web.git
synced 2025-07-22 20:51:39 +00:00
feat: 多会话基础逻辑梳理
This commit is contained in:
@@ -1,12 +1,55 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
interface HistoryState {
|
||||
list: any[]
|
||||
}
|
||||
import type { HistoryState } from './helper'
|
||||
import { getLocalHistory, setLocalHistory } from './helper'
|
||||
|
||||
export const useHistoryStore = defineStore('history-store', {
|
||||
state: (): HistoryState => ({
|
||||
list: [],
|
||||
}),
|
||||
actions: {},
|
||||
state: (): HistoryState => getLocalHistory(),
|
||||
getters: {
|
||||
getCurrentChat(state): Chat.Chat[] {
|
||||
if (state.historyChat.length === 0)
|
||||
return []
|
||||
|
||||
if (state.active === null)
|
||||
state.active = state.historyChat.length - 1
|
||||
|
||||
return state.historyChat[state.active].data
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
addChat(data: Chat.Chat) {
|
||||
if (this.active !== null) {
|
||||
this.historyChat[this.active].data.push(data)
|
||||
this.active = this.historyChat.length - 1
|
||||
setLocalHistory(this.$state)
|
||||
}
|
||||
},
|
||||
|
||||
clearChat() {
|
||||
if (this.active !== null) {
|
||||
this.historyChat[this.active].data = []
|
||||
setLocalHistory(this.$state)
|
||||
}
|
||||
},
|
||||
|
||||
chooseHistory(index: number) {
|
||||
this.active = index
|
||||
setLocalHistory(this.$state)
|
||||
},
|
||||
|
||||
addHistory(data: Chat.HistoryChat) {
|
||||
this.historyChat.push(data)
|
||||
this.active = this.historyChat.length - 1
|
||||
setLocalHistory(this.$state)
|
||||
},
|
||||
|
||||
editHistory(index: number, isEdit: boolean) {
|
||||
this.historyChat[index].isEdit = isEdit
|
||||
setLocalHistory(this.$state)
|
||||
},
|
||||
|
||||
removeHistory(index: number) {
|
||||
this.historyChat.splice(index, 1)
|
||||
setLocalHistory(this.$state)
|
||||
},
|
||||
},
|
||||
})
|
||||
|
Reference in New Issue
Block a user