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