fix 修复头像上传成功/取消后无法清空图片的问题
This commit is contained in:
@@ -4,16 +4,12 @@
|
|||||||
<h4 class="h4">我的信息</h4>
|
<h4 class="h4">我的信息</h4>
|
||||||
<div class="yo-avatar-info">
|
<div class="yo-avatar-info">
|
||||||
<yo-image :id="form.avatar" :size="128" icon="user" type="avatar" />
|
<yo-image :id="form.avatar" :size="128" icon="user" type="avatar" />
|
||||||
<div @click="avatar.cropper = true" class="yo-avatar-info--cover">
|
<div @click="onAvatarStart" class="yo-avatar-info--cover">
|
||||||
<a-icon type="cloud-upload-o" />
|
<a-icon type="cloud-upload-o" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<br />
|
<br />
|
||||||
<a-card :key="avatar.key" v-if="avatar.cropper">
|
<a-card v-if="avatar.cropper">
|
||||||
<a-alert type="error">
|
|
||||||
<template slot="message">上传完成时无法被销毁</template>
|
|
||||||
</a-alert>
|
|
||||||
<br />
|
|
||||||
<a-row :gutter="16" align="middle" type="flex">
|
<a-row :gutter="16" align="middle" type="flex">
|
||||||
<a-col :span="12">
|
<a-col :span="12">
|
||||||
<div class="yo-avatar-cropper">
|
<div class="yo-avatar-cropper">
|
||||||
@@ -56,7 +52,7 @@
|
|||||||
icon="check"
|
icon="check"
|
||||||
type="primary"
|
type="primary"
|
||||||
>确认</a-button>
|
>确认</a-button>
|
||||||
<a-button @click="avatar.cropper = false" icon="close">取消</a-button>
|
<a-button @click="onAvatarCancel" icon="close">取消</a-button>
|
||||||
</a-col>
|
</a-col>
|
||||||
</a-row>
|
</a-row>
|
||||||
</a-card>
|
</a-card>
|
||||||
@@ -172,7 +168,6 @@ export default {
|
|||||||
form: {},
|
form: {},
|
||||||
|
|
||||||
avatar: {
|
avatar: {
|
||||||
key: Date.now(),
|
|
||||||
cropper: false,
|
cropper: false,
|
||||||
img: '',
|
img: '',
|
||||||
autoWidth: 200,
|
autoWidth: 200,
|
||||||
@@ -223,6 +218,10 @@ export default {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onAvatarStart() {
|
||||||
|
this.avatar.cropper = true;
|
||||||
|
},
|
||||||
|
|
||||||
onAvatarOk() {
|
onAvatarOk() {
|
||||||
this.avatar.uploading = true;
|
this.avatar.uploading = true;
|
||||||
this.$refs.cropper.getCropBlob(async (data) => {
|
this.$refs.cropper.getCropBlob(async (data) => {
|
||||||
@@ -233,17 +232,35 @@ export default {
|
|||||||
const { data: fileId } = await this.$api.sysFileInfoUpload(fd);
|
const { data: fileId } = await this.$api.sysFileInfoUpload(fd);
|
||||||
this.form.avatar = fileId;
|
this.form.avatar = fileId;
|
||||||
|
|
||||||
this.avatar.cropper = false;
|
this.onAvatarCancel();
|
||||||
} finally {
|
} finally {
|
||||||
this.avatar.uploading = false;
|
this.avatar.uploading = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onAvatarCancel() {
|
||||||
|
this.avatar = {
|
||||||
|
...this.avatar,
|
||||||
|
...{
|
||||||
|
cropper: false,
|
||||||
|
img: '',
|
||||||
|
preview: {},
|
||||||
|
file: null,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
async onSaveInfo() {
|
async onSaveInfo() {
|
||||||
this.saving = true;
|
this.saving = true;
|
||||||
try {
|
try {
|
||||||
await this.$api.sysUserUpdateInfo(this.form);
|
await this.$api.sysUserUpdateInfo({
|
||||||
|
avatar: this.form.avatar,
|
||||||
|
nickName: this.form.nickName,
|
||||||
|
birthday: this.form.birthday,
|
||||||
|
sex: this.form.sex,
|
||||||
|
tel: this.form.tel,
|
||||||
|
});
|
||||||
await this.onRefreshInfo();
|
await this.onRefreshInfo();
|
||||||
this.$message.success('更新个人信息成功');
|
this.$message.success('更新个人信息成功');
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user