fix: 修复顶栏模式bug和侧栏无图标的bug

This commit is contained in:
pixelmaxQM 2025-04-21 23:14:53 +08:00
parent 09cb29da17
commit 54595d46e5
2 changed files with 35 additions and 46 deletions

View File

@ -5,31 +5,20 @@
height: sideHeight
}"
>
<template #title>
<div
v-if="!isCollapse"
class="flex items-center"
:style="{
height: sideHeight
}"
>
<el-icon v-if="routerInfo.meta.icon">
<component :is="routerInfo.meta.icon" />
</el-icon>
<span>{{ routerInfo.meta.title }}</span>
</div>
<template v-else>
<el-icon v-if="routerInfo.meta.icon">
<component :is="routerInfo.meta.icon" />
</el-icon>
<span>{{ routerInfo.meta.title }}</span>
</template>
<el-icon v-if="routerInfo.meta.icon">
<component :is="routerInfo.meta.icon" />
</el-icon>
<template v-else>
{{ routerInfo.meta.title[0] }}
</template>
<template #title>
{{ routerInfo.meta.title }}
</template>
</el-menu-item>
</template>
<script setup>
import { computed } from 'vue'
import {computed, inject} from 'vue'
import { useAppStore } from '@/pinia'
import { storeToRefs } from 'pinia'
const appStore = useAppStore()

View File

@ -17,8 +17,8 @@
@select="selectTopMenuItem"
>
<template v-for="item in routerStore.asyncRouters[0]?.children || []">
<el-menu-item
v-if="!item.hidden && (!item.children || item.children.length === 0)"
<el-menu-item
v-if="!item.hidden && (!item.children || item.children.length === 0)"
:key="item.name"
:index="item.name"
class="dark:text-slate-300 overflow-hidden"
@ -31,13 +31,13 @@
</el-icon>
<template v-else>
{{ item.meta.title[0] }}
</template>
</template>
<template #title>
{{ item.meta.title }}
</template>
</el-menu-item>
<template v-else-if="!item.hidden" >
<el-menu-item
<el-menu-item
:key="item.name"
:index="item.name"
:class="{'is-active': topActive === item.name}"
@ -110,14 +110,14 @@
import { useRouterStore } from '@/pinia/modules/router'
import { useAppStore } from '@/pinia'
import { storeToRefs } from 'pinia'
const appStore = useAppStore()
const { device, config } = storeToRefs(appStore)
defineOptions({
name: 'SidebarMode'
})
const route = useRoute()
const router = useRouter()
const routerStore = useRouterStore()
@ -125,7 +125,7 @@
const active = ref('')
const topActive = ref('')
const secondLevelMenus = ref([])
const layoutSideWidth = computed(() => {
if (!isCollapse.value) {
return config.value.layout_side_width
@ -136,7 +136,7 @@
provide('isCollapse', isCollapse)
//
const updateSecondLevelMenus = (menuName) => {
const menu = routerStore.asyncRouters[0]?.children.find(item => item.name === menuName)
@ -144,18 +144,18 @@
secondLevelMenus.value = menu.children
}
}
//
const selectTopMenuItem = (index) => {
topActive.value = index
//
const menu = routerStore.asyncRouters[0]?.children.find(item => item.name === index)
//
if (menu && menu.children && menu.children.length > 0) {
updateSecondLevelMenus(index)
//
const firstVisibleChild = menu.children.find(child => !child.hidden)
if (firstVisibleChild) {
@ -166,12 +166,12 @@
navigateToMenuItem(index)
}
}
//
const selectMenuItem = (index) => {
navigateToMenuItem(index)
}
//
const navigateToMenuItem = (index) => {
const query = {}
@ -208,33 +208,33 @@
}
watchEffect(() => {
if (route.name === 'Iframe') {
active.value = decodeURIComponent(route.query.url)
return
}
active.value = route.meta.activeName || route.name
//
const findParentMenu = () => {
//
const isTopMenu = routerStore.asyncRouters[0]?.children.some(
item => !item.hidden && item.name === route.name
)
if (isTopMenu) {
return route.name
}
for (const topMenu of routerStore.asyncRouters[0]?.children || []) {
if (topMenu.hidden) continue
//
if (topMenu.children && topMenu.children.some(child => child.name === route.name)) {
return topMenu.name
}
//
const checkChildren = (items) => {
for (const item of items || []) {
@ -247,18 +247,18 @@
}
return false
}
if (topMenu.children && checkChildren(topMenu.children)) {
return topMenu.name
}
}
return null
}
const parentMenu = findParentMenu()
if (parentMenu) {
topActive.value = parentMenu
//
const menu = routerStore.asyncRouters[0]?.children.find(item => item.name === parentMenu)
if (menu && menu.children && menu.children.length > 0) {
@ -269,7 +269,7 @@
const firstMenuWithChildren = routerStore.asyncRouters[0].children.find(
item => !item.hidden && item.children && item.children.length > 0
)
if (firstMenuWithChildren) {
//
updateSecondLevelMenus(firstMenuWithChildren.name)
@ -281,7 +281,7 @@
const firstMenuWithChildren = routerStore.asyncRouters[0].children.find(
item => !item.hidden && item.children && item.children.length > 0
)
if (firstMenuWithChildren) {
//
topActive.value = route.name
@ -297,4 +297,4 @@
isCollapse.value = false
}
})
</script>
</script>