@@ -2,15 +2,15 @@ import classnames from 'classnames'
2
2
import Vue from 'vue'
3
3
import ref from 'vue-ref'
4
4
import BaseMixin from '../../_util/BaseMixin'
5
- import { initDefaultProps , getEvents } from '../../_util/props-util'
5
+ import { initDefaultProps , getEvents , getClass } from '../../_util/props-util'
6
6
import { cloneElement } from '../../_util/vnode'
7
7
import ContainerRender from '../../_util/ContainerRender'
8
8
import getScrollBarSize from '../../_util/getScrollBarSize'
9
9
import drawerProps from './drawerProps'
10
10
import {
11
11
dataToArray ,
12
12
transitionEnd ,
13
- trnasitionStr ,
13
+ transitionStr ,
14
14
addEventListener ,
15
15
removeEventListener ,
16
16
transformArguments ,
@@ -40,7 +40,7 @@ const Drawer = {
40
40
showMask : true ,
41
41
handler : true ,
42
42
maskStyle : { } ,
43
- wrapClassName : '' ,
43
+ wrapperClassName : '' ,
44
44
} ) ,
45
45
data ( ) {
46
46
this . levelDom = [ ]
@@ -51,8 +51,9 @@ const Drawer = {
51
51
this . sFirstEnter = this . firstEnter
52
52
this . timeout = null
53
53
this . children = null
54
- this . drawerId = Number ( ( Date . now ( ) + Math . random ( ) ) . toString ( )
55
- . replace ( '.' , Math . round ( Math . random ( ) * 9 ) ) ) . toString ( 16 )
54
+ this . drawerId = Number (
55
+ ( Date . now ( ) + Math . random ( ) ) . toString ( ) . replace ( '.' , Math . round ( Math . random ( ) * 9 ) ) ,
56
+ ) . toString ( 16 )
56
57
const open = this . open !== undefined ? this . open : ! ! this . defaultOpen
57
58
currentDrawer [ this . drawerId ] = open
58
59
this . orignalOpen = this . open
@@ -170,7 +171,7 @@ const Drawer = {
170
171
onWrapperTransitionEnd ( e ) {
171
172
if ( e . target === this . contentWrapper ) {
172
173
this . dom . style . transition = ''
173
- if ( ! this . sOpen && this . getCrrentDrawerSome ( ) ) {
174
+ if ( ! this . sOpen && this . getCurrentDrawerSome ( ) ) {
174
175
document . body . style . overflowX = ''
175
176
if ( this . maskDom ) {
176
177
this . maskDom . style . left = ''
@@ -185,7 +186,7 @@ const Drawer = {
185
186
this . container = this . defaultGetContainer ( )
186
187
}
187
188
} ,
188
- getCrrentDrawerSome ( ) {
189
+ getCurrentDrawerSome ( ) {
189
190
return ! Object . keys ( currentDrawer ) . some ( key => currentDrawer [ key ] )
190
191
} ,
191
192
getSelfContainer ( ) {
@@ -215,8 +216,11 @@ const Drawer = {
215
216
if ( level === 'all' ) {
216
217
const children = Array . prototype . slice . call ( this . parent . children )
217
218
children . forEach ( child => {
218
- if ( child . nodeName !== 'SCRIPT' && child . nodeName !== 'STYLE' &&
219
- child . nodeName !== 'LINK' && child !== this . container ) {
219
+ if ( child . nodeName !== 'SCRIPT' &&
220
+ child . nodeName !== 'STYLE' &&
221
+ child . nodeName !== 'LINK' &&
222
+ child !== this . container
223
+ ) {
220
224
this . levelDom . push ( child )
221
225
}
222
226
} )
@@ -251,9 +255,12 @@ const Drawer = {
251
255
if ( getContainer === 'body' ) {
252
256
const eventArray = [ 'touchstart' ]
253
257
const domArray = [ document . body , this . maskDom , this . handlerdom , this . contentDom ]
254
- const right = document . body . scrollHeight > ( window . innerHeight || document . documentElement . clientHeight ) &&
258
+ const right =
259
+ document . body . scrollHeight >
260
+ ( window . innerHeight || document . documentElement . clientHeight ) &&
255
261
window . innerWidth > document . body . offsetWidth
256
- ? getScrollBarSize ( 1 ) : 0
262
+ ? getScrollBarSize ( 1 )
263
+ : 0
257
264
let widthTransition = `width ${ duration } ${ ease } `
258
265
const trannsformTransition = `transform ${ duration } ${ ease } `
259
266
if ( open && document . body . style . overflow !== 'hidden' ) {
@@ -295,12 +302,12 @@ const Drawer = {
295
302
this . passive
296
303
)
297
304
} )
298
- } else if ( this . getCrrentDrawerSome ( ) ) {
305
+ } else if ( this . getCurrentDrawerSome ( ) ) {
299
306
document . body . style . overflow = ''
300
307
if ( ( this . isOpenChange || openTransition ) && right ) {
301
308
document . body . style . position = ''
302
309
document . body . style . width = ''
303
- if ( trnasitionStr ) {
310
+ if ( transitionStr ) {
304
311
document . body . style . overflowX = 'hidden'
305
312
}
306
313
this . dom . style . transition = 'none'
@@ -367,21 +374,19 @@ const Drawer = {
367
374
maskStyle,
368
375
width,
369
376
height,
370
- wrapClassName,
371
377
} = this . $props
372
378
const children = this . $slots . default
373
379
const wrapperClassname = classnames ( prefixCls , {
374
380
[ `${ prefixCls } -${ placement } ` ] : true ,
375
381
[ `${ prefixCls } -open` ] : open ,
376
- [ wrapClassName ] : ! ! wrapClassName ,
382
+ ... getClass ( this ) ,
377
383
} )
378
384
const isOpenChange = this . isOpenChange
379
385
const isHorizontal = placement === 'left' || placement === 'right'
380
386
const placementName = `translate${ isHorizontal ? 'X' : 'Y' } `
381
387
// 百分比与像素动画不同步,第一次打用后全用像素动画。
382
388
// const defaultValue = !this.contentDom || !level ? '100%' : `${value}px`;
383
- const placementPos =
384
- placement === 'left' || placement === 'top' ? '-100%' : '100%'
389
+ const placementPos = placement === 'left' || placement === 'top' ? '-100%' : '100%'
385
390
const transform = open ? '' : `${ placementName } (${ placementPos } )`
386
391
if ( isOpenChange === undefined || isOpenChange ) {
387
392
const contentValue = this . contentDom ? this . contentDom . getBoundingClientRect ( ) [
@@ -390,7 +395,7 @@ const Drawer = {
390
395
const value = ( isHorizontal ? width : height ) || contentValue
391
396
this . setLevelDomTransform ( open , false , placementName , value )
392
397
}
393
- let handlerCildren
398
+ let handlerChildren
394
399
if ( handler !== false ) {
395
400
const handlerDefalut = (
396
401
< div class = 'drawer-handle' >
@@ -400,7 +405,7 @@ const Drawer = {
400
405
const { handler : handlerSlot } = this . $slots
401
406
const handlerSlotVnode = handlerSlot || handlerDefalut
402
407
const { click : handleIconClick } = getEvents ( handlerSlotVnode )
403
- handlerCildren = cloneElement ( handlerSlotVnode , {
408
+ handlerChildren = cloneElement ( handlerSlotVnode , {
404
409
on : {
405
410
click : ( e ) => {
406
411
handleIconClick && handleIconClick ( )
@@ -475,7 +480,7 @@ const Drawer = {
475
480
>
476
481
{ children }
477
482
</ div >
478
- { handlerCildren }
483
+ { handlerChildren }
479
484
</ div >
480
485
</ div >
481
486
)
@@ -484,7 +489,7 @@ const Drawer = {
484
489
return this . open !== undefined ? this . open : this . sOpen
485
490
} ,
486
491
getTouchParentScroll ( root , currentTarget , differX , differY ) {
487
- if ( ! currentTarget ) {
492
+ if ( ! currentTarget || currentTarget === document ) {
488
493
return false
489
494
}
490
495
// root 为 drawer-content 设定了 overflow, 判断为 root 的 parent 时结束滚动;
@@ -506,20 +511,27 @@ const Drawer = {
506
511
*/
507
512
const t = currentTarget . scrollTop
508
513
const l = currentTarget . scrollLeft
509
- currentTarget . scrollTo ( currentTarget . scrollLeft + 1 , currentTarget . scrollTop + 1 )
514
+ if ( currentTarget . scrollTo ) {
515
+ currentTarget . scrollTo ( currentTarget . scrollLeft + 1 , currentTarget . scrollTop + 1 )
516
+ }
510
517
const currentT = currentTarget . scrollTop
511
518
const currentL = currentTarget . scrollLeft
512
- currentTarget . scrollTo ( currentTarget . scrollLeft - 1 , currentTarget . scrollTop - 1 )
513
-
519
+ if ( currentTarget . scrollTo ) {
520
+ currentTarget . scrollTo ( currentTarget . scrollLeft - 1 , currentTarget . scrollTop - 1 )
521
+ }
514
522
if (
515
- isY && ( ! scrollY || ! ( currentT - t ) ||
516
- ( scrollY && ( currentTarget . scrollTop >= scrollY && differY < 0 ||
517
- currentTarget . scrollTop <= 0 && differY > 0 ) )
518
- ) ||
519
- isX && ( ! scrollX || ! ( currentL - l ) ||
520
- ( scrollX && ( currentTarget . scrollLeft >= scrollX && differX < 0 ||
521
- currentTarget . scrollLeft <= 0 && differX > 0 ) )
522
- )
523
+ ( isY &&
524
+ ( ! scrollY ||
525
+ ! ( currentT - t ) ||
526
+ ( scrollY &&
527
+ ( ( currentTarget . scrollTop >= scrollY && differY < 0 ) ||
528
+ ( currentTarget . scrollTop <= 0 && differY > 0 ) ) ) ) ) ||
529
+ ( isX &&
530
+ ( ! scrollX ||
531
+ ! ( currentL - l ) ||
532
+ ( scrollX &&
533
+ ( ( currentTarget . scrollLeft >= scrollX && differX < 0 ) ||
534
+ ( currentTarget . scrollLeft <= 0 && differX > 0 ) ) ) ) )
523
535
) {
524
536
return this . getTouchParentScroll ( root , currentTarget . parentNode , differX , differY )
525
537
}
@@ -544,8 +556,8 @@ const Drawer = {
544
556
if (
545
557
currentTarget === this . maskDom ||
546
558
currentTarget === this . handlerdom ||
547
- currentTarget === this . contentDom &&
548
- this . getTouchParentScroll ( currentTarget , e . target , differX , differY )
559
+ ( currentTarget === this . contentDom &&
560
+ this . getTouchParentScroll ( currentTarget , e . target , differX , differY ) )
549
561
) {
550
562
e . preventDefault ( )
551
563
}
@@ -588,7 +600,7 @@ const Drawer = {
588
600
</ div >
589
601
)
590
602
}
591
- if ( ! this . container || ! open && ! this . sFirstEnter ) {
603
+ if ( ! this . container || ( ! open && ! this . sFirstEnter ) ) {
592
604
return null
593
605
}
594
606
return (
0 commit comments