UserAvatar.vue 804 B

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