From bb577bef0ba81b9ff1fcbea4eba6a842b6a0be18 Mon Sep 17 00:00:00 2001
From: TsMask <340112800@qq.com>
Date: Fri, 17 Nov 2023 11:16:08 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=84=E7=90=86router.=E5=A4=9A?=
=?UTF-8?q?=E8=AF=AD=E8=A8=80=E6=98=BE=E7=A4=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/router/index.ts | 5 +++--
src/store/modules/app.ts | 2 +-
src/views/account/profile.vue | 16 ++++++++++++++++
src/views/account/settings.vue | 34 +++++++++++++++++++++++++++++++---
src/views/index.vue | 18 ++++++++++++++++++
5 files changed, 69 insertions(+), 6 deletions(-)
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 @@
@@ -18,10 +40,16 @@ let activeKey = ref('base-info');
-
+
-
+
diff --git a/src/views/index.vue b/src/views/index.vue
index c823855f..9488501e 100644
--- a/src/views/index.vue
+++ b/src/views/index.vue
@@ -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秒执行一次
});