<template>
  <div class="navbar">
    <div class="right-menu" v-if="$store.state.settings.sidebarLogo">
      <el-dropdown
        class="avatar-container"
        trigger="click"
        placement="top-start"
      >
        <div class="avatar-wrapper">
          <el-avatar :size="size" :src="circleUrl" class="user-avatar" />
          <!--          <i class="el-icon-caret-bottom" />-->
        </div>
        <el-dropdown-menu slot="dropdown" class="user-dropdown">
          <router-link to="/">
            <el-dropdown-item>
              首页
            </el-dropdown-item>
          </router-link>
          <el-dropdown-item divided>
            <span style="display:block;" @click="resetPassword">修改密码</span>
          </el-dropdown-item>
          <el-dropdown-item divided>
            <span style="display:block;" @click="logout">退出</span>
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
    <reset-password-dialog
      :visible.sync="resetPasswordVisible"
    ></reset-password-dialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import url from '@/assets/images/active.png'
import ResetPasswordDialog from '@/views/system/user/components/ResetPasswordDialog.vue'

export default {
  components: { ResetPasswordDialog },
  data() {
    return {
      circleUrl: url,
      size: 40,
      resetPasswordVisible: false
    }
  },
  computed: {
    ...mapGetters(['sidebar', 'avatar'])
  },
  methods: {
    toggleSideBar() {
      this.$store.dispatch('app/toggleSideBar')
    },
    async logout() {
      this.$messageBox(
        async () => {
          await this.$store.dispatch('user/logout')
          await this.$store.dispatch('user/removeRoles')
          this.$router.push(`/login?redirect=${this.$route.fullPath}`)
        },
        '确定要退出吗?',
        'warning',
        '提示'
      )

      // this.$confirm({
      //   confirmButtonText: '确定',
      //   cancelButtonText: '取消',
      //   type: 'warning'
      // }).then(async () => {
      //
      // })
    },
    resetPassword() {
      this.resetPasswordVisible = true
    }
  }
}
</script>

<style lang="scss" scoped>
.navbar {
  height: 50px;
  overflow: hidden;
  position: relative;

  .hamburger-container {
    line-height: 46px;
    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;

    &: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: 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;
        }
      }
    }
  }
}
.el-avatar {
  background: none;
}
.el-dropdown-menu__item {
  &:hover {
    color: var(--color-primary);
    background: none;
  }
}
</style>
