From c16972a80ca98e246588cd0fbf5d34928c519e4b Mon Sep 17 00:00:00 2001 From: "X.Mo" Date: Tue, 9 Jul 2024 10:42:25 +0800 Subject: [PATCH] fix: redirect bug --- src/layout/components/columns/ma-columns-menu.vue | 12 ++++++------ src/layout/components/components/children-menu.vue | 4 +--- src/layout/components/mixed/index.vue | 13 ++++++++----- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/layout/components/columns/ma-columns-menu.vue b/src/layout/components/columns/ma-columns-menu.vue index bb4578c7..0be8a550 100644 --- a/src/layout/components/columns/ma-columns-menu.vue +++ b/src/layout/components/columns/ma-columns-menu.vue @@ -60,14 +60,14 @@ const classStyle = ref('flex flex-col parent-menu items-center rounded mt-1 text-gray-200 hover:bg-gray-700 dark:hover:text-gray-50 dark:hover:bg-blackgray-1') onMounted(() => { - initMenu() + initMenu(true) }) watch(() => route, v => { - initMenu() + initMenu(false) }, { deep: true }) - const initMenu = () => { + const initMenu = (init = true) => { let current if (route.matched[1]?.meta?.breadcrumb) { current = route.matched[1].meta.breadcrumb[0].name @@ -76,18 +76,18 @@ } if (userStore.routers && userStore.routers.length > 0) { userStore.routers.map((item, index) => { - if (item.name == current) loadMenu(item, index) + if (item.name == current) loadMenu(item, index, init) }) } } - const loadMenu = (bigMenu, index) => { + const loadMenu = (bigMenu, index, isInit = true) => { if (bigMenu.meta.type === 'L') { window.open(bigMenu.path) return } if (bigMenu.children.length > 0) { - if (bigMenu.redirect) { + if (bigMenu.redirect && isInit) { router.push(bigMenu.redirect) } MaMenuRef.value.loadChildMenu(bigMenu) diff --git a/src/layout/components/components/children-menu.vue b/src/layout/components/components/children-menu.vue index f36519e5..bcbc60bf 100644 --- a/src/layout/components/components/children-menu.vue +++ b/src/layout/components/components/children-menu.vue @@ -51,9 +51,7 @@ const routerPush = (menu) => { if (menu.meta && menu.meta.type === 'L') { window.open(menu.path) - } else if (menu.redirect) { - router.push(menu.redirect) - } else { + }else { router.push(menu.path) tagStore.addTag({ name: menu.name, title: menu.meta.title, path: menu.path }) } diff --git a/src/layout/components/mixed/index.vue b/src/layout/components/mixed/index.vue index 7272a4ed..23867771 100644 --- a/src/layout/components/mixed/index.vue +++ b/src/layout/components/mixed/index.vue @@ -62,14 +62,14 @@ const active = ref() onMounted(() => { - initMenu() + initMenu(true) }) watch(() => route, v => { - initMenu() + initMenu(false) }, { deep: true }) - const initMenu = () => { + const initMenu = (init = true) => { if (route.matched[1]?.meta?.breadcrumb) { active.value = route.matched[1].meta.breadcrumb[0].name } else { @@ -77,17 +77,20 @@ } if (userStore.routers && userStore.routers.length > 0) { userStore.routers.map((item, index) => { - if (item.name == active.value) loadMenu(item) + if (item.name == active.value) loadMenu(item, init) }) } } - const loadMenu = (bigMenu) => { + const loadMenu = (bigMenu, isInit = true) => { if (bigMenu.meta.type === 'L') { window.open(bigMenu.path) return } if (bigMenu.children.length > 0) { + if (bigMenu.redirect && isInit) { + router.push(bigMenu.redirect) + } MaMenuRef.value.loadChildMenu(bigMenu) showMenu.value = true } else {