@@ -14,8 +14,29 @@ import { PopupManager } from '@opentiny/utils'
14
14
import { getStyle , addClass } from '@opentiny/utils'
15
15
import { createComponent , hooks , appProperties } from '@opentiny/vue-common'
16
16
import Loading from './index'
17
+ import type { ILoadingState } from '@opentiny/vue-renderless/types/loading.type'
18
+
19
+ interface LoadingConfig {
20
+ text ?: string | null
21
+ body ?: boolean
22
+ lock ?: boolean
23
+ customClass ?: string
24
+ fullscreen ?: boolean
25
+ iconSize ?: string
26
+ target ?: HTMLElement | string
27
+ size ?: string
28
+ loadingImg ?: string
29
+ tiny_mode ?: string
30
+ }
31
+
32
+ interface LoadingInstance {
33
+ state : ILoadingState
34
+ $el : HTMLElement
35
+ originalPosition ?: string
36
+ originalOverflow ?: string
37
+ }
17
38
18
- export const defaults = {
39
+ export const defaults : LoadingConfig = {
19
40
text : null ,
20
41
body : false ,
21
42
lock : false ,
@@ -24,7 +45,7 @@ export const defaults = {
24
45
iconSize : ''
25
46
}
26
47
27
- let fullscreenLoading = null
48
+ let fullscreenLoading : LoadingInstance | null = null
28
49
29
50
export const constants = {
30
51
TEXT_ATTR : 'tiny-loading__text' ,
@@ -36,45 +57,48 @@ export const constants = {
36
57
PARENT_RELATIVE_CLS : 'tiny-loading__parent-relative' ,
37
58
LOAD_ICON_TEXT : 'ui.load.dot'
38
59
}
39
- const addStyle = ( options , parent , instance ) => {
40
- let maskStyle = { }
60
+
61
+ const addStyle = ( options : LoadingConfig , parent : HTMLElement , instance : LoadingInstance ) => {
62
+ let maskStyle : Record < string , string > = { }
41
63
42
64
if ( options . fullscreen ) {
43
- instance . originalPosition = getStyle ( document . body , 'position' )
44
- instance . originalOverflow = getStyle ( document . body , 'overflow' )
45
- maskStyle . zIndex = PopupManager . nextZIndex ( )
65
+ instance . originalPosition = getStyle ( document . body , 'position' ) || ''
66
+ instance . originalOverflow = getStyle ( document . body , 'overflow' ) || ''
67
+ maskStyle . zIndex = PopupManager . nextZIndex ( ) . toString ( )
46
68
} else if ( options . body ) {
47
- const clientRect = options . target . getBoundingClientRect ( )
69
+ const target = options . target as HTMLElement
70
+ const clientRect = target ?. getBoundingClientRect ( )
48
71
49
- instance . originalPosition = getStyle ( document . body , 'position' )
72
+ instance . originalPosition = getStyle ( document . body , 'position' ) || ''
50
73
51
74
const direction = [ 'top' , 'left' ]
52
75
53
76
direction . forEach ( ( property ) => {
54
77
let scroll = property === 'top' ? 'scrollTop' : 'scrollLeft'
55
78
56
- maskStyle [ property ] = clientRect [ property ] + document . body [ scroll ] + document . documentElement [ scroll ] + 'px'
79
+ maskStyle [ property ] =
80
+ ( clientRect ?. [ property ] || 0 ) + document . body [ scroll ] + document . documentElement [ scroll ] + 'px'
57
81
} )
58
82
59
83
const size = [ 'height' , 'width' ]
60
84
61
85
size . forEach ( ( property ) => {
62
- maskStyle [ property ] = clientRect [ property ] + 'px'
86
+ maskStyle [ property ] = ( clientRect ?. [ property ] || 0 ) + 'px'
63
87
} )
64
88
} else {
65
- instance . originalPosition = getStyle ( parent , 'position' )
89
+ instance . originalPosition = getStyle ( parent , 'position' ) || ''
66
90
}
67
91
68
92
Object . keys ( maskStyle ) . forEach ( ( property ) => {
69
93
instance . $el . style [ property ] = maskStyle [ property ]
70
94
} )
71
95
}
72
96
73
- export default ( configs = { } ) => {
97
+ export default ( configs : LoadingConfig = { } ) => {
74
98
configs = { ...defaults , ...configs }
75
99
76
100
if ( typeof configs . target === 'string' ) {
77
- configs . target = document . querySelector ( configs . target )
101
+ configs . target = document . querySelector ( configs . target ) as HTMLElement
78
102
}
79
103
80
104
configs . target = configs . target || document . body
@@ -104,7 +128,7 @@ export default (configs = {}) => {
104
128
tiny_mode : configs . tiny_mode || appProperties ( ) . tiny_mode ?. value
105
129
} ,
106
130
el : document . createElement ( 'div' )
107
- } )
131
+ } ) as LoadingInstance
108
132
109
133
for ( const key in configs ) {
110
134
if ( Object . prototype . hasOwnProperty . call ( configs , key ) ) {
0 commit comments