2022-01-03 09:41:34 +08:00
|
|
|
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-03 09:41:34 +08:00
|
|
|
|
2022-01-05 17:02:25 +08:00
|
|
|
const { wsCache } = useCache()
|
2022-01-03 09:41:34 +08:00
|
|
|
|
|
|
|
export const useLocaleStore = defineStore({
|
|
|
|
id: 'locales',
|
2022-01-05 17:02:25 +08:00
|
|
|
state: (): LocaleState => localeModules,
|
2022-01-03 09:41:34 +08:00
|
|
|
getters: {
|
2022-01-18 16:22:47 +08:00
|
|
|
getCurrentLocale(): LocaleDropdownType {
|
|
|
|
return this.currentLocale
|
2022-01-03 09:41:34 +08:00
|
|
|
},
|
|
|
|
getLocaleMap(): LocaleDropdownType[] {
|
|
|
|
return this.localeMap
|
|
|
|
}
|
|
|
|
},
|
|
|
|
actions: {
|
2022-01-18 16:22:47 +08:00
|
|
|
setCurrentLocale(localeMap: LocaleDropdownType) {
|
2022-01-03 09:41:34 +08:00
|
|
|
// 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)
|
2022-01-03 09:41:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-01-15 14:24:50 +08:00
|
|
|
export const useLocaleStoreWithOut = () => {
|
2022-01-03 09:41:34 +08:00
|
|
|
return useLocaleStore(store)
|
|
|
|
}
|