Selaa lähdekoodia

优化修改头像在小屏幕上页面布局错位的问题

RuoYi 3 vuotta sitten
vanhempi
commit
c759728269

+ 3 - 2
ruoyi-ui/src/assets/styles/ruoyi.scss

@@ -250,9 +250,10 @@
250 250
 }
251 251
 
252 252
 .avatar-upload-preview {
253
-	position: absolute;
253
+	position: relative;
254 254
 	top: 50%;
255
-	transform: translate(50%, -50%);
255
+	left: 50%;
256
+	transform: translate(-50%, -50%);
256 257
 	width: 200px;
257 258
 	height: 200px;
258 259
 	border-radius: 50%;

+ 21 - 8
ruoyi-ui/src/views/system/user/profile/userAvatar.vue

@@ -24,7 +24,7 @@
24 24
       </el-row>
25 25
       <br />
26 26
       <el-row>
27
-        <el-col :lg="2" :md="2">
27
+        <el-col :lg="2" :sm="3" :xs="3">
28 28
           <el-upload action="#" :http-request="requestUpload" :show-file-list="false" :before-upload="beforeUpload">
29 29
             <el-button size="small">
30 30
               选择
@@ -32,19 +32,19 @@
32 32
             </el-button>
33 33
           </el-upload>
34 34
         </el-col>
35
-        <el-col :lg="{span: 1, offset: 2}" :md="2">
35
+        <el-col :lg="{span: 1, offset: 2}" :sm="2" :xs="2">
36 36
           <el-button icon="el-icon-plus" size="small" @click="changeScale(1)"></el-button>
37 37
         </el-col>
38
-        <el-col :lg="{span: 1, offset: 1}" :md="2">
38
+        <el-col :lg="{span: 1, offset: 1}" :sm="2" :xs="2">
39 39
           <el-button icon="el-icon-minus" size="small" @click="changeScale(-1)"></el-button>
40 40
         </el-col>
41
-        <el-col :lg="{span: 1, offset: 1}" :md="2">
41
+        <el-col :lg="{span: 1, offset: 1}" :sm="2" :xs="2">
42 42
           <el-button icon="el-icon-refresh-left" size="small" @click="rotateLeft()"></el-button>
43 43
         </el-col>
44
-        <el-col :lg="{span: 1, offset: 1}" :md="2">
44
+        <el-col :lg="{span: 1, offset: 1}" :sm="2" :xs="2">
45 45
           <el-button icon="el-icon-refresh-right" size="small" @click="rotateRight()"></el-button>
46 46
         </el-col>
47
-        <el-col :lg="{span: 2, offset: 6}" :md="2">
47
+        <el-col :lg="{span: 2, offset: 6}" :sm="2" :xs="2">
48 48
           <el-button type="primary" size="small" @click="uploadImg()">提 交</el-button>
49 49
         </el-col>
50 50
       </el-row>
@@ -56,6 +56,7 @@
56 56
 import store from "@/store";
57 57
 import { VueCropper } from "vue-cropper";
58 58
 import { uploadAvatar } from "@/api/system/user";
59
+import { debounce } from '@/utils'
59 60
 
60 61
 export default {
61 62
   components: { VueCropper },
@@ -79,7 +80,8 @@ export default {
79 80
         autoCropHeight: 200, // 默认生成截图框高度
80 81
         fixedBox: true // 固定截图框大小 不允许改变
81 82
       },
82
-      previews: {}
83
+      previews: {},
84
+      resizeHandler: null
83 85
     };
84 86
   },
85 87
   methods: {
@@ -90,6 +92,16 @@ export default {
90 92
     // 打开弹出层结束时的回调
91 93
     modalOpened() {
92 94
       this.visible = true;
95
+      if (!this.resizeHandler) {
96
+        this.resizeHandler = debounce(() => {
97
+          this.refresh()
98
+        }, 100)
99
+      }
100
+      window.addEventListener("resize", this.resizeHandler)
101
+    },
102
+    // 刷新组件
103
+    refresh() {
104
+      this.$refs.cropper.refresh();
93 105
     },
94 106
     // 覆盖默认的上传行为
95 107
     requestUpload() {
@@ -141,6 +153,7 @@ export default {
141 153
     closeDialog() {
142 154
       this.options.img = store.getters.avatar
143 155
       this.visible = false;
156
+      window.removeEventListener("resize", this.resizeHandler)
144 157
     }
145 158
   }
146 159
 };
@@ -169,4 +182,4 @@ export default {
169 182
   line-height: 110px;
170 183
   border-radius: 50%;
171 184
 }
172
-</style>
185
+</style>