修复bug
This commit is contained in:
@ -8,15 +8,15 @@
|
||||
</div>
|
||||
<div class="flex">
|
||||
<div class="navigation-item pointer" v-for="item in navRoutes" :key="item.path"
|
||||
@click="handleParentClick(item)" @mouseenter="showSubmenu(item)" @mouseleave="hideSubmenu">
|
||||
@click="handleParentClick(item)" @mouseenter="showSubmenu(item)" @mouseleave="hideSubmenu">
|
||||
<span
|
||||
:class="{ 'selected-navigation': $route.matched.some(record => record.path === item.path) }">{{
|
||||
:class="{ 'selected-navigation': isParentMatch(item) }">{{
|
||||
item.meta.navigationName }}
|
||||
<i class="el-icon-arrow-down" v-if="item.meta.children"></i>
|
||||
<i class="el-icon-arrow-down" v-if="item.meta.children"></i>
|
||||
</span>
|
||||
<div v-if="activeMenu === item.path && item.meta.children" class="submenu">
|
||||
<div v-for="sub in item.children" :key="sub.path" @click.stop="goto(sub.path)"
|
||||
class="submenu-item pointer">
|
||||
class="submenu-item pointer">
|
||||
<img :src="`/logo/${sub.meta.icon}.png`" alt="" />
|
||||
{{ sub.name }}
|
||||
</div>
|
||||
@ -84,6 +84,39 @@ export default {
|
||||
hideSubmenu() {
|
||||
this.activeMenu = null;
|
||||
},
|
||||
/**
|
||||
* 判断当前导航项是否应该被选中
|
||||
* @param {Object} item 导航项
|
||||
* @returns {Boolean} 是否选中
|
||||
*/
|
||||
isParentMatch(item) {
|
||||
// 首先检查原始的路径匹配逻辑,保持向后兼容性
|
||||
const pathMatch = this.$route.matched.some(record => record.path === item.path);
|
||||
if (pathMatch) return true;
|
||||
|
||||
// 获取当前路由的meta信息
|
||||
const currentRouteMeta = this.$route.meta || {};
|
||||
const currentParent = currentRouteMeta.parent;
|
||||
|
||||
// 如果当前路由没有parent属性,直接返回false
|
||||
if (!currentParent) return false;
|
||||
|
||||
// 获取当前导航项的meta信息
|
||||
const navItemMeta = item.meta || {};
|
||||
const navItemParent = navItemMeta.parent || '';
|
||||
|
||||
// 根据parent属性的类型进行判断
|
||||
if (typeof currentParent === 'string') {
|
||||
// parent是字符串时,直接比较是否相等
|
||||
return currentParent === navItemParent;
|
||||
} else if (Array.isArray(currentParent)) {
|
||||
// parent是数组时,判断导航项的parent是否在数组中
|
||||
return currentParent.includes(navItemParent);
|
||||
}
|
||||
|
||||
// 其他情况返回false
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
@ -98,13 +131,13 @@ export default {
|
||||
.navigation-container {
|
||||
height: $navigationBarHeight;
|
||||
display: flex;
|
||||
font-weight: 500;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
.logo {
|
||||
@include flex-center;
|
||||
color: $white;
|
||||
//font-family: 'Poppins-Bold', serif;
|
||||
|
||||
span {
|
||||
font-size: $normal-font-size;
|
||||
@ -115,6 +148,7 @@ export default {
|
||||
margin-left: 20px;
|
||||
padding: 10px;
|
||||
position: relative;
|
||||
//font-family: 'Poppins-Medium', serif;
|
||||
|
||||
span {
|
||||
color: $grey;
|
||||
@ -125,6 +159,8 @@ export default {
|
||||
|
||||
&.selected-navigation {
|
||||
color: $white;
|
||||
font-weight: 500;
|
||||
//font-family: 'Poppins-Bold', serif;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user