diff --git a/src/composables/useFullscreenLoading.ts b/src/composables/useFullscreenLoading.ts index f88b211..1572aad 100644 --- a/src/composables/useFullscreenLoading.ts +++ b/src/composables/useFullscreenLoading.ts @@ -1,15 +1,6 @@ import type { LoadingOptions } from "element-plus" import { ElLoading } from "element-plus" -const defaultOptions = { - lock: true, - text: "加载中..." -} - -interface LoadingInstance { - close: () => void -} - interface UseFullscreenLoading { ) => ReturnType>( fn: T, @@ -17,8 +8,17 @@ interface UseFullscreenLoading { ): (...args: Parameters) => Promise> } +interface LoadingInstance { + close: () => void +} + +const DEFAULT_OPTIONS = { + lock: true, + text: "加载中..." +} + /** - * 传入一个函数 fn,在它执行周期内,加上「全屏」loading + * 传入一个函数 fn,在它执行周期内,加上「全屏」Loading * @param fn 要执行的函数 * @param options LoadingOptions * @returns 返回一个新的函数,该函数返回一个 Promise @@ -27,10 +27,10 @@ export const useFullscreenLoading: UseFullscreenLoading = (fn, options = {}) => let loadingInstance: LoadingInstance return async (...args) => { try { - loadingInstance = ElLoading.service({ ...defaultOptions, ...options }) + loadingInstance = ElLoading.service({ ...DEFAULT_OPTIONS, ...options }) return await fn(...args) } finally { - loadingInstance?.close() + loadingInstance.close() } } }