@@ -14,8 +14,29 @@ import { PopupManager } from '@opentiny/utils'
1414import { getStyle , addClass } from '@opentiny/utils'
1515import { createComponent , hooks , appProperties } from '@opentiny/vue-common'
1616import 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+ }
1738
18- export const defaults = {
39+ export const defaults : LoadingConfig = {
1940 text : null ,
2041 body : false ,
2142 lock : false ,
@@ -24,7 +45,7 @@ export const defaults = {
2445 iconSize : ''
2546}
2647
27- let fullscreenLoading = null
48+ let fullscreenLoading : LoadingInstance | null = null
2849
2950export const constants = {
3051 TEXT_ATTR : 'tiny-loading__text' ,
@@ -36,45 +57,48 @@ export const constants = {
3657 PARENT_RELATIVE_CLS : 'tiny-loading__parent-relative' ,
3758 LOAD_ICON_TEXT : 'ui.load.dot'
3859}
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 > = { }
4163
4264 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 ( )
4668 } else if ( options . body ) {
47- const clientRect = options . target . getBoundingClientRect ( )
69+ const target = options . target as HTMLElement
70+ const clientRect = target ?. getBoundingClientRect ( )
4871
49- instance . originalPosition = getStyle ( document . body , 'position' )
72+ instance . originalPosition = getStyle ( document . body , 'position' ) || ''
5073
5174 const direction = [ 'top' , 'left' ]
5275
5376 direction . forEach ( ( property ) => {
5477 let scroll = property === 'top' ? 'scrollTop' : 'scrollLeft'
5578
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'
5781 } )
5882
5983 const size = [ 'height' , 'width' ]
6084
6185 size . forEach ( ( property ) => {
62- maskStyle [ property ] = clientRect [ property ] + 'px'
86+ maskStyle [ property ] = ( clientRect ?. [ property ] || 0 ) + 'px'
6387 } )
6488 } else {
65- instance . originalPosition = getStyle ( parent , 'position' )
89+ instance . originalPosition = getStyle ( parent , 'position' ) || ''
6690 }
6791
6892 Object . keys ( maskStyle ) . forEach ( ( property ) => {
6993 instance . $el . style [ property ] = maskStyle [ property ]
7094 } )
7195}
7296
73- export default ( configs = { } ) => {
97+ export default ( configs : LoadingConfig = { } ) => {
7498 configs = { ...defaults , ...configs }
7599
76100 if ( typeof configs . target === 'string' ) {
77- configs . target = document . querySelector ( configs . target )
101+ configs . target = document . querySelector ( configs . target ) as HTMLElement
78102 }
79103
80104 configs . target = configs . target || document . body
@@ -104,7 +128,7 @@ export default (configs = {}) => {
104128 tiny_mode : configs . tiny_mode || appProperties ( ) . tiny_mode ?. value
105129 } ,
106130 el : document . createElement ( 'div' )
107- } )
131+ } ) as LoadingInstance
108132
109133 for ( const key in configs ) {
110134 if ( Object . prototype . hasOwnProperty . call ( configs , key ) ) {
0 commit comments