From 592fa8265045b1bdd963f895a92b4e3d506b9747 Mon Sep 17 00:00:00 2001 From: pany <939630029@qq.com> Date: Mon, 25 Nov 2024 10:40:24 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=20useFullscreenL?= =?UTF-8?q?oading=20=E4=BB=A3=E7=A0=81=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/composables/useFullscreenLoading.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) 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() } } }