feat: 侧边栏记录
This commit is contained in:
18
src/store/modules/app/helper.ts
Normal file
18
src/store/modules/app/helper.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { ls } from '@/utils/storage'
|
||||
|
||||
export interface AppState {
|
||||
siderCollapsed: boolean
|
||||
}
|
||||
|
||||
export function defaultSetting() {
|
||||
return { siderCollapsed: false }
|
||||
}
|
||||
|
||||
export function getAppSetting() {
|
||||
const localSetting: AppState = ls.get('appSetting')
|
||||
return localSetting ?? defaultSetting()
|
||||
}
|
||||
|
||||
export function setAppSetting(setting: AppState) {
|
||||
ls.set('appSetting', setting)
|
||||
}
|
||||
@@ -1,19 +1,16 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
interface AppState {
|
||||
siderCollapsed: boolean
|
||||
}
|
||||
import type { AppState } from './helper'
|
||||
import { getAppSetting, setAppSetting } from './helper'
|
||||
|
||||
export const useAppStore = defineStore('app-store', {
|
||||
state: (): AppState => ({
|
||||
siderCollapsed: false,
|
||||
}),
|
||||
state: (): AppState => getAppSetting(),
|
||||
actions: {
|
||||
setSiderCollapsed(collapsed: boolean) {
|
||||
this.siderCollapsed = collapsed
|
||||
setAppSetting(this.$state)
|
||||
},
|
||||
toggleSiderCollapse() {
|
||||
this.siderCollapsed = !this.siderCollapsed
|
||||
this.setSiderCollapsed(!this.siderCollapsed)
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user