Explorar el Código

修复头像上传成功二次打开无法改变裁剪框大小和位置问题

RuoYi hace 5 años
padre
commit
ad690bac17
Se han modificado 1 ficheros con 10 adiciones y 2 borrados
  1. 10 2
      ruoyi-ui/src/views/system/user/profile/userAvatar.vue

+ 10 - 2
ruoyi-ui/src/views/system/user/profile/userAvatar.vue

@@ -1,7 +1,7 @@
1 1
 <template>
2 2
   <div>
3 3
     <img v-bind:src="options.img" @click="editCropper()" title="点击上传头像" class="img-circle img-lg" />
4
-    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
4
+    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body @opened="modalOpened">
5 5
       <el-row>
6 6
         <el-col :xs="24" :md="12" :style="{height: '350px'}">
7 7
           <vue-cropper
@@ -13,6 +13,7 @@
13 13
             :autoCropHeight="options.autoCropHeight"
14 14
             :fixedBox="options.fixedBox"
15 15
             @realTime="realTime"
16
+            v-if="visible"
16 17
           />
17 18
         </el-col>
18 19
         <el-col :xs="24" :md="12" :style="{height: '350px'}">
@@ -67,6 +68,8 @@ export default {
67 68
     return {
68 69
       // 是否显示弹出层
69 70
       open: false,
71
+      // 是否显示cropper
72
+      visible: false,
70 73
       // 弹出层标题
71 74
       title: "修改头像",
72 75
       options: {
@@ -84,6 +87,10 @@ export default {
84 87
     editCropper() {
85 88
       this.open = true;
86 89
     },
90
+    // 打开弹出层结束时的回调
91
+    modalOpened() {
92
+      this.visible = true;
93
+    },
87 94
     // 覆盖默认的上传行为
88 95
     requestUpload() {
89 96
     },
@@ -121,9 +128,10 @@ export default {
121 128
           if (response.code === 200) {
122 129
             this.open = false;
123 130
             this.options.img = process.env.VUE_APP_BASE_API + response.imgUrl;
131
+            store.commit('SET_AVATAR', this.options.img);
124 132
             this.msgSuccess("修改成功");
125 133
           }
126
-          this.$refs.cropper.clearCrop();
134
+          this.visible = false;
127 135
         });
128 136
       });
129 137
     },