UserAvatar.vue 844 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <template>
  2. <div class="change-avatar">
  3. <CropperAvatar
  4. ref="cropperRef"
  5. :btnProps="{ preIcon: 'ant-design:cloud-upload-outlined' }"
  6. :showBtn="false"
  7. :value="avatar"
  8. width="120px"
  9. @change="handelUpload"
  10. />
  11. </div>
  12. </template>
  13. <script lang="ts" setup>
  14. import { propTypes } from '@/utils/propTypes'
  15. import { uploadAvatar } from '@/api/system/user/profile'
  16. defineOptions({ name: 'UserAvatar' })
  17. const props = defineProps({
  18. img: propTypes.string.def('')
  19. })
  20. const avatar = computed(() => {
  21. return props.img
  22. })
  23. const cropperRef = ref()
  24. const handelUpload = async ({ data }) => {
  25. await uploadAvatar({ avatarFile: data })
  26. cropperRef.value.close()
  27. }
  28. </script>
  29. <style lang="scss" scoped>
  30. .change-avatar {
  31. img {
  32. display: block;
  33. margin-bottom: 15px;
  34. border-radius: 50%;
  35. }
  36. }
  37. </style>