From 6d9b76e5b13c573cbe926e2f5529a556c1e64f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Thu, 9 Feb 2023 11:49:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96topNav=E6=89=93=E5=BC=80?= =?UTF-8?q?=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/TopNav/index.vue | 51 +++++++++++++-------------------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/src/components/TopNav/index.vue b/src/components/TopNav/index.vue index d0c6e11..9a8300a 100644 --- a/src/components/TopNav/index.vue +++ b/src/components/TopNav/index.vue @@ -43,10 +43,10 @@ import usePermissionStore from '@/store/modules/permission' // 顶部栏初始数 const visibleNumber = ref(5) -// 是否为首次加载 -const isFrist = ref(false) // 当前激活菜单的 index const currentIndex = ref(undefined) +// 隐藏侧边栏路由 +const hideList = ['/index', '/user/profile'] const appStore = useAppStore() const settingsStore = useSettingsStore() @@ -82,10 +82,10 @@ const childrenMenus = computed(() => { for (let item in router.children) { if (router.children[item].parentPath === undefined) { if (router.path === '/') { - router.children[item].path = getNormalPath('/redirect/' + router.children[item].path) + router.children[item].path = '/' + router.children[item].path } else { if (!isHttp(router.children[item].path)) { - router.children[item].path = getNormalPath(router.path + '/' + router.children[item].path) + router.children[item].path = router.path + '/' + router.children[item].path } } router.children[item].parentPath = router.path @@ -99,52 +99,39 @@ const childrenMenus = computed(() => { // 默认激活的菜单 const activeMenu = computed(() => { const path = route.path - let activePath = defaultRouter.value - if (path.lastIndexOf('/') > 0) { + let activePath = path + if (path !== undefined && path.lastIndexOf('/') > 0 && hideList.indexOf(path) === -1) { const tmpPath = path.substring(1, path.length) activePath = '/' + tmpPath.substring(0, tmpPath.indexOf('/')) - } else if ('/index' == path || '' == path) { - if (!isFrist.value) { - isFrist.value = true - } else { - activePath = 'index' + if (!route.meta.link) { + appStore.toggleSideBarHide(false) } + } else if (!route.children) { + activePath = path + appStore.toggleSideBarHide(true) } - let routes = activeRoutes(activePath) - if (routes.length === 0) { - activePath = currentIndex.value || defaultRouter.value - - activeRoutes(activePath) - } + activeRoutes(activePath) return activePath }) -// 默认激活的路由 -const defaultRouter = computed(() => { - let router - Object.keys(routers.value).some((key) => { - if (!routers.value[key].hidden) { - router = routers.value[key].path - return true - } - }) - return router -}) function setVisibleNumber() { const width = document.body.getBoundingClientRect().width / 3 visibleNumber.value = parseInt(width / 85) } function handleSelect(key, keyPath) { currentIndex.value = key + const route = routers.value.find((item) => item.path === key) if (isHttp(key)) { // http(s):// 路径新窗口打开 window.open(key, '_blank') - } else if (key.indexOf('/redirect') !== -1) { - // /redirect 路径内部打开 - router.push({ path: key.replace('/redirect', '') }).catch((err) => {}) + } else if (!route || !route.children) { + // 没有子路由路径内部打开 + router.push({ path: key }) + appStore.toggleSideBarHide(true) } else { // 显示左侧联动菜单 activeRoutes(key) + appStore.toggleSideBarHide(false) } } // 当前激活的路由 @@ -159,6 +146,8 @@ function activeRoutes(key) { } if (routes.length > 0) { permissionStore.setSidebarRouters(routes) + } else { + // appStore.toggleSideBarHide(true) } return routes }