fix: 处理router.多语言显示
This commit is contained in:
@@ -118,8 +118,9 @@ const router = createRouter({
|
||||
/**全局路由-后置守卫 */
|
||||
router.afterEach((to, from, failure) => {
|
||||
NProgress.done();
|
||||
const title = to.meta?.title
|
||||
// 设置标题
|
||||
if (to.meta?.title) {
|
||||
if (!failure && title) {
|
||||
useAppStore().setTitle(to.meta.title);
|
||||
}
|
||||
});
|
||||
@@ -132,7 +133,7 @@ router.beforeEach((to, from, next) => {
|
||||
NProgress.start();
|
||||
const token = getToken();
|
||||
// 获取系统配置信息
|
||||
const appStore = useAppStore();
|
||||
const appStore =useAppStore()
|
||||
if (!appStore.loginBackground) {
|
||||
appStore.fnSysConf();
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ const useAppStore = defineStore('app', {
|
||||
actions: {
|
||||
/**设置网页标题 */
|
||||
setTitle(title?: string) {
|
||||
if (title) {
|
||||
if (title && title.indexOf('router.') === -1) {
|
||||
document.title = `${title} - ${this.appName}`;
|
||||
} else {
|
||||
document.title = this.appName;
|
||||
|
||||
@@ -6,7 +6,11 @@ import { reactive, ref, onMounted } from 'vue';
|
||||
import { parseDateToStr } from '@/utils/date-utils';
|
||||
import useUserStore from '@/store/modules/user';
|
||||
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||
import { useRoute } from 'vue-router';
|
||||
import useAppStore from '@/store/modules/app';
|
||||
import useI18n from '@/hooks/useI18n';
|
||||
const appStore = useAppStore();
|
||||
const route = useRoute();
|
||||
const { t } = useI18n();
|
||||
|
||||
/**加载状态 */
|
||||
@@ -71,7 +75,19 @@ function fnGetProfile() {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 国际化翻译转换
|
||||
*/
|
||||
function fnLocale() {
|
||||
let title = route.meta.title as string;
|
||||
if (title.indexOf('router.') !== -1) {
|
||||
title = t(title);
|
||||
}
|
||||
appStore.setTitle(title);
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fnLocale();
|
||||
// 获取信息
|
||||
fnGetProfile();
|
||||
});
|
||||
|
||||
@@ -1,14 +1,36 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
import { onActivated, ref } from 'vue';
|
||||
import { PageContainer } from '@ant-design-vue/pro-layout';
|
||||
import BaseInfo from './components/base-info.vue';
|
||||
import ResetPasswd from './components/reset-passwd.vue';
|
||||
import StyleLayout from './components/style-layout.vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import useAppStore from '@/store/modules/app';
|
||||
import useI18n from '@/hooks/useI18n';
|
||||
const appStore = useAppStore();
|
||||
const route = useRoute();
|
||||
const { t } = useI18n();
|
||||
|
||||
/**Tab标签激活 */
|
||||
let activeKey = ref<string>('base-info');
|
||||
|
||||
/**
|
||||
* 国际化翻译转换
|
||||
*/
|
||||
function fnLocale() {
|
||||
let title = route.meta.title as string;
|
||||
if (title.indexOf('router.') !== -1) {
|
||||
title = t(title);
|
||||
}
|
||||
appStore.setTitle(title);
|
||||
}
|
||||
|
||||
onActivated(() => {
|
||||
// 调用时机为首次挂载
|
||||
// 以及每次从缓存中被重新插入时
|
||||
fnLocale();
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -18,10 +40,16 @@ let activeKey = ref<string>('base-info');
|
||||
<a-tab-pane key="base-info" :tab="t('views.account.settings.baseInfo')">
|
||||
<BaseInfo></BaseInfo>
|
||||
</a-tab-pane>
|
||||
<a-tab-pane key="reset-passwd" :tab="t('views.account.settings.resetPasswd')">
|
||||
<a-tab-pane
|
||||
key="reset-passwd"
|
||||
:tab="t('views.account.settings.resetPasswd')"
|
||||
>
|
||||
<ResetPasswd></ResetPasswd>
|
||||
</a-tab-pane>
|
||||
<a-tab-pane key="style-layout" :tab="t('views.account.settings.styleLayout')">
|
||||
<a-tab-pane
|
||||
key="style-layout"
|
||||
:tab="t('views.account.settings.styleLayout')"
|
||||
>
|
||||
<StyleLayout></StyleLayout>
|
||||
</a-tab-pane>
|
||||
</a-tabs>
|
||||
|
||||
@@ -12,7 +12,12 @@ import * as echarts from 'echarts/core';
|
||||
import { TitleComponent, LegendComponent } from 'echarts/components';
|
||||
import { PieChart } from 'echarts/charts';
|
||||
import { LabelLayout } from 'echarts/features';
|
||||
import { useRoute } from 'vue-router';
|
||||
import useAppStore from '@/store/modules/app';
|
||||
const appStore = useAppStore();
|
||||
const route = useRoute();
|
||||
const { t } = useI18n();
|
||||
|
||||
echarts.use([
|
||||
TooltipComponent,
|
||||
GaugeChart,
|
||||
@@ -370,7 +375,20 @@ function rowClick(record: any, index: any) {
|
||||
};
|
||||
}
|
||||
let timer: any;
|
||||
|
||||
/**
|
||||
* 国际化翻译转换
|
||||
*/
|
||||
function fnLocale( ) {
|
||||
let title = route.meta.title as string;
|
||||
if (title.indexOf('router.') !== -1) {
|
||||
title = t(title);
|
||||
}
|
||||
appStore.setTitle(title);
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fnLocale()
|
||||
fnGetList();
|
||||
timer = setInterval(fnGetList, 10000); // 每隔10秒执行一次
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user