<template>
  <div class="head-index">
    <img class="logo" :src="iconUrl"/>{{$store.state.userName}}
    <div class="fl-r">
      <el-button round size="mini" @click="logOut">退出登录</el-button>
    </div>
  </div>
</template>
<script>
  import {logoutApi} from "../../service/api";
  import iconUrl from '../../assets/logos.png'
  import cookie from '../../util/cookie'
  export default {
    name: "headIndex",
    data(){
      return {
        iconUrl:iconUrl
      }
    },
    methods:{
      logOut(){
        this.$confirm('确定退出系统?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          logoutApi().then(()=>{
            cookie.delete('cc_token');
            this.$store.dispatch('setToken','');
            this.$store.dispatch('setUserName','');
            this.$router.push({name:'login'})
          })
        }).catch(() => {

        });
      }
    }
  }
</script>

<style scoped lang="less">
  @import "../../util/public";
  .head-index{
    height: 100%;
    line-height: 60px;
    .logo{
      height: 50px;
      vertical-align: middle;
      margin-right: 20px;
      position: relative;
      top: -5px;
    }
  }
  .btn-div{
    text-align: center;
  }
</style>
