38 lines
837 B
TypeScript
38 lines
837 B
TypeScript
import { create } from 'zustand'
|
|||
|
|
import { createJSONStorage, devtools, persist } from 'zustand/middleware'
|
||
|
|
|
||
|
|
type State = {
|
||
|
|
connected: boolean
|
||
|
|
currentKeys: string[]
|
||
|
|
}
|
||
|
|
|
||
|
|
type Action = {
|
||
|
|
setConnected: (ok: boolean) => void
|
||
|
|
setCurrentKeys: (keys: string[]) => void
|
||
|
|
}
|
||
|
|
|
||
|
|
const useGlobalStore = create<State & Action>()(
|
||
|
|
devtools(
|
||
|
|
persist(
|
||
|
|
set => ({
|
||
|
|
connected: false,
|
||
|
|
currentKeys: ['Home'],
|
||
|
|
currentSections: ['首页'],
|
||
|
|
setConnected: (ok: boolean) =>
|
||
|
|
set(() => ({
|
||
|
|
connected: ok
|
||
|
|
})),
|
||
|
|
setCurrentKeys: (currentKeys: string[]) =>
|
||
|
|
set(() => ({
|
||
|
|
currentKeys: currentKeys
|
||
|
|
}))
|
||
|
|
}),
|
||
|
|
{
|
||
|
|
name: 'hdm_storage',
|
||
|
|
storage: createJSONStorage(() => sessionStorage)
|
||
|
|
}
|
||
|
|
)
|
||
|
|
)
|
||
|
|
)
|
||
|
|
export default useGlobalStore
|