Commit 7437e984 by Tang

feat: 优化头部导航激活状态

parent d85fb029
...@@ -4,43 +4,61 @@ ...@@ -4,43 +4,61 @@
<nav class="navbar-nav-wrap"> <nav class="navbar-nav-wrap">
<!-- Default Logo --> <!-- Default Logo -->
<a class="navbar-brand" href="/Home" aria-label="Front"> <a class="navbar-brand" href="/Home" aria-label="Front">
<img class="navbar-brand-logo" src="../../../assets/image/head/logo.png" alt="Logo"> <img
class="navbar-brand-logo"
src="../../../assets/image/head/logo.png"
alt="Logo"
/>
</a> </a>
<!-- End Default Logo --> <!-- End Default Logo -->
<!-- Collapse --> <!-- Collapse -->
<div class="navbar-collapse collapse" id="navbarNavDropdown"> <div class="navbar-collapse collapse" id="navbarNavDropdown">
<div class="navbar-absolute-top-scroller"> <div class="navbar-absolute-top-scroller">
<ul class="navbar-nav"> <ul class="navbar-nav">
<!-- Nav items--> <!-- Nav items-->
<li v-for="nav in navList" <template v-for="nav in navList">
<li
v-if="nav.children && nav.children.length > 0"
class="gs-nav-item nav-item" class="gs-nav-item nav-item"
:key="nav.id" :key="nav.id"
:class="{'active':currentNav===nav.id}" :class="{ active: currentNav === nav.id }"
@click="handleNavClick(nav)"> @click.stop="handleNavClick(nav)"
<a :id="`gs-nav-item-${nav.id}`" class="nav-link" >
aria-current="page" <a
href="#" :id="`gs-nav-item-${nav.id}`"
role="button" class="nav-link"
data-bs-toggle="dropdown" aria-current="page"
aria-expanded="false">{{ nav.name }}</a> href="#"
role="button"
<!-- Dropdown Menu --> data-bs-toggle="dropdown"
<HeaderDropdown v-if="nav.children.length>0" :nav="nav" @itemClick="handleItemClick"/> aria-expanded="false"
<!-- End Dropdown Menu --> >{{ nav.name }}</a
</li> >
<!-- Dropdown Menu -->
<HeaderDropdown :nav="nav" @itemClick="handleItemClick" />
<!-- End Dropdown Menu -->
</li>
<li
v-else
:key="nav.id"
@click.stop="handleNavClick(nav)"
class="gs-nav-item nav-item"
:class="{ active: currentNav === nav.id }"
>
<a class="nav-link" href="#">{{ nav.name }}</a>
</li>
</template>
<!-- Nav items End--> <!-- Nav items End-->
</ul> </ul>
</div> </div>
</div> </div>
<!-- End Collapse --> <!-- End Collapse -->
<!-- Button --> <!-- Button -->
<HeaderBtn/> <HeaderBtn />
<!-- End Button --> <!-- End Button -->
</nav> </nav>
</div> </div>
...@@ -50,30 +68,51 @@ ...@@ -50,30 +68,51 @@
<script> <script>
import HeaderBtn from "./HeaderBtn.vue"; import HeaderBtn from "./HeaderBtn.vue";
import HeaderDropdown from "./HeaderDropdown.vue"; import HeaderDropdown from "./HeaderDropdown.vue";
import {nav} from "./mock"; import { nav } from "./mock";
export default { export default {
components: {HeaderBtn, HeaderDropdown}, components: { HeaderBtn, HeaderDropdown },
data() { data() {
return { return {
navList: nav, navList: nav,
currentNav: '0', currentNav: "0",
preActive: "",
}; };
}, },
mounted() {
window.addEventListener("click", this.handleWindowClick);
},
beforeDestroy() {
window.removeEventListener("click", this.handleWindowClick);
},
methods: { methods: {
handleWindowClick() {
console.log(this.preActive);
if (this.preActive) {
this.currentNav = this.preActive;
this.preActive = "";
}
},
handleNavClick(nav) { handleNavClick(nav) {
if (!!nav.children || nav.children.length === 0){ if (!nav.children || nav.children.length === 0) {
this.currentNav = nav.id; this.currentNav = nav.id;
} else {
// 点击的是有dropdown的nav 需要保存当前激活状态
this.preActive = this.currentNav;
this.currentNav = "";
} }
}, },
handleItemClick(item) { handleItemClick(item) {
console.log(item); if (item.link.startsWith("http")) {
if (item.link.startsWith('http')) {
window.open(item.link); window.open(item.link);
} else { } else {
if (this.preActive !== "") {
this.preActive = "";
}
this.currentNav = item.root.id; this.currentNav = item.root.id;
item.breadcrumb && this.$store.commit('system/SET_BREADCRUMB', item.breadcrumb) item.breadcrumb &&
this.$router.push({path: item.link}) this.$store.commit("system/SET_BREADCRUMB", item.breadcrumb);
this.$router.push({ path: item.link });
} }
}, },
}, },
...@@ -86,7 +125,6 @@ export default { ...@@ -86,7 +125,6 @@ export default {
} }
.gs-header-nav { .gs-header-nav {
.navbar-nav-wrap { .navbar-nav-wrap {
position: relative; position: relative;
display: flex; display: flex;
...@@ -102,55 +140,64 @@ export default { ...@@ -102,55 +140,64 @@ export default {
// 导航item样式 // 导航item样式
.gs-nav-item.nav-item { .gs-nav-item.nav-item {
&.active > a { &.active > a,
color: #F26335; a.show {
color: #f26335;
&::after {
content: "";
position: absolute;
left: 8px;
right: 8px;
bottom: 0;
height: 2px;
background-color: #f26335;
}
} }
> a { > a {
position: relative;
font-size: 14px; font-size: 14px;
font-weight: bold; font-weight: bold;
color: #002C6C; color: #002c6c;
padding: 10px 8px; padding: 10px 8px;
margin: 0 16px; margin: 0 16px;
} }
} }
.navbar-toggler { .navbar-toggler {
padding: .5rem .5rem padding: 0.5rem 0.5rem;
} }
.navbar-toggler:focus { .navbar-toggler:focus {
box-shadow: none box-shadow: none;
} }
.navbar-toggler .navbar-toggler-text { .navbar-toggler .navbar-toggler-text {
color: #21325b color: #21325b;
} }
.navbar-toggler .navbar-toggler-default { .navbar-toggler .navbar-toggler-default {
display: flex display: flex;
} }
.navbar-toggler .navbar-toggler-toggled { .navbar-toggler .navbar-toggler-toggled {
display: none display: none;
} }
.navbar-toggler[aria-expanded=true] .navbar-toggler-default { .navbar-toggler[aria-expanded="true"] .navbar-toggler-default {
display: none display: none;
} }
.navbar-toggler[aria-expanded=true] .navbar-toggler-toggled { .navbar-toggler[aria-expanded="true"] .navbar-toggler-toggled {
display: flex display: flex;
} }
.navbar-topbar .navbar-toggler { .navbar-topbar .navbar-toggler {
margin-left: 0; margin-left: 0;
font-size: .875rem font-size: 0.875rem;
} }
} }
@media (max-width: 1400px) { @media (max-width: 1400px) {
//导航item边距 //导航item边距
.gs-header-nav .gs-nav-item.nav-item { .gs-header-nav .gs-nav-item.nav-item {
...@@ -160,7 +207,6 @@ export default { ...@@ -160,7 +207,6 @@ export default {
} }
} }
@media (max-width: 1200px) { @media (max-width: 1200px) {
//导航item边距 //导航item边距
.gs-header-nav .gs-nav-item.nav-item { .gs-header-nav .gs-nav-item.nav-item {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment