fix: 个人中心头像为空时不能修改

(cherry picked from commit e6a9dd0e4c)
This commit is contained in:
xingyu 2023-08-28 17:53:45 +08:00 committed by shizhong
parent a15d777afb
commit bdaeb75ccc
2 changed files with 19 additions and 21 deletions

View File

@ -1,6 +1,7 @@
<template>
<div class="user-info-head" @click="open()">
<img :src="sourceValue" class="img-circle img-lg" />
<img v-if="sourceValue" :src="sourceValue" alt="avatar" class="img-circle img-lg" />
<img v-if="!sourceValue" :src="avatar" alt="avatar" class="img-circle img-lg" />
<el-button v-if="showBtn" :class="`${prefixCls}-upload-btn`" @click="open()">
{{ btnText ? btnText : t('cropper.selectImage') }}
</el-button>
@ -17,6 +18,7 @@ import { useDesign } from '@/hooks/web/useDesign'
import { propTypes } from '@/utils/propTypes'
import { useI18n } from 'vue-i18n'
import CopperModal from './CopperModal.vue'
import avatar from '@/assets/imgs/avatar.jpg'
const props = defineProps({
width: propTypes.string.def('200px'),
@ -83,14 +85,14 @@ $prefix-cls: #{$namespace}--cropper-avatar;
}
&-image-mask {
opacity: 0%;
position: absolute;
width: inherit;
height: inherit;
border-radius: inherit;
border: inherit;
background: rgb(0 0 0 / 40%);
cursor: pointer;
background: rgb(0 0 0 / 40%);
border: inherit;
border-radius: inherit;
opacity: 0;
transition: opacity 0.4s;
::v-deep(svg) {
@ -99,7 +101,7 @@ $prefix-cls: #{$namespace}--cropper-avatar;
}
&-image-mask:hover {
opacity: 4000%;
opacity: 40;
}
&-upload-btn {
@ -121,21 +123,18 @@ $prefix-cls: #{$namespace}--cropper-avatar;
height: 120px;
}
.user-info-head:hover:after {
content: '+';
.user-info-head:hover::after {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
color: #eee;
background: rgba(0, 0, 0, 0.5);
inset: 0;
font-size: 24px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
cursor: pointer;
font-style: normal;
line-height: 110px;
color: #eee;
cursor: pointer;
background: rgb(0 0 0 / 50%);
border-radius: 50%;
content: '+';
}
</style>

View File

@ -4,7 +4,7 @@
ref="cropperRef"
:btnProps="{ preIcon: 'ant-design:cloud-upload-outlined' }"
:showBtn="false"
:value="avatar"
:value="img"
width="120px"
@change="handelUpload"
/>
@ -14,12 +14,11 @@
import { propTypes } from '@/utils/propTypes'
import { uploadAvatarApi } from '@/api/system/user/profile'
const props = defineProps({
defineOptions({ name: 'UserAvatar' })
defineProps({
img: propTypes.string.def('')
})
const avatar = computed(() => {
return props.img
})
const cropperRef = ref()
const handelUpload = async ({ data }) => {