diff --git a/src/router/index.ts b/src/router/index.ts index f9406532..23e9b84c 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -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(); } diff --git a/src/store/modules/app.ts b/src/store/modules/app.ts index fa29a5ad..bc6d9df4 100644 --- a/src/store/modules/app.ts +++ b/src/store/modules/app.ts @@ -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; diff --git a/src/views/account/profile.vue b/src/views/account/profile.vue index 20a4a3b3..71c0131f 100644 --- a/src/views/account/profile.vue +++ b/src/views/account/profile.vue @@ -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(); }); diff --git a/src/views/account/settings.vue b/src/views/account/settings.vue index e23fc2db..6a65315a 100644 --- a/src/views/account/settings.vue +++ b/src/views/account/settings.vue @@ -1,14 +1,36 @@