UserAvatar.vue 899 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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 { computed, ref } from 'vue'
  15. import { propTypes } from '@/utils/propTypes'
  16. import { CropperAvatar } from '@/components/Cropper'
  17. import { uploadAvatarApi } from '@/api/system/user/profile'
  18. const props = defineProps({
  19. img: propTypes.string.def('')
  20. })
  21. const avatar = computed(() => {
  22. return props.img
  23. })
  24. const cropperRef = ref()
  25. const handelUpload = async ({ data }) => {
  26. await uploadAvatarApi({ avatarFile: data })
  27. cropperRef.value.close()
  28. }
  29. </script>
  30. <style scoped lang="scss">
  31. .change-avatar {
  32. img {
  33. display: block;
  34. margin-bottom: 15px;
  35. border-radius: 50%;
  36. }
  37. }
  38. </style>