优化头像上传参数新增文件名称

This commit is contained in:
RuoYi 2023-11-29 12:41:04 +08:00
parent 72e4cd9fb3
commit 42bb8f6445

View File

@ -70,12 +70,13 @@ export default {
// //
title: "修改头像", title: "修改头像",
options: { options: {
img: store.getters.avatar, // img: store.getters.avatar, //
autoCrop: true, // autoCrop: true, //
autoCropWidth: 200, // autoCropWidth: 200, //
autoCropHeight: 200, // autoCropHeight: 200, //
fixedBox: true, // fixedBox: true, //
outputType:"png" // PNG outputType:"png", // PNG
filename: 'avatar' //
}, },
previews: {}, previews: {},
resizeHandler: null resizeHandler: null
@ -125,6 +126,7 @@ export default {
reader.readAsDataURL(file); reader.readAsDataURL(file);
reader.onload = () => { reader.onload = () => {
this.options.img = reader.result; this.options.img = reader.result;
this.options.filename = file.name;
}; };
} }
}, },
@ -132,7 +134,7 @@ export default {
uploadImg() { uploadImg() {
this.$refs.cropper.getCropBlob(data => { this.$refs.cropper.getCropBlob(data => {
let formData = new FormData(); let formData = new FormData();
formData.append("avatarfile", data); formData.append("avatarfile", data, this.options.filename);
uploadAvatar(formData).then(response => { uploadAvatar(formData).then(response => {
this.open = false; this.open = false;
this.options.img = process.env.VUE_APP_BASE_API + response.imgUrl; this.options.img = process.env.VUE_APP_BASE_API + response.imgUrl;