<template>
  <div class="navbar">
    <hamburger :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" />

    <breadcrumb class="breadcrumb-container" />

    <div class="right-menu">
      <div class="xl-form" style="padding-right: 20px;">
        <span class="scoped-op" @click="cashUpdate">更新缓存</span>
        <span class="scoped-op2" @click="openPwdPopup">修改密码</span>
        <span class="scoped-user">{{sysUser.nickname}}</span>
        <el-button icon="el-icon-user" class="xl-form-btn t4 xs" @click="logout">退出</el-button>
      </div>
    </div>
    <pwd-edit
      :isShow="isPwdShow"
      @close="closePwdPopup"
    />
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import Breadcrumb from '@/components/Breadcrumb'
import Hamburger from '@/components/Hamburger'
import PwdEdit from '@/components/Common/PwdEdit'
export default {
  components: {
    Breadcrumb,
    Hamburger,
    PwdEdit,
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'sysUser',
      'sysUser',
      'notifyObj',
    ])
  },
  data () {
    return {
      isPwdShow: false,
    }
  },
  created () {
    // this.getNotify()
  },
  methods: {
    qaHandle () {
      this.$router.push('/qa/index')
    },
    getNotify () {
      this.$store.dispatch('user/getNotify')
    },
    closePwdPopup () {
      this.isPwdShow = false
    },
    openPwdPopup () {
      this.isPwdShow = true
    },
    cashUpdate () {
      this.$store.dispatch('user/getDict').then(() => {
        this.$store.dispatch('user/getMenu').then(() => {
          window.setTimeout(() => {
            this.$router.go(0)
          }, 100)
        })
      })
    },
    toggleSideBar() {
      this.$store.dispatch('app/toggleSideBar')
    },
    async logout() {
      this.$msg('退出登录？', 'confirm', () => {
        window.sessionStorage.clear()
        // window.localStorage.clear()
        this.$router.go(0)
      })
      // 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;
  }

  .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;
        }
      }
    }
  }
}

.scoped-user {
  display: inline-block;
  vertical-align: middle;
  color: #666;
  padding-right: 10px;
  font-weight: bold;
}
.scoped-op {
  display: inline-block;
  vertical-align: middle;
  font-weight: bold;
  color: #ffc107;
  padding-right: 20px;
  font-size: 14px;
  text-decoration: underline;
  cursor: pointer;
}
.scoped-op2 {
  display: inline-block;
  vertical-align: middle;
  font-weight: bold;
  color: #e94141;
  padding-right: 20px;
  font-size: 14px;
  text-decoration: underline;
  cursor: pointer;
}
.scoped-op3 {
  display: inline-block;
  vertical-align: middle;
  font-weight: bold;
  color: #19be6b;
  padding-right: 20px;
  font-size: 14px;
  cursor: pointer;
  animation: animate 0.5s linear infinite;
}
@keyframes animate {
  0%, 100% {
    text-shadow: -1.5px -1.5px 0 #0ff, 1.5px 1.5px 0 #f00;
  }
  25% {
    text-shadow: 1.5px 1.5px 0 #0ff, -1.5px -1.5px 0 #f00;
  }
  50% {
    text-shadow: 1.5px -1.5px 0 #0ff, 1.5px -1.5px 0 #f00;
  }
  75% {
    text-shadow: -1.5px 1.5px 0 #0ff, -1.5px 1.5px 0 #f00;
  }
} 
</style>
