Navbar.vue 4.64 KB
<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">
      <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click" @command="handleCommand">
        <div class="avatar-wrapper">
          <span style="padding-right:10px">{{ name }}</span>
          <img :src="avatar + '?imageView2/1/w/80/h/80'" class="user-avatar" />
        </div>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="a">个人中心</el-dropdown-item>
          <el-dropdown-item command="f">退出登录</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 { getSession } from '@/utils/session'
export default {
  components: {
    Breadcrumb,
    Hamburger
  },
  created () {
    // this.init();
  },
  computed: {
    ...mapGetters(['sidebar', 'avatar', 'name'])
  },
  methods: {
    // init () {
    //   let userInfo = getSession('userInfo');
    //   if (userInfo && userInfo.userValid === 0) {
    //     this.userValid = 0;
    //   }
    // },
    toggleSideBar () {
      this.$store.dispatch('app/toggleSideBar')
    },
    searchMessageCenter () {
      this.$router.push({ name: 'messagecenter' })
    },
    handleCommand (command) {
      if (command == 'a') {
        //个人中心
        this.$router.push({ name: 'personal' })
      } else if (command == 'f') {
        // 退出
        this.$store.dispatch('user/logout')
        this.$router.push(`/login?redirect=${this.$route.fullPath}`)
        window.sessionStorage.clear()
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.el-dropdown-menu {
  padding: 0 !important;
  border: 1px solid #EBEEF5;
  box-shadow: 0 2px 10px 0 rgba(0, 0, 0, 0.12);
  border-radius: 4px 0 0 4px 4px;

  .el-dropdown-menu__item {
    text-align: center;
    margin-top: 0 !important;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #4A4A4A;
    width: 140px;
    height: 36px;
    line-height: 36px;
  }

  .el-dropdown-menu__item:nth-child(6) {
    border-top: 1px solid #EBEEF5;
  }

  .popper__arrow {
    top: -11px !important;
    left: 110px !important;
    transform: rotate(0deg) scale(2);
  }

  .el-dropdown-menu__item:not(.is-disabled):hover,
  .el-dropdown-menu__item:focus {
    background: #F6F7F9;
    color: #4A4A4A;
  }
}

.navbar {
  height: 40px;
  overflow: hidden;
  position: relative;
  background: #fff;
  box-shadow: 0 1px 0px rgba(0, 21, 41, 0.08);

  .hamburger-container {
    line-height: 43px;
    height: 100%;
    float: left;
    cursor: pointer;
    transition: background 0.3s;
    -webkit-tap-highlight-color: transparent;

    &:hover {
      background: rgba(0, 0, 0, 0.025);
    }
  }

  .breadcrumb-container {
    float: left;
  }

  .right-menu {
    float: right;
    height: 100%;
    line-height: 50px;

    .organization-item {
      margin-right: 40px;
      margin-top: -40px !important;
    }

    .item {
      margin-right: 40px;
      margin-top: -20px;
      line-height: 18.4px;
      cursor: pointer;
      position: relative;

      .item-box {
        position: absolute;
        top: -5px;
        left: 3px;
        width: 100%;
        min-width: 25px;
        height: 25px;
        cursor: pointer;
        z-index: 100;
      }
    }

    &: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 0.3s;

        &:hover {
          background: rgba(0, 0, 0, 0.025);
        }
      }
    }

    .avatar-container {
      margin-right: 20px;

      .avatar-wrapper {
        position: relative;
        display: flex;
        height: 40px;
        align-items: center;

        .user-avatar {
          cursor: pointer;
          width: 35px;
          height: 35px;
          border-radius: 50%;
        }

        .el-icon-caret-bottom {
          cursor: pointer;
          position: absolute;
          right: -15px;
          top: 17px;
          font-size: 12px;
        }
      }
    }
  }

  /*2.隐藏滚动条,太丑了*/
  .el-drawer__container ::-webkit-scrollbar {
    display: none;

  }

  .el-form-item--small .el-form-item__label {
    width: 80px !important;
  }
}
</style>