UserAvatar.vue 826 B

123456789101112131415161718192021222324252627282930313233343536373839
  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="img"
  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. import { CropperAvatar } from '@/components/Cropper'
  17. defineOptions({ name: 'UserAvatar' })
  18. defineProps({
  19. img: propTypes.string.def('')
  20. })
  21. const cropperRef = ref()
  22. const handelUpload = async ({ data }) => {
  23. await uploadAvatar({ avatarFile: data })
  24. cropperRef.value.close()
  25. }
  26. </script>
  27. <style lang="scss" scoped>
  28. .change-avatar {
  29. img {
  30. display: block;
  31. margin-bottom: 15px;
  32. border-radius: 50%;
  33. }
  34. }
  35. </style>