提交 5f7c7551 编写于 作者: D DCloud_LXH

feat: 下拉显示一级菜单,搜索框下沉

上级 53dc16a5
...@@ -61,11 +61,11 @@ ...@@ -61,11 +61,11 @@
flex-direction column flex-direction column
justify-content center justify-content center
#docsearch span #docsearch span
@media (min-width: $MQMobile) @media (min-width: 1200px)
& &
display flex display flex
@media (max-width: $MQMobile) @media (max-width: 1200px)
:root :root
--docsearch-spacing 10px --docsearch-spacing 10px
--docsearch-footer-height 40px --docsearch-footer-height 40px
......
...@@ -30,9 +30,7 @@ ...@@ -30,9 +30,7 @@
<div <div
class="links" class="links"
:style="linksWrapMaxWidth ? { :style="SearchBoxStyle"
'max-width': linksWrapMaxWidth + 'px'
} : {}"
> >
<!-- <a class="switch-version" href="javascript:void(0)">回到旧版</a> --> <!-- <a class="switch-version" href="javascript:void(0)">回到旧版</a> -->
<DcloudSearchPage v-if="isAlgoliaSearch" ref="dcloudSearchPage" :options="algolia"/> <DcloudSearchPage v-if="isAlgoliaSearch" ref="dcloudSearchPage" :options="algolia"/>
...@@ -42,6 +40,14 @@ ...@@ -42,6 +40,14 @@
</div> </div>
<div class="sub-navbar"> <div class="sub-navbar">
<DropdownLink
class="custom-main-navbar can-hide"
v-if="showSubNavBar && fixedNavbar"
:item="{
text: customNavBarKeys[navConfig.userNavIndex],
items: customNavBar
}"
/>
<NavLinks class="can-hide" /> <NavLinks class="can-hide" />
<div class="mobile-sub-navbar"> <div class="mobile-sub-navbar">
<div class="subnavbar__item" @click="$emit('toggle-sidebar')"> <div class="subnavbar__item" @click="$emit('toggle-sidebar')">
...@@ -61,6 +67,7 @@ import MainNavbarLink from './MainNavbarLink.vue'; ...@@ -61,6 +67,7 @@ import MainNavbarLink from './MainNavbarLink.vue';
import NavbarLogo from './NavbarLogo.vue'; import NavbarLogo from './NavbarLogo.vue';
import DcloudSearchPage from './DcloudSearchPage'; import DcloudSearchPage from './DcloudSearchPage';
import navInject from '../mixin/navInject'; import navInject from '../mixin/navInject';
import DropdownLink from '@theme/components/DropdownLink.vue'
import { forbidScroll, os } from '../util'; import { forbidScroll, os } from '../util';
export default { export default {
...@@ -75,14 +82,16 @@ export default { ...@@ -75,14 +82,16 @@ export default {
SearchBox, SearchBox,
AlgoliaSearchBox, AlgoliaSearchBox,
NavbarLogo, NavbarLogo,
DcloudSearchPage DcloudSearchPage,
DropdownLink
}, },
data () { data () {
return { return {
linksWrapMaxWidth: null, linksWrapMaxWidth: null,
showMobilePanel: false, showMobilePanel: false,
fixedNavbar: false fixedNavbar: false,
SearchBoxTop: 0
} }
}, },
...@@ -93,6 +102,18 @@ export default { ...@@ -93,6 +102,18 @@ export default {
isAlgoliaSearch () { isAlgoliaSearch () {
return this.algolia && this.algolia.apiKey && this.algolia.indexName return this.algolia && this.algolia.apiKey && this.algolia.indexName
},
SearchBoxStyle () {
const initStyle = {
top: `${this.SearchBoxTop}px`,
zIndex: 100
};
return this.linksWrapMaxWidth
? Object.assign({}, initStyle, {
'max-width': this.linksWrapMaxWidth + 'px',
})
: initStyle;
} }
}, },
...@@ -148,7 +169,7 @@ export default { ...@@ -148,7 +169,7 @@ export default {
this.vuepressToc && this.vuepressToc.removeAttribute('style') this.vuepressToc && this.vuepressToc.removeAttribute('style')
this.navbar && this.navbar.removeAttribute('style') this.navbar && this.navbar.removeAttribute('style')
if (this.pageContainer) { if (this.pageContainer) {
this.pageContainer.style.marginTop = this.showSubNavBar ? 'auto' : `${this.navbarHeight}px` this.pageContainer.style.marginTop = this.showSubNavBar || !os.pc ? 'auto' : `${this.navbarHeight}px`
} }
}, },
onWindowScroll () { onWindowScroll () {
...@@ -165,6 +186,7 @@ export default { ...@@ -165,6 +186,7 @@ export default {
if (!this.fixedNavbar) { if (!this.fixedNavbar) {
this.fixedNavbar = true this.fixedNavbar = true
this.navbar.style.top = `-${this.mainNavBarHeight}px` this.navbar.style.top = `-${this.mainNavBarHeight}px`
this.SearchBoxTop = this.mainNavBarHeight + (this.subNavBarHeight - this.mainNavBarHeight) / 2
this.$nextTick(() => { this.$nextTick(() => {
this.pageContainer && (this.pageContainer.style.marginTop = `${this.navbarHeight}px`) this.pageContainer && (this.pageContainer.style.marginTop = `${this.navbarHeight}px`)
}) })
...@@ -173,6 +195,7 @@ export default { ...@@ -173,6 +195,7 @@ export default {
if (this.fixedNavbar) { if (this.fixedNavbar) {
this.fixedNavbar = false this.fixedNavbar = false
this.pageContainer && (this.pageContainer.style.marginTop = 'auto') this.pageContainer && (this.pageContainer.style.marginTop = 'auto')
this.SearchBoxTop = 0
} }
} }
}, },
...@@ -264,6 +287,7 @@ $navbar-horizontal-padding = 1.5rem ...@@ -264,6 +287,7 @@ $navbar-horizontal-padding = 1.5rem
display none !important display none !important
.links .links
padding-left 0rem // 1.5rem padding-left 0rem // 1.5rem
top 0 !important
.site-name .site-name
width calc(100vw - 9.4rem) width calc(100vw - 9.4rem)
overflow hidden overflow hidden
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
export const navbar = [ export const navbar = [
{ {
text: 'uni-app', text: 'uni-app',
link: '/',
items: [ items: [
{ {
text: '介绍', text: '介绍',
......
...@@ -20,6 +20,7 @@ $navbar-logo-height = $navbar-main-navbar-height - 2rem ...@@ -20,6 +20,7 @@ $navbar-logo-height = $navbar-main-navbar-height - 2rem
& &
display none display none
.sub-navbar .sub-navbar
position relative
line-height $navbar-sub-navbar-height line-height $navbar-sub-navbar-height
border-top-width 1px border-top-width 1px
.mobile-main-navbar .mobile-main-navbar
...@@ -76,6 +77,20 @@ $navbar-logo-height = $navbar-main-navbar-height - 2rem ...@@ -76,6 +77,20 @@ $navbar-logo-height = $navbar-main-navbar-height - 2rem
color inherit color inherit
&:hover &:hover
color $accentColor color $accentColor
.custom-main-navbar
position absolute
height 30px
top calc(50% - 15px)
left 2rem
@media (max-width: 1200px)
display none
a
color inherit
.nav-dropdown
right auto
left 0
z-index 12
@media (max-width: $MQMobile) @media (max-width: $MQMobile)
$navbar-a-color = #222; $navbar-a-color = #222;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册