UserAvatar.vue 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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="convertImageUrl(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. import { useUserStore } from '@/store/modules/user'
  18. import { convertImageUrl } from '@/utils/image-helper'
  19. const { t } = useI18n()
  20. defineOptions({ name: 'UserAvatar' })
  21. defineProps({
  22. img: propTypes.string.def('')
  23. })
  24. const userStore = useUserStore()
  25. const cropperRef = ref()
  26. const handelUpload = async ({ data }) => {
  27. const res = await uploadAvatar({ avatarFile: data })
  28. cropperRef.value.close()
  29. userStore.setUserAvatarAction(res.data)
  30. }
  31. </script>
  32. <style lang="scss" scoped>
  33. .change-avatar {
  34. img {
  35. display: block;
  36. margin-bottom: 15px;
  37. border-radius: 50%;
  38. }
  39. }
  40. </style>