| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <template>
- <div class="change-avatar">
- <CropperAvatar
- ref="cropperRef"
- :btnProps="{ preIcon: 'ant-design:cloud-upload-outlined' }"
- :showBtn="false"
- :value="convertImageUrl(img)"
- width="120px"
- @change="handelUpload"
- />
- </div>
- </template>
- <script lang="ts" setup>
- import { propTypes } from '@/utils/propTypes'
- import { uploadAvatar } from '@/api/system/user/profile'
- import { CropperAvatar } from '@/components/Cropper'
- import { useUserStore } from '@/store/modules/user'
- import { convertImageUrl } from '@/utils/image-helper'
- const { t } = useI18n()
- defineOptions({ name: 'UserAvatar' })
- defineProps({
- img: propTypes.string.def('')
- })
- const userStore = useUserStore()
- const cropperRef = ref()
- const handelUpload = async ({ data }) => {
- const res = await uploadAvatar({ avatarFile: data })
- cropperRef.value.close()
- userStore.setUserAvatarAction(res.data)
- }
- </script>
- <style lang="scss" scoped>
- .change-avatar {
- img {
- display: block;
- margin-bottom: 15px;
- border-radius: 50%;
- }
- }
- </style>
|