<template>
  <div class="head-index">
    {{$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 cookie from '../../util/cookie'
  export default {
    name: "headIndex",
    data(){
      return {

      }
    },
    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: 40px;
  }
  .btn-div{
    text-align: center;
  }
</style>
