feat 修改三级路由跳转问题

This commit is contained in:
Asoka 2025-06-05 15:34:51 +08:00
parent b8c8d403db
commit df35c72dae
4 changed files with 80 additions and 70 deletions

View File

@ -82,21 +82,7 @@ const closeLayoutAsideMobileMode = () => {
if (clientWidth < 1000) themeConfig.value.isCollapse = false if (clientWidth < 1000) themeConfig.value.isCollapse = false
document.body.setAttribute('class', '') document.body.setAttribute('class', '')
} }
// //
const setFilterRoutes = () => {
if (themeConfig.value.layout === 'columns') return false
state.menuList = filterRoutesFun(routesList.value)
}
//
const filterRoutesFun = <T extends RouteItem>(arr: T[]): T[] => {
return arr
.filter((item: T) => !item.meta?.isHide)
.map((item: T) => {
item = Object.assign({}, item)
if (item.children) item.children = filterRoutesFun(item.children)
return item
})
}
// //
const initMenuFixed = (clientWidth: number) => { const initMenuFixed = (clientWidth: number) => {
state.clientWidth = clientWidth state.clientWidth = clientWidth
@ -112,15 +98,16 @@ const onAsideEnterLeave = (bool: Boolean) => {
// //
onBeforeMount(() => { onBeforeMount(() => {
initMenuFixed(document.body.clientWidth) initMenuFixed(document.body.clientWidth)
setFilterRoutes()
// (mittBus.off('setSendColumnsChildren)) // (mittBus.off('setSendColumnsChildren))
// 使 // 使
mittBus.on('setSendColumnsChildren', (res: MittMenu) => { mittBus.on('setSendColumnsChildren', (res: MittMenu) => {
console.log('setSendColumnsChildren', res)
!res.children || res.children.length < 1 ? (themeConfig.value.isCollapse = true) : (themeConfig.value.isCollapse = false) !res.children || res.children.length < 1 ? (themeConfig.value.isCollapse = true) : (themeConfig.value.isCollapse = false)
state.menuList = res.children state.menuList = res.children
}) })
// //
mittBus.on('setSendClassicChildren', (res: MittMenu) => { mittBus.on('setSendClassicChildren', (res: MittMenu) => {
console.log('setSendClassicChildren', res)
let { layout, isClassicSplitMenu } = themeConfig.value let { layout, isClassicSplitMenu } = themeConfig.value
if (layout === 'classic' && isClassicSplitMenu) { if (layout === 'classic' && isClassicSplitMenu) {
// //
@ -131,10 +118,6 @@ onBeforeMount(() => {
state.menuList = res.children state.menuList = res.children
} }
}) })
//
mittBus.on('getBreadcrumbIndexSetFilterRoutes', () => {
setFilterRoutes()
})
// () // ()
mittBus.on('layoutMobileResize', (res: LayoutMobileResize) => { mittBus.on('layoutMobileResize', (res: LayoutMobileResize) => {
initMenuFixed(res.clientWidth) initMenuFixed(res.clientWidth)
@ -157,11 +140,17 @@ watch(
if (layout === 'classic' && isClassicSplitMenu) return false if (layout === 'classic' && isClassicSplitMenu) return false
} }
) )
// ` -> -> ` //
watch( watch(
() => routesList.value, () => routesList.value,
() => { () => {
setFilterRoutes() //
} if (themeConfig.value.layout === 'defaults') return
//
if (routesList.value.length > 0) {
layoutAsideScrollbarRef.value?.update()
}
},
{ deep: true }
) )
</script> </script>

View File

@ -17,6 +17,7 @@
<span>{{ $t(item.meta?.title) }}</span> <span>{{ $t(item.meta?.title) }}</span>
</el-menu-item> </el-menu-item>
</el-menu> </el-menu>
<!-- 将四个模块合并为一个下拉菜单类似语言切换 --> <!-- 将四个模块合并为一个下拉菜单类似语言切换 -->
<el-dropdown <el-dropdown
:show-timeout="70" :show-timeout="70"
@ -185,33 +186,24 @@ const onModuleCommand = (path: string) => {
const selectedModule = menuLists.value.find(item => item.path === path) const selectedModule = menuLists.value.find(item => item.path === path)
if (!selectedModule) return if (!selectedModule) return
// 使 //
if (selectedModule.meta?.isLink && !selectedModule.meta?.isIframe) {
onALinkClick(selectedModule)
return
}
//
if (selectedModule.children && selectedModule.children.length > 0) { if (selectedModule.children && selectedModule.children.length > 0) {
const firstChild = selectedModule.children.find((child: RouteItem) => !child.meta?.isHide) const firstChild = selectedModule.children.find((child: RouteRecordRaw) => !child.meta?.isHide)
if (firstChild) { if (firstChild) {
router.push(firstChild.path) router.push(firstChild.path)
// console.log('onModuleCommand setSendColumnsChildren1', firstChild.path)
//
mittBus.emit('setSendColumnsChildren', setSendSubMenuChildren(firstChild.path)) mittBus.emit('setSendColumnsChildren', setSendSubMenuChildren(firstChild.path))
} else { } else {
router.push(selectedModule.path) router.push(selectedModule.path)
console.log('onModuleCommand setSendColumnsChildren2', firstChild.path)
mittBus.emit('setSendColumnsChildren', { children: [] }) mittBus.emit('setSendColumnsChildren', { children: [] })
} }
} else { } else {
router.push(selectedModule.path) router.push(selectedModule.path)
console.log('onModuleCommand setSendColumnsChildren3', selectedModule.path)
mittBus.emit('setSendColumnsChildren', { children: [] }) mittBus.emit('setSendColumnsChildren', { children: [] })
} }
//
mittBus.emit('getBreadcrumbIndexSetFilterRoutes')
if (themeConfig.value.layout === 'classic' && themeConfig.value.isClassicSplitMenu) {
mittBus.emit('setSendClassicChildren', setSendClassicChildren(path))
}
} }
// //
@ -239,14 +231,17 @@ const setSendSubMenuChildren = (path: string) => {
res.children = sub.children ? [...sub.children] : [] res.children = sub.children ? [...sub.children] : []
} }
} }
console.log('res', res)
return res return res
} }
// //
const onSubMenuClick = (path: string) => { const onSubMenuClick = (path: string) => {
//
router.push(path) router.push(path)
// //
mittBus.emit('getBreadcrumbIndexSetFilterRoutes') console.log('onSubMenuClick setSendColumnsChildren4', path)
mittBus.emit('setSendColumnsChildren', setSendSubMenuChildren(path)) mittBus.emit('setSendColumnsChildren', setSendSubMenuChildren(path))
} }
@ -287,12 +282,11 @@ onBeforeRouteUpdate((to) => {
if (matchedModule) { if (matchedModule) {
state.currentModulePath = matchedModule.path state.currentModulePath = matchedModule.path
} }
// // tagsView
// tagsView // let { layout, isClassicSplitMenu } = themeConfig.value
let { layout, isClassicSplitMenu } = themeConfig.value // if (layout === 'classic' && isClassicSplitMenu) {
if (layout === 'classic' && isClassicSplitMenu) { // mittBus.emit('setSendClassicChildren', setSendClassicChildren(to.path))
mittBus.emit('setSendClassicChildren', setSendClassicChildren(to.path)) // }
}
}) })
</script> </script>

View File

@ -3,7 +3,7 @@
<el-sub-menu :index="val.path" :key="val.path" v-if="val.children && val.children.length > 0"> <el-sub-menu :index="val.path" :key="val.path" v-if="val.children && val.children.length > 0">
<template #title> <template #title>
<SvgIcon :name="val.meta.icon" /> <SvgIcon :name="val.meta.icon" />
<span>{{ $t(val.meta.title) }}</span> <span>{{ $t(val.meta.title) + '12345' }}</span>
</template> </template>
<sub-item :chil="val.children" /> <sub-item :chil="val.children" />
</el-sub-menu> </el-sub-menu>
@ -11,13 +11,7 @@
<el-menu-item :index="val.path" :key="val.path"> <el-menu-item :index="val.path" :key="val.path">
<template v-if="!val.meta.isLink || (val.meta.isLink && val.meta.isIframe)"> <template v-if="!val.meta.isLink || (val.meta.isLink && val.meta.isIframe)">
<SvgIcon :name="val.meta.icon" /> <SvgIcon :name="val.meta.icon" />
<span>{{ $t(val.meta.title) }}</span> <span>{{ $t(val.meta.title) + '123456' }}</span>
</template>
<template v-else>
<a class="w100" @click.prevent="onALinkClick(val)">
<SvgIcon :name="val.meta.icon" />
{{ $t(val.meta.title) }}
</a>
</template> </template>
</el-menu-item> </el-menu-item>
</template> </template>
@ -27,7 +21,6 @@
<script setup lang="ts" name="navMenuSubItem"> <script setup lang="ts" name="navMenuSubItem">
import { computed } from 'vue' import { computed } from 'vue'
import { RouteRecordRaw } from 'vue-router' import { RouteRecordRaw } from 'vue-router'
import other from '/@/utils/other'
// //
const props = defineProps({ const props = defineProps({
@ -40,10 +33,7 @@ const props = defineProps({
// //
const chils = computed(() => { const chils = computed(() => {
console.log('chils', props.chil)
return <RouteItems>props.chil return <RouteItems>props.chil
}) })
//
const onALinkClick = (val: RouteItem) => {
other.handleOpenLink(val)
}
</script> </script>

View File

@ -10,19 +10,24 @@
<template v-for="val in menuLists"> <template v-for="val in menuLists">
<el-sub-menu :index="val.path" v-if="val.children && val.children.length > 0" :key="val.path"> <el-sub-menu :index="val.path" v-if="val.children && val.children.length > 0" :key="val.path">
<template #title> <template #title>
<SvgIcon :name="val.meta.icon" /> <SvgIcon :name="val.meta?.icon || ''" />
<span>{{ $t(val.meta.title) }}</span> <span>{{ $t(val.meta?.title || '') }}</span>
</template> </template>
<SubItem :chil="val.children" /> <SubItem :chil="val.children" />
</el-sub-menu> </el-sub-menu>
<template v-else> <template v-else>
<el-menu-item :index="val.path" :key="val.path"> <el-menu-item :index="val.path" :key="val.path">
<SvgIcon :name="val.meta.icon" /> <SvgIcon :name="val.meta?.icon || ''" />
<template #title v-if="!val.meta.isLink || (val.meta.isLink && val.meta.isIframe)"> <template
<span>{{ $t(val.meta.title) }}</span> #title
v-if="!val.meta?.isLink || (val.meta?.isLink && val.meta?.isIframe)"
>
<span>{{ $t(val.meta?.title || '') }}</span>
</template> </template>
<template #title v-else> <template #title v-else>
<a class="w100" @click.prevent="onALinkClick(val)">{{ $t(val.meta.title) }}</a> <a class="w100" @click.prevent="onALinkClick(val)">
{{ $t(val.meta?.title || '') }}
</a>
</template> </template>
</el-menu-item> </el-menu-item>
</template> </template>
@ -31,11 +36,13 @@
</template> </template>
<script setup lang="ts" name="navMenuVertical"> <script setup lang="ts" name="navMenuVertical">
import { defineAsyncComponent, reactive, computed, onMounted, watch } from 'vue' import { defineAsyncComponent, reactive, computed, ref, watch, onMounted } from 'vue'
import type { PropType } from 'vue'
import { useRoute, onBeforeRouteUpdate, RouteRecordRaw } from 'vue-router' import { useRoute, onBeforeRouteUpdate, RouteRecordRaw } from 'vue-router'
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
import { useThemeConfig } from '/@/stores/themeConfig' import { useThemeConfig } from '/@/stores/themeConfig'
import other from '/@/utils/other' import other from '/@/utils/other'
import mittBus from '/@/utils/mitt'
// //
const SubItem = defineAsyncComponent(() => import('/@/layout/navMenu/subItem.vue')) const SubItem = defineAsyncComponent(() => import('/@/layout/navMenu/subItem.vue'))
@ -44,7 +51,7 @@ const SubItem = defineAsyncComponent(() => import('/@/layout/navMenu/subItem.vue
const props = defineProps({ const props = defineProps({
// //
menuList: { menuList: {
type: Array<RouteRecordRaw>, type: Array as PropType<RouteItem[]>,
default: () => [], default: () => [],
}, },
}) })
@ -58,16 +65,42 @@ const state = reactive({
isCollapse: false, isCollapse: false,
}) })
// //
const menuLists = computed(() => { const localMenuList = ref<RouteItem[]>([])
return <RouteItems>props.menuList
//
localMenuList.value = props.menuList
// Debug: initial menuList received
console.log('vertical initial menuList:', props.menuList)
// menuList
watch(
() => props.menuList,
(newList) => {
// Debug: props.menuList changed
console.log('vertical props.menuList changed:', newList)
localMenuList.value = newList
},
{ immediate: true }
)
//
mittBus.on('setSendColumnsChildren', (res) => {
// Debug: received setSendColumnsChildren event
console.log('vertical received setSendColumnsChildren:', res)
localMenuList.value = res.children || []
}) })
//
const menuLists = computed(() => localMenuList.value)
// //
const getThemeConfig = computed(() => { const getThemeConfig = computed(() => {
return themeConfig.value return themeConfig.value
}) })
// //
const setParentHighlight = (currentRoute: RouteToFrom) => { const setParentHighlight = (currentRoute: RouteToFrom) => {
console.log('vertical currentRoute', currentRoute)
const { path, meta } = currentRoute const { path, meta } = currentRoute
const pathSplit = meta?.isDynamic ? meta.isDynamicPath!.split('/') : path!.split('/') const pathSplit = meta?.isDynamic ? meta.isDynamicPath!.split('/') : path!.split('/')
if (pathSplit.length >= 4 && meta?.isHide) return pathSplit.splice(0, 3).join('/') if (pathSplit.length >= 4 && meta?.isHide) return pathSplit.splice(0, 3).join('/')
@ -79,10 +112,14 @@ const onALinkClick = (val: RouteItem) => {
} }
// //
onMounted(() => { onMounted(() => {
// Debug: onMounted, current route
console.log('vertical onMounted route.path:', route.path)
state.defaultActive = setParentHighlight(route) state.defaultActive = setParentHighlight(route)
}) })
// //
onBeforeRouteUpdate((to) => { onBeforeRouteUpdate((to) => {
// Debug: onBeforeRouteUpdate, target route
console.log('vertical onBeforeRouteUpdate to.path:', to.path)
state.defaultActive = setParentHighlight(to) state.defaultActive = setParentHighlight(to)
const clientWidth = document.body.clientWidth const clientWidth = document.body.clientWidth
if (clientWidth < 1000) themeConfig.value.isCollapse = false if (clientWidth < 1000) themeConfig.value.isCollapse = false