<template>
  <div id="navBar">
    <el-menu class="navbar" mode="horizontal">
      <div class="user-profile-container">
        <div class="user-profile-content">
          <!-- <div class="menu-icons">
          <span class="menu-icon"><i class="el-icon-search icon"></i></span>
          <span class="menu-icon"><i class="el-icon-message icon"></i></span>
          <span class="menu-icon">
            <el-badge is-dot class="item">
              <i class="el-icon-bell icon"></i>
            </el-badge>
          </span>
        </div> -->
          <el-dropdown>
            <div class="user-profile-body">
              <img class="user-avatar" src="https://img.alicdn.com/tfs/TB1ONhloamWBuNjy1XaXXXCbXXa-200-200.png" />
              <span class="user-name" v-if="user && user.id">欢迎,{{ (user && user.user_name) || '' }}</span>
              <span class="user-name" v-else @click="$router.push({ path: '/admin' })">请登录</span>
            </div>
            <el-dropdown-menu class="user-dropdown" slot="dropdown">
              <!-- <router-link to="/updatePw" v-if="user && user.id">
              <el-dropdown-item>
                修改密码
              </el-dropdown-item>
            </router-link> -->
              <el-dropdown-item v-if="user && user.id">
                <span @click="toLogout()" style="display:block;">退出</span>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </div>
    </el-menu>
  </div>
</template>

<script>
export default {
  name: 'navBar',
  props: {},
  components: {},
  data: () => ({
    user: {},
  }),
  created() {},
  computed: {},
  methods: {
    async toLogout() {
      this.$router.push({ path: '/admin' });
    },
  },
};
</script>

<style lang="less" scoped>
.navbar {
  height: 4rem;
  box-shadow: 0 0.0625rem 0.25rem rgba(0, 21, 41, 0.08);
  .user-profile-container {
    position: absolute;
    right: 1.25rem;
    cursor: pointer;
    .user-profile-content {
      display: flex;
      padding: 1.25rem 0;
    }
    .menu-icons {
      display: flex;
      align-items: center;
      .menu-icon {
        padding: 0 0.75rem;
        .icon {
          display: inline-block;
          font-size: 1.125rem;
          text-align: center;
        }
      }
    }
    .user-profile-body {
      position: relative;
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: center;
      text-align: center;
      padding-right: 0.875rem;
    }
    .user-avatar {
      width: 1.5rem;
      height: 1.5rem;
      margin: 0 0.5rem 0 0.75rem;
      border-radius: 0.25rem;
    }
    .user-name {
      color: rgba(0, 0, 0, 0.65);
    }
    .user-department {
      font-size: 0.75rem;
      color: rgba(102, 102, 102, 0.65);
    }
    .el-icon-caret-bottom {
      position: absolute;
      right: 0;
      top: 0.8125rem;
      font-size: 0.75rem;
    }
  }
}
</style>
