chore: init bj_power monorepo (dashboard/mes/wms/wms_client/workstation), clear subproject git metadata and align naming to folder names
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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
|
||||
@@ -0,0 +1,66 @@
|
||||
import { create } from 'zustand'
|
||||
import { createJSONStorage, devtools, persist } from 'zustand/middleware'
|
||||
|
||||
type State = {
|
||||
token: string
|
||||
userInfo: UserInfosState
|
||||
isDark: boolean
|
||||
locale: 'zh-CN' | 'en-US'
|
||||
}
|
||||
|
||||
type Action = {
|
||||
setToken: (token: string) => void
|
||||
setUserInfo: (userinfo: UserInfosState) => void
|
||||
setDark: (dark: boolean) => void
|
||||
changeLocale: (val: 'zh-CN' | 'en-US') => void
|
||||
clear: () => void
|
||||
}
|
||||
|
||||
const useLocalStore = create<State & Action>()(
|
||||
devtools(
|
||||
persist(
|
||||
set => ({
|
||||
token: '',
|
||||
userInfo: null as unknown as UserInfosState,
|
||||
isDark: false,
|
||||
locale: 'zh-CN',
|
||||
setToken: (token: string) =>
|
||||
set(() => ({
|
||||
token: token
|
||||
})),
|
||||
setUserInfo: (userInfo: UserInfosState) =>
|
||||
set(() => ({
|
||||
userInfo: userInfo
|
||||
})),
|
||||
setDark: (dark: boolean) => {
|
||||
if (dark) {
|
||||
document.body.setAttribute('theme-mode', 'dark')
|
||||
} else {
|
||||
document.body.removeAttribute('theme-mode')
|
||||
}
|
||||
set(() => ({
|
||||
isDark: dark
|
||||
}))
|
||||
},
|
||||
changeLocale: (val: 'zh-CN' | 'en-US') => {
|
||||
if (val === 'zh-CN') {
|
||||
set({ locale: 'zh-CN' })
|
||||
} else {
|
||||
set({ locale: 'en-US' })
|
||||
}
|
||||
},
|
||||
clear: () => {
|
||||
set(() => ({
|
||||
token: '',
|
||||
userInfo: null as unknown as UserInfosState
|
||||
}))
|
||||
}
|
||||
}),
|
||||
{
|
||||
name: 'hdm_storage',
|
||||
storage: createJSONStorage(() => localStorage)
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
export default useLocalStore
|
||||
Reference in New Issue
Block a user