feat: 多会话基础逻辑梳理

This commit is contained in:
ChenZhaoYu
2023-02-14 15:07:50 +08:00
parent 33c02cfe10
commit de34af8747
11 changed files with 213 additions and 107 deletions

View File

@@ -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)
}

View File

@@ -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)