Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gs1
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
吴迪
gs1
Commits
7437e984
Commit
7437e984
authored
Oct 03, 2021
by
Tang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 优化头部导航激活状态
parent
d85fb029
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
45 deletions
+91
-45
index.vue
src/components/layout/header/index.vue
+91
-45
No files found.
src/components/layout/header/index.vue
View file @
7437e984
...
@@ -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
:
#002
C6C
;
color
:
#002
c6c
;
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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment