<template>
  <div class="home-header">
    <page-tags />
    <div class="user-area">
      <span class="user-name">{{ userInfo && userInfo.userName }}</span>
      <el-button type="text" @click="logout"
        >退出登录</el-button
      >
    </div>
  </div>
</template>
<script>
import pageTags from './pageTags.vue'
import { logout } from '@/common/api/login'
import { setToken, setUser } from '@/utils/auth'
import { mapState } from 'vuex'

export default {
  components: { pageTags },
  name: 'HomeHeader',
  computed: {
    ...mapState(['userInfo']),
  },
  methods: {
    async logout() {
      try {
        await logout()
      } catch (e) {
        console.error(e)
      }

      setUser(null)
      setToken('')
      this.$router.push('/login')
    },
  },
}
</script>
<style lang="scss" scoped>
.home-header {
  display: flex;
  overflow: hidden;
}

.page-tags {
  flex: 1;
  overflow: auto hidden;
}

.user-area {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  padding-right: 16px;

  .user-name {
    margin-right: 10px;
  }
}
</style>
