2023-02-11 00:44:00 +08:00
|
|
|
<template>
|
|
|
|
<div class="change-avatar">
|
|
|
|
<CropperAvatar
|
|
|
|
ref="cropperRef"
|
|
|
|
:btnProps="{ preIcon: 'ant-design:cloud-upload-outlined' }"
|
2023-04-14 21:32:11 +08:00
|
|
|
:showBtn="false"
|
|
|
|
:value="avatar"
|
2023-02-11 00:44:00 +08:00
|
|
|
width="120px"
|
2023-04-14 21:32:11 +08:00
|
|
|
@change="handelUpload"
|
2023-02-11 00:44:00 +08:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</template>
|
2023-06-21 19:14:34 +08:00
|
|
|
<script lang="ts" setup>
|
2023-02-11 00:44:00 +08:00
|
|
|
import { propTypes } from '@/utils/propTypes'
|
2023-04-05 20:13:35 +08:00
|
|
|
import { uploadAvatar } from '@/api/system/user/profile'
|
2023-04-14 21:32:11 +08:00
|
|
|
|
2023-06-21 19:14:34 +08:00
|
|
|
defineOptions({ name: 'UserAvatar' })
|
|
|
|
|
2023-02-11 00:44:00 +08:00
|
|
|
const props = defineProps({
|
|
|
|
img: propTypes.string.def('')
|
|
|
|
})
|
|
|
|
const avatar = computed(() => {
|
|
|
|
return props.img
|
|
|
|
})
|
|
|
|
|
|
|
|
const cropperRef = ref()
|
|
|
|
const handelUpload = async ({ data }) => {
|
2023-04-05 20:13:35 +08:00
|
|
|
await uploadAvatar({ avatarFile: data })
|
2023-02-11 00:44:00 +08:00
|
|
|
cropperRef.value.close()
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2023-04-14 21:32:11 +08:00
|
|
|
<style lang="scss" scoped>
|
2023-02-11 00:44:00 +08:00
|
|
|
.change-avatar {
|
|
|
|
img {
|
|
|
|
display: block;
|
|
|
|
margin-bottom: 15px;
|
|
|
|
border-radius: 50%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|