| | |
| | | customClass: 'art-loading-fix' |
| | | } |
| | | let loadingInstance = null |
| | | let loadingTimer = null |
| | | const DEFAULT_LOADING_DELAY = 180 |
| | | const loadingService = { |
| | | /** |
| | | * 显示 loading |
| | | * @returns 关闭 loading 的函数 |
| | | */ |
| | | showLoading() { |
| | | if (!loadingInstance) { |
| | | const config = { |
| | | ...DEFAULT_LOADING_CONFIG, |
| | | background: getLoadingBackground() |
| | | } |
| | | loadingInstance = ElLoading.service(config) |
| | | if (!loadingInstance && !loadingTimer) { |
| | | loadingTimer = setTimeout(() => { |
| | | loadingTimer = null |
| | | if (loadingInstance) { |
| | | return |
| | | } |
| | | const config = { |
| | | ...DEFAULT_LOADING_CONFIG, |
| | | background: getLoadingBackground() |
| | | } |
| | | loadingInstance = ElLoading.service(config) |
| | | }, DEFAULT_LOADING_DELAY) |
| | | } |
| | | return () => this.hideLoading() |
| | | }, |
| | |
| | | * 隐藏 loading |
| | | */ |
| | | hideLoading() { |
| | | if (loadingTimer) { |
| | | clearTimeout(loadingTimer) |
| | | loadingTimer = null |
| | | } |
| | | if (loadingInstance) { |
| | | loadingInstance.close() |
| | | loadingInstance = null |