Browse Source

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

RuoYi 2 years ago
parent
commit
0037e65ca0
1 changed files with 9 additions and 7 deletions
  1. 9 7
      ruoyi-ui/src/views/system/user/profile/userAvatar.vue

+ 9 - 7
ruoyi-ui/src/views/system/user/profile/userAvatar.vue

@@ -70,12 +70,13 @@ export default {
70
       // 弹出层标题
70
       // 弹出层标题
71
       title: "修改头像",
71
       title: "修改头像",
72
       options: {
72
       options: {
73
-        img: store.getters.avatar, //裁剪图片的地址
74
-        autoCrop: true, // 是否默认生成截图框
75
-        autoCropWidth: 200, // 默认生成截图框宽度
76
-        autoCropHeight: 200, // 默认生成截图框高度
77
-        fixedBox: true, // 固定截图框大小 不允许改变
78
-        outputType:"png" // 默认生成截图为PNG格式
73
+        img: store.getters.avatar,  //裁剪图片的地址
74
+        autoCrop: true,             // 是否默认生成截图框
75
+        autoCropWidth: 200,         // 默认生成截图框宽度
76
+        autoCropHeight: 200,        // 默认生成截图框高度
77
+        fixedBox: true,             // 固定截图框大小 不允许改变
78
+        outputType:"png",           // 默认生成截图为PNG格式
79
+        filename: 'avatar'          // 文件名称
79
       },
80
       },
80
       previews: {},
81
       previews: {},
81
       resizeHandler: null
82
       resizeHandler: null
@@ -125,6 +126,7 @@ export default {
125
         reader.readAsDataURL(file);
126
         reader.readAsDataURL(file);
126
         reader.onload = () => {
127
         reader.onload = () => {
127
           this.options.img = reader.result;
128
           this.options.img = reader.result;
129
+          this.options.filename = file.name;
128
         };
130
         };
129
       }
131
       }
130
     },
132
     },
@@ -132,7 +134,7 @@ export default {
132
     uploadImg() {
134
     uploadImg() {
133
       this.$refs.cropper.getCropBlob(data => {
135
       this.$refs.cropper.getCropBlob(data => {
134
         let formData = new FormData();
136
         let formData = new FormData();
135
-        formData.append("avatarfile", data);
137
+        formData.append("avatarfile", data, this.options.filename);
136
         uploadAvatar(formData).then(response => {
138
         uploadAvatar(formData).then(response => {
137
           this.open = false;
139
           this.open = false;
138
           this.options.img = process.env.VUE_APP_BASE_API + response.imgUrl;
140
           this.options.img = process.env.VUE_APP_BASE_API + response.imgUrl;