gohttpdUi/src/store/modules/locale.ts

33 lines
921 B
TypeScript
Raw Normal View History

import { defineStore } from 'pinia'
import { store } from '../index'
2022-01-05 17:02:25 +08:00
import { useCache } from '@/hooks/web/useCache'
import { localeModules, elLocaleMap } from '@/config/locale'
import type { LocaleState } from '@/config/locale'
2022-01-05 17:02:25 +08:00
const { wsCache } = useCache()
export const useLocaleStore = defineStore({
id: 'locales',
2022-01-05 17:02:25 +08:00
state: (): LocaleState => localeModules,
getters: {
2022-01-18 16:22:47 +08:00
getCurrentLocale(): LocaleDropdownType {
return this.currentLocale
},
getLocaleMap(): LocaleDropdownType[] {
return this.localeMap
}
},
actions: {
2022-01-18 16:22:47 +08:00
setCurrentLocale(localeMap: LocaleDropdownType) {
// this.locale = Object.assign(this.locale, localeMap)
2022-01-18 16:22:47 +08:00
this.currentLocale.lang = localeMap?.lang
this.currentLocale.elLocale = elLocaleMap[localeMap?.lang]
2022-01-05 17:02:25 +08:00
wsCache.set('lang', localeMap?.lang)
}
}
})
export const useLocaleStoreWithOut = () => {
return useLocaleStore(store)
}