<template>
<!-- 面包屑导航栏 -->
<div class="navbar">
<!-- 点击切换侧边栏 -->
<hamburger id="hamburger-container" :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" />
<!-- 导航栏 -->
<breadcrumb id="breadcrumb-container" class="breadcrumb-container" />
<!-- 右侧菜单 -->
<div class="right-menu">
<template v-if="device!=='mobile'">
<!-- 搜索 -->
<search id="header-search" class="right-menu-item" />
<!-- 错误日志 -->
<error-log class="errLog-container right-menu-item hover-effect" />
<!-- 全屏显示 -->
<screenfull id="screenfull" class="right-menu-item hover-effect" />
<!-- 尺寸选择 -->
<el-tooltip content="Global Size" effect="dark" placement="bottom">
<size-select id="size-select" class="right-menu-item hover-effect" />
</el-tooltip>
</template>
<!-- 右侧头像下拉菜单 -->
<el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
<!-- 头像 -->
<div class="avatar-wrapper">
<img :src="avatar+'?imageView2/1/w/80/h/80'" class="user-avatar">
<i class="el-icon-caret-bottom" />
</div>
<!-- 菜单列表 -->
<el-dropdown-menu slot="dropdown">
<!-- 进入概要页面 -->
<router-link to="/profile/index">
<el-dropdown-item>Profile</el-dropdown-item>
</router-link>
<!-- 进入主页 -->
<router-link to="/">
<el-dropdown-item>Dashboard</el-dropdown-item>
</router-link>
<!-- 项目地址 -->
<a target="_blank" href="https://github.com/PanJiaChen/vue-element-admin/">
<el-dropdown-item>Github</el-dropdown-item>
</a>
<!-- 文档地址 -->
<a target="_blank" href="https://panjiachen.github.io/vue-element-admin-site/#/">
<el-dropdown-item>Docs</el-dropdown-item>
</a>
<!-- 退出登录 -->
<el-dropdown-item divided @click.native="logout">
<span style="display:block;">Log Out</span>
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
import Breadcrumb from '@/components/Breadcrumb' // 导航栏组件
import Hamburger from '@/components/Hamburger' // 汉堡包
import ErrorLog from '@/components/ErrorLog' // 错误日志组件
import Screenfull from '@/components/Screenfull' // 全屏显示组件
import SizeSelect from '@/components/SizeSelect' // 尺寸选择组件
import Search from '@/components/HeaderSearch' // 搜索组件
export default {
components: {
Breadcrumb,
Hamburger,
ErrorLog,
Screenfull,
SizeSelect,
Search
},
computed: {
...mapGetters([
'sidebar',
'avatar',
'device'
])
},
methods: {
// 切换侧边栏
toggleSideBar() {
this.$store.dispatch('app/toggleSideBar')
},
// 退出
async logout() {
await this.$store.dispatch('user/logout')
this.$router.push(`/login?redirect=${this.$route.fullPath}`)
}
}
}
</script>
<style lang="scss" scoped>
.navbar {
height: 50px;
overflow: hidden;
position: relative;
background: #fff;
box-shadow: 0 1px 4px rgba(0,21,41,.08);
.hamburger-container {
line-height: 46px;
height: 100%;
float: left;
cursor: pointer;
transition: background .3s;
-webkit-tap-highlight-color:transparent;
&:hover {
background: rgba(0, 0, 0, .025)
}
}
.breadcrumb-container {
float: left;
}
.errLog-container {
display: inline-block;
vertical-align: top;
}
.right-menu {
float: right;
height: 100%;
line-height: 50px;
&:focus {
outline: none;
}
.right-menu-item {
display: inline-block;
padding: 0 8px;
height: 100%;
font-size: 18px;
color: #5a5e66;
vertical-align: text-bottom;
&.hover-effect {
cursor: pointer;
transition: background .3s;
&:hover {
background: rgba(0, 0, 0, .025)
}
}
}
.avatar-container {
margin-right: 30px;
.avatar-wrapper {
margin-top: 5px;
position: relative;
.user-avatar {
cursor: pointer;
width: 40px;
height: 40px;
border-radius: 10px;
}
.el-icon-caret-bottom {
cursor: pointer;
position: absolute;
right: -20px;
top: 25px;
font-size: 12px;
}
}
}
}
}
</style>