Vben
2021-04-10 215d8bab380728164d7fe2958c2d2d1151fce892
src/locales/useLocale.ts
@@ -6,7 +6,7 @@
import moment from 'moment';
import { i18n } from './setupI18n';
import { localeStore } from '/@/store/modules/locale';
import { useLocaleStoreWithOut } from '/@/store/modules/locale';
import { unref, computed } from 'vue';
interface LangModule {
@@ -18,6 +18,8 @@
const loadLocalePool: LocaleType[] = [];
function setI18nLanguage(locale: LocaleType) {
  const localeStore = useLocaleStoreWithOut();
  if (i18n.mode === 'legacy') {
    i18n.global.locale = locale;
  } else {
@@ -28,6 +30,7 @@
}
export function useLocale() {
  const localeStore = useLocaleStoreWithOut();
  const getLocale = computed(() => localeStore.getLocale);
  const getShowLocalePicker = computed(() => localeStore.getShowPicker);
@@ -40,7 +43,9 @@
  async function changeLocale(locale: LocaleType) {
    const globalI18n = i18n.global;
    const currentLocale = unref(globalI18n.locale);
    if (currentLocale === locale) return locale;
    if (currentLocale === locale) {
      return locale;
    }
    if (loadLocalePool.includes(locale)) {
      setI18nLanguage(locale);