header改写

master
toesbieya 6 years ago
parent 64b538ab70
commit 8dedccbddf
  1. 62
      vue/src/layout/component/Header.vue

@ -1,16 +1,4 @@
<template> <script type="text/jsx">
<header
:class="{'header-container':true,'hide-header':hideHeader}"
@mouseenter="() => this.mouseOutside = false"
@mouseleave="() => this.mouseOutside = true"
>
<v-navbar @menu-show="e => this.navbarMenuShow = e"/>
<tags-view v-if="useTagsView" @menu-show="e => this.tagsViewMenuShow = e"/>
</header>
</template>
<script>
import {mapState} from 'vuex' import {mapState} from 'vuex'
import VNavbar from './Navbar' import VNavbar from './Navbar'
import TagsView from './TagsView' import TagsView from './TagsView'
@ -24,8 +12,7 @@ export default {
return { return {
mouseOutside: true, mouseOutside: true,
navbarMenuShow: false, navbarMenuShow: false,
tagsViewMenuShow: false, tagsViewMenuShow: false
appMain: null
} }
}, },
@ -56,11 +43,9 @@ export default {
moveEvent(e) { moveEvent(e) {
if (e.clientY <= 15) this.mouseOutside = false if (e.clientY <= 15) this.mouseOutside = false
}, },
addEvent() { addEvent() {
this.appMain.addEventListener('mousemove', this.moveEvent) this.appMain.addEventListener('mousemove', this.moveEvent)
}, },
removeEvent() { removeEvent() {
this.appMain.removeEventListener('mousemove', this.moveEvent) this.appMain.removeEventListener('mousemove', this.moveEvent)
} }
@ -71,29 +56,26 @@ export default {
if (this.headerAutoHidden) this.addEvent() if (this.headerAutoHidden) this.addEvent()
this.$once('hook:beforeDestroy', this.removeEvent) this.$once('hook:beforeDestroy', this.removeEvent)
} },
}
</script>
<style lang="scss">
@import "~@/asset/style/variables.scss";
.has-tags-view .header-container {
height: calc(#{$nav-height} + #{$tags-view-height});
}
.header-container {
position: relative;
height: $nav-height;
transition: height .3s ease-in-out;
flex-shrink: 0;
&.hide-header {
height: 0;
> .navbar { render() {
height: 0; const mouseCtrlFactory = (enter = true) => () => this.mouseOutside = !enter
} const menuCtrlFactory = key => e => this[key] = e
return (
<el-collapse-transition>
<header
v-show={!this.hideHeader}
class="header-container"
on-mouseenter={mouseCtrlFactory()}
on-mouseleave={mouseCtrlFactory(false)}
>
<v-navbar on-menu-show={menuCtrlFactory('navbarMenuShow')}/>
{this.useTagsView && <tags-view on-menu-show={menuCtrlFactory('tagsViewMenuShow')}/>}
</header>
</el-collapse-transition>
)
} }
} }
</style> </script>

Loading…
Cancel
Save