Navbar.vue 2.1 KB
Newer Older
Pan's avatar
Pan committed
1
<template>
Pan's avatar
Pan committed
2
  <el-menu class="navbar" mode="horizontal">
3 4
    <hamburger :toggle-click="toggleSideBar" :is-active="sidebar.opened" class="hamburger-container"/>
    <breadcrumb />
Pan's avatar
Pan committed
5 6
    <el-dropdown class="avatar-container" trigger="click">
      <div class="avatar-wrapper">
7 8
        <img :src="avatar+'?imageView2/1/w/80/h/80'" class="user-avatar">
        <i class="el-icon-caret-bottom"/>
Pan's avatar
Pan committed
9
      </div>
10
      <el-dropdown-menu slot="dropdown" class="user-dropdown">
Pan's avatar
Pan committed
11
        <router-link class="inlineBlock" to="/">
Pan's avatar
Pan committed
12 13 14 15
          <el-dropdown-item>
            Home
          </el-dropdown-item>
        </router-link>
Pan's avatar
Pan committed
16
        <el-dropdown-item divided>
17
          <span style="display:block;" @click="logout">LogOut</span>
Pan's avatar
Pan committed
18
        </el-dropdown-item>
Pan's avatar
Pan committed
19 20 21
      </el-dropdown-menu>
    </el-dropdown>
  </el-menu>
Pan's avatar
Pan committed
22 23 24
</template>

<script>
Pan's avatar
Pan committed
25
import { mapGetters } from 'vuex'
Pan's avatar
Pan committed
26
import Breadcrumb from '@/components/Breadcrumb'
Pan's avatar
Pan committed
27
import Hamburger from '@/components/Hamburger'
Pan's avatar
Pan committed
28

Pan's avatar
Pan committed
29 30
export default {
  components: {
Pan's avatar
Pan committed
31
    Breadcrumb,
Pan's avatar
Pan committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45
    Hamburger
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar'
    ])
  },
  methods: {
    toggleSideBar() {
      this.$store.dispatch('ToggleSideBar')
    },
    logout() {
      this.$store.dispatch('LogOut').then(() => {
Pan's avatar
Pan committed
46
        location.reload() // 为了重新实例化vue-router对象 避免bug
Pan's avatar
Pan committed
47
      })
Pan's avatar
Pan committed
48
    }
Pan's avatar
Pan committed
49 50
  }
}
Pan's avatar
Pan committed
51 52 53
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
Pan's avatar
Pan committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
.navbar {
  height: 50px;
  line-height: 50px;
  border-radius: 0px !important;
  .hamburger-container {
    line-height: 58px;
    height: 50px;
    float: left;
    padding: 0 10px;
  }
  .screenfull {
    position: absolute;
    right: 90px;
    top: 16px;
    color: red;
  }
  .avatar-container {
    height: 50px;
    display: inline-block;
    position: absolute;
    right: 35px;
    .avatar-wrapper {
      cursor: pointer;
      margin-top: 5px;
      position: relative;
      .user-avatar {
        width: 40px;
        height: 40px;
        border-radius: 10px;
      }
      .el-icon-caret-bottom {
        position: absolute;
        right: -20px;
        top: 25px;
        font-size: 12px;
      }
Pan's avatar
Pan committed
90
    }
Pan's avatar
Pan committed
91 92
  }
}
Pan's avatar
Pan committed
93 94
</style>