feat: 多会话基础逻辑梳理
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { ls } from '@/utils/storage'
|
||||
import { ss } from '@/utils/storage'
|
||||
|
||||
const LOCAL_NAME = 'appSetting'
|
||||
|
||||
export interface AppState {
|
||||
siderCollapsed: boolean
|
||||
@@ -8,11 +10,11 @@ export function defaultSetting() {
|
||||
return { siderCollapsed: false }
|
||||
}
|
||||
|
||||
export function getAppSetting() {
|
||||
const localSetting: AppState = ls.get('appSetting')
|
||||
export function getLocalSetting() {
|
||||
const localSetting: AppState | undefined = ss.get(LOCAL_NAME)
|
||||
return localSetting ?? defaultSetting()
|
||||
}
|
||||
|
||||
export function setAppSetting(setting: AppState) {
|
||||
ls.set('appSetting', setting)
|
||||
export function setLocalSetting(setting: AppState) {
|
||||
ss.set(LOCAL_NAME, setting)
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import type { AppState } from './helper'
|
||||
import { getAppSetting, setAppSetting } from './helper'
|
||||
import { getLocalSetting, setLocalSetting } from './helper'
|
||||
|
||||
export const useAppStore = defineStore('app-store', {
|
||||
state: (): AppState => getAppSetting(),
|
||||
state: (): AppState => getLocalSetting(),
|
||||
actions: {
|
||||
setSiderCollapsed(collapsed: boolean) {
|
||||
this.siderCollapsed = collapsed
|
||||
setAppSetting(this.$state)
|
||||
setLocalSetting(this.$state)
|
||||
},
|
||||
toggleSiderCollapse() {
|
||||
this.setSiderCollapsed(!this.siderCollapsed)
|
||||
|
||||
21
src/store/modules/history/helper.ts
Normal file
21
src/store/modules/history/helper.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { ss } from '@/utils/storage'
|
||||
|
||||
const LOCAL_NAME = 'historyChat'
|
||||
|
||||
export interface HistoryState {
|
||||
historyChat: Chat.HistoryChat[]
|
||||
active: number | null
|
||||
}
|
||||
|
||||
export function defaultSetting() {
|
||||
return { historyChat: [], active: null }
|
||||
}
|
||||
|
||||
export function getLocalHistory() {
|
||||
const localSetting: HistoryState | undefined = ss.get(LOCAL_NAME)
|
||||
return localSetting ?? defaultSetting()
|
||||
}
|
||||
|
||||
export function setLocalHistory(data: HistoryState) {
|
||||
ss.set(LOCAL_NAME, data)
|
||||
}
|
||||
@@ -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