2024-09-26 09:38:02 +08:00
|
|
|
<template>
|
2024-10-03 15:52:18 +08:00
|
|
|
<el-config-provider :locale="currentLocale">
|
|
|
|
<router-view />
|
|
|
|
<ReDialog />
|
|
|
|
</el-config-provider>
|
2024-09-26 09:38:02 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2024-10-03 15:52:18 +08:00
|
|
|
import { ElConfigProvider } from 'element-plus';
|
|
|
|
import { computed, onMounted } from 'vue';
|
|
|
|
import { ReDialog } from '@/components/BaseDialog';
|
|
|
|
import en from 'element-plus/es/locale/lang/en';
|
|
|
|
import zhCn from 'element-plus/es/locale/lang/zh-cn';
|
|
|
|
import plusEn from 'plus-pro-components/es/locale/lang/en';
|
|
|
|
import plusZhCn from 'plus-pro-components/es/locale/lang/zh-cn';
|
|
|
|
import { useNav } from '@/layout/hooks/useNav';
|
|
|
|
import { useI18n } from 'vue-i18n';
|
|
|
|
import { userI18nStore } from '@/store/i18n/i18n';
|
2024-09-26 09:38:02 +08:00
|
|
|
|
|
|
|
const i18nStore = userI18nStore();
|
|
|
|
const i18n = useI18n();
|
|
|
|
const { $storage } = useNav();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* * 设置多语言内容
|
|
|
|
*/
|
|
|
|
const setI18n = async () => {
|
2024-10-03 15:52:18 +08:00
|
|
|
await i18nStore.fetchI18n();
|
|
|
|
const languageData = JSON.parse(localStorage.getItem('i18nStore') as any);
|
|
|
|
// 初始化设置多语言内容
|
|
|
|
const locale = $storage.locale.locale;
|
|
|
|
// 如果本地没有语言版本,设置为服务端默认内容
|
|
|
|
if (locale == '' || locale == null || !locale) {
|
|
|
|
const local = languageData.i18n.local;
|
|
|
|
i18n.locale.value = local;
|
|
|
|
$storage.locale = { locale: local };
|
|
|
|
i18n.mergeLocaleMessage(local, languageData.i18n[local]);
|
|
|
|
return;
|
|
|
|
}
|
2024-09-26 09:38:02 +08:00
|
|
|
|
2024-10-03 15:52:18 +08:00
|
|
|
i18n.locale.value = locale;
|
|
|
|
$storage.locale = { locale };
|
|
|
|
i18nStore.i18n.local = locale;
|
|
|
|
i18n.mergeLocaleMessage(locale, languageData.i18n[locale]);
|
2024-09-26 09:38:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* * 当前语言类别
|
|
|
|
*/
|
|
|
|
const currentLocale = computed(() => {
|
2024-10-03 15:52:18 +08:00
|
|
|
const languageData = JSON.parse(localStorage.getItem('i18nStore') as any);
|
|
|
|
const local = languageData ? languageData.i18n.local : {};
|
|
|
|
return local === 'zh' ? { ...zhCn, ...plusZhCn } : { ...plusEn, ...en };
|
2024-09-26 09:38:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
onMounted(() => {
|
2024-10-03 15:52:18 +08:00
|
|
|
// 设置多语言
|
|
|
|
setI18n();
|
2024-09-26 09:38:02 +08:00
|
|
|
});
|
|
|
|
</script>
|