1- /* eslint-disable */
2- import { defineComponent } from 'vue'
3- import { createComponent } from '../../shared/scripts/component'
4- import Loading from './loading'
1+ import type { CSSProperties , VNode , ComponentInternalInstance } from 'vue' ;
2+ import { defineComponent } from 'vue' ;
3+ import { createComponent } from '../../shared/scripts/component' ;
4+ import Loading from './loading' ;
55
6- import { LoadingProps } from './types'
6+ import { LoadingProps } from './types' ;
77
8- const loadingConstructor = defineComponent ( Loading )
8+ const loadingConstructor = defineComponent ( Loading ) ;
99
1010interface TargetElement extends Element {
11- style ?: any
11+ style ?: CSSProperties ;
1212}
1313
14- const cacheTarget = new WeakMap ( )
14+ type IMargeVNodeComponent = VNode [ 'component' ] & {
15+ loadingInstance ?: ComponentInternalInstance [ 'proxy' ] ;
16+ } | null ;
17+
18+ const cacheTarget = new WeakMap ( ) ;
1519
1620const loading = {
17- open ( options : LoadingProps = { } ) {
21+ open ( options : LoadingProps = { } ) : IMargeVNodeComponent {
1822
19- const parent : TargetElement = options . target || document . body
23+ const parent : TargetElement = options . target || document . body ;
2024
2125 if ( cacheTarget . has ( parent ) ) {
22- return cacheTarget . get ( parent )
26+ return cacheTarget . get ( parent ) ;
27+ }
28+ if ( parent . style ) {
29+ parent . style . position = options . positionType ;
2330 }
2431
25- parent . style . position = options . positionType
26-
27- const isFull = document . body === parent
32+ const isFull = document . body === parent ;
2833
29- options = { ...new LoadingProps ( ) , ...options }
34+ options = { ...new LoadingProps ( ) , ...options } ;
3035
31- const instance = createComponent ( loadingConstructor , {
36+ const instance : IMargeVNodeComponent = createComponent ( loadingConstructor , {
3237 ...options ,
3338 isFull
34- } , options . loadingTemplateRef ? ( ) => options . loadingTemplateRef : null )
35-
36- cacheTarget . set ( parent , instance )
37-
38- instance . proxy . open ( )
39- parent . appendChild ( instance . proxy . $el )
40-
41- const close = instance . proxy . close
42- instance . loadingInstance = instance . proxy
43- instance . loadingInstance . close = ( ...args : any [ ] ) => {
44- cacheTarget . delete ( parent )
45- // 1. 箭头函数内部并没有内置arguments对象 @mrundef-210810
46- // 2. 如果没有上下文要求`apply(null)`,不必使用apply/call
47- // close.apply(null, arguments)
48- close ( ...args )
39+ } , options . loadingTemplateRef ? ( ) => options . loadingTemplateRef : null ) ;
40+
41+ cacheTarget . set ( parent , instance ) ;
42+
43+ instance ?. proxy ?. open ( ) ;
44+ parent . appendChild ( instance ?. proxy ?. $el ) ;
45+
46+ const close = instance ?. proxy ?. close ;
47+ if ( instance ) {
48+ instance . loadingInstance = instance ?. proxy ;
49+ if ( instance . loadingInstance ) {
50+ instance . loadingInstance . close = ( ...args : unknown [ ] ) => {
51+ cacheTarget . delete ( parent ) ;
52+ // 1. 箭头函数内部并没有内置arguments对象 @mrundef-210810
53+ // 2. 如果没有上下文要求`apply(null)`,不必使用apply/call
54+ // close.apply(null, arguments)
55+ close ?.( ...args ) ;
56+ } ;
57+ }
4958 }
50-
51- return instance
59+ return instance ;
5260 }
53- }
61+ } ;
5462
55- export default loading
63+ export default loading ;
0 commit comments