From f4b902011e685a96b09cbbc4e07e2eb4302c5005 Mon Sep 17 00:00:00 2001 From: zhangdaiscott Date: Fri, 10 Nov 2023 19:49:55 +0800 Subject: [PATCH] =?UTF-8?q?online=E8=8F=9C=E5=8D=95=E5=90=8D=E5=AD=97?= =?UTF-8?q?=E5=92=8C=E9=A1=B5=E9=9D=A2title=E4=B8=8D=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/web/useTitle.ts | 41 +++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/src/hooks/web/useTitle.ts b/src/hooks/web/useTitle.ts index ed28a21..a25f5f8 100644 --- a/src/hooks/web/useTitle.ts +++ b/src/hooks/web/useTitle.ts @@ -4,8 +4,8 @@ import { useTitle as usePageTitle } from '@vueuse/core'; import { useGlobSetting } from '/@/hooks/setting'; import { useRouter } from 'vue-router'; import { useLocaleStore } from '/@/store/modules/locale'; - import { REDIRECT_NAME } from '/@/router/constant'; +import { getMenus } from '/@/router/menus'; /** * Listening to page changes and dynamically changing site titles @@ -26,10 +26,43 @@ export function useTitle() { if (route.name === REDIRECT_NAME) { return; } - - const tTitle = t(route?.meta?.title as string); - pageTitle.value = tTitle ? ` ${tTitle} - ${title} ` : `${title}`; + // update-begin--author:liaozhiyang---date:20231110---for:【QQYUN-6938】online菜单名字和页面title不一致 + if (route.params && Object.keys(route.params).length) { + getMenus().then((menus) => { + const getTitle = getMatchingRouterName(menus, route.fullPath); + let tTitle = ''; + if (getTitle) { + tTitle = t(getTitle); + } else { + tTitle = t(route?.meta?.title as string); + }; + pageTitle.value = tTitle ? ` ${tTitle} - ${title} ` : `${title}`; + }); + } else { + const tTitle = t(route?.meta?.title as string); + pageTitle.value = tTitle ? ` ${tTitle} - ${title} ` : `${title}`; + } + // update-end--author:liaozhiyang---date:20231110---for:【QQYUN-6938】online菜单名字和页面title不一致 }, { immediate: true } ); } +/** + 2023-11-09 + liaozhiyang + 获取路由匹配模式的真实页面名字 +*/ +function getMatchingRouterName(menus, path) { + for (let i = 0, len = menus.length; i < len; i++) { + const item = menus[i]; + if (item.path === path && !item.redirect && !item.paramPath) { + return item.meta?.title; + } else if (item.children?.length) { + const result = getMatchingRouterName(item.children, path); + if (result) { + return result; + } + } + } + return ''; +}