<script setup>
import { useUserStore } from '@/store/user'

const props = defineProps({
  size: {
    type: Number,
    default: 40
  },
  bgColor: {
    type: String,
    default: '#96CCF6'
  }
})

const emit = defineEmits(['tap'])
const userStore = useUserStore()
const { getUserInfo } = storeToRefs(userStore)
const userInfo = computed(() => getUserInfo.value)
// 取昵称的第一个字
const nickName = computed(() => {
  if (userInfo.value.nickName) {
    return userInfo.value.nickName[0]
  }
  return ''
})
const handle = () => {
  emit('tap')
}
</script>

<template>
  <up-avatar
    :src="userInfo.avatar"
    :text="userInfo.avatar ? '' : nickName"
    :size="size"
    :bg-color="bgColor"
    @tap="handle"
  />
</template>
