24
24
:color =" closeIconColor"
25
25
:size =" closeIconSize"
26
26
></u-icon >
27
- <slot />
27
+ <scroll-view class =" u-drawer__scroll-view" scroll-y =" true" >
28
+ <slot />
29
+ </scroll-view >
28
30
</view >
29
- <block v-else ><slot /></block >
31
+ <scroll-view class =" u-drawer__scroll-view" scroll-y =" true" v-else >
32
+ <slot />
33
+ </scroll-view >
30
34
<view class =" u-close" :class =" ['u-close--' + closeIconPos]" >
31
35
<u-icon
32
36
v-if =" mode != 'center' && closeable"
@@ -158,6 +162,18 @@ export default {
158
162
closeIconSize: {
159
163
type: [String , Number ],
160
164
default: ' 30'
165
+ },
166
+ // 宽度,只对左,右,中部弹出时起作用,单位rpx,或者"auto"
167
+ // 或者百分比"50%",表示由内容撑开高度或者宽度,优先级高于length参数
168
+ width: {
169
+ type: String ,
170
+ default: ' '
171
+ },
172
+ // 高度,只对上,下,中部弹出时起作用,单位rpx,或者"auto"
173
+ // 或者百分比"50%",表示由内容撑开高度或者宽度,优先级高于length参数
174
+ height: {
175
+ type: String ,
176
+ default: ' '
161
177
}
162
178
},
163
179
data () {
@@ -172,20 +188,17 @@ export default {
172
188
// 根据mode的位置,设定其弹窗的宽度(mode = left|right),或者高度(mode = top|bottom)
173
189
style () {
174
190
let style = {};
175
- let translate = ' 100%' ;
176
- // 判断是否是否百分比或者auto值,是的话,直接使用该值,否则默认为rpx单位的数值
177
- let length = / %$ / .test (this .length ) || this .length == ' auto' ? this .length : uni .upx2px (this .length ) + ' px' ;
178
191
// 如果是左边或者上边弹出时,需要给translate设置为负值,用于隐藏
179
192
if (this .mode == ' left' || this .mode == ' right' ) {
180
193
style = {
181
- width: length,
194
+ width: this . width ? this . getUnitValue ( this . width ) : this . getUnitValue ( this . length ) ,
182
195
height: ' 100%' ,
183
196
transform: ` translate3D(${ this .mode == ' left' ? ' -100%' : ' 100%' } ,0px,0px)`
184
197
};
185
198
} else if (this .mode == ' top' || this .mode == ' bottom' ) {
186
199
style = {
187
200
width: ' 100%' ,
188
- height: length,
201
+ height: this . height ? this . getUnitValue ( this . height ) : this . getUnitValue ( this . length ) ,
189
202
transform: ` translate3D(0px,${ this .mode == ' top' ? ' -100%' : ' 100%' } ,0px)`
190
203
};
191
204
}
@@ -215,16 +228,17 @@ export default {
215
228
// 中部弹窗的特有样式
216
229
centerStyle () {
217
230
let style = {};
218
- let length = / %$ / .test (this .length ) || this .length == ' auto' ? this .length : uni .upx2px (this .length ) + ' px' ;
219
- style .width = length;
231
+ style .width = this .width ? this .getUnitValue (this .width ) : this .getUnitValue (this .length );
232
+ // 中部弹出的模式,如果没有设置高度,就用auto值,由内容撑开高度
233
+ style .height = this .height ? this .getUnitValue (this .height ) : ' auto' ;
220
234
style .zIndex = this .zIndex ? this .zIndex : this .$u .zIndex .popup ;
221
235
if (this .borderRadius ) {
222
236
style .borderRadius = ` ${ this .borderRadius } rpx` ;
223
237
// 不加可能圆角无效
224
238
style .overflow = ' hidden' ;
225
239
}
226
240
return style;
227
- }
241
+ },
228
242
},
229
243
watch: {
230
244
value (val ) {
@@ -236,6 +250,11 @@ export default {
236
250
}
237
251
},
238
252
methods: {
253
+ // 判断传入的值,是否带有单位,如果没有,就默认用rpx单位
254
+ getUnitValue (val ) {
255
+ if (/ (%| px| rpx| auto)$ / .test (val)) return val;
256
+ else return val + ' rpx'
257
+ },
239
258
// 遮罩被点击
240
259
maskClick () {
241
260
this .close ();
@@ -307,6 +326,11 @@ export default {
307
326
transition : all 0.3s linear ;
308
327
}
309
328
329
+ .u-drawer__scroll-view {
330
+ width : 100% ;
331
+ height : 100% ;
332
+ }
333
+
310
334
.u-drawer-left {
311
335
top : 0 ;
312
336
bottom : 0 ;
@@ -375,7 +399,7 @@ export default {
375
399
376
400
.u-close {
377
401
position : absolute ;
378
- z-index : 1 ;
402
+ z-index : 3 ;
379
403
}
380
404
381
405
.u-close--top-left {
0 commit comments