<template>
    <div class="user-avator-dropdown">
        <Dropdown @on-click="handleClick">
          <!--  <Avatar :src="userAvator"/> -->
            <span style="color: #444; ">{{username}}-[退出]</span>
            <i class="el-icon-setting"></i>

            <DropdownMenu slot="list">
                 <!-- <DropdownItem name="usercenter">个人信息</DropdownItem>
                <DropdownItem name="changePwd">修改密码</DropdownItem> -->
                <DropdownItem name="logout">退出登录</DropdownItem>
            </DropdownMenu>
        </Dropdown>
    </div>
</template>

<script>
import './user.less'
import { logout } from '@/api/user'
import store from 'store'
import { disconnectSocket } from '@/libs/socket'
export default {
  name: 'user',
  props: {
    userAvator: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      username: ''
    }
  },
  created () {
    this.username = store.get('userinfo').username
  },
  methods: {
    handleClick (name) {
      switch (name) {
        case 'logout':
          logout({}).then(() => {
            // 断开WebSocket连接
            disconnectSocket()
            this.$store.commit('logout')
            location.reload()
          })
          break
        case 'changePwd':
          this.$router({
            name: 'changePassword'
          })
          break
        case 'usercenter':
          this.$router({
            name: 'own'
          })
          break
      }
    }
  }
}
</script>
