mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-08-27 09:34:19 +08:00
refactor: refactored multi-language modules to support lazy loading and remote loading
This commit is contained in:
44
src/store/modules/locale.ts
Normal file
44
src/store/modules/locale.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import store from '/@/store';
|
||||
|
||||
import { VuexModule, getModule, Module, Mutation, Action } from 'vuex-module-decorators';
|
||||
|
||||
import { LOCALE_KEY } from '/@/enums/cacheEnum';
|
||||
|
||||
import { hotModuleUnregisterModule } from '/@/utils/helper/vuexHelper';
|
||||
import { LocaleSetting, LocaleType } from '/#/config';
|
||||
import { createLocalStorage } from '/@/utils/cache';
|
||||
import { localeSetting } from '/@/settings/localeSetting';
|
||||
|
||||
const ls = createLocalStorage();
|
||||
|
||||
const lsSetting = (ls.get(LOCALE_KEY) || localeSetting) as LocaleSetting;
|
||||
|
||||
const NAME = 'locale';
|
||||
hotModuleUnregisterModule(NAME);
|
||||
@Module({ dynamic: true, namespaced: true, store, name: NAME })
|
||||
class Locale extends VuexModule {
|
||||
private info: LocaleSetting = lsSetting;
|
||||
|
||||
get getShowPicker(): boolean {
|
||||
return !!this.info?.showPicker;
|
||||
}
|
||||
|
||||
get getLocale(): LocaleType {
|
||||
return this.info?.locale;
|
||||
}
|
||||
|
||||
@Mutation
|
||||
setLocaleInfo(info: Partial<LocaleSetting>): void {
|
||||
this.info = { ...this.info, ...info };
|
||||
ls.set(LOCALE_KEY, this.info);
|
||||
}
|
||||
|
||||
@Action
|
||||
initLocale(): void {
|
||||
this.setLocaleInfo({
|
||||
...localeSetting,
|
||||
...this.info,
|
||||
});
|
||||
}
|
||||
}
|
||||
export const localeStore = getModule<Locale>(Locale);
|
Reference in New Issue
Block a user