From 42a9967952f11cf303c7381d747ec2da9c46788d Mon Sep 17 00:00:00 2001 From: pany <939630029@qq.com> Date: Wed, 8 Feb 2023 11:31:56 +0800 Subject: [PATCH] =?UTF-8?q?types:=20=E4=BC=98=E5=8C=96=20useFullscreenLoad?= =?UTF-8?q?ing=20=E7=9A=84=E7=B1=BB=E5=9E=8B=EF=BC=88=E9=97=AD=E5=8C=85?= =?UTF-8?q?=E7=9A=84=E6=B3=9B=E5=9E=8B=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useFullscreenLoading.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/hooks/useFullscreenLoading.ts b/src/hooks/useFullscreenLoading.ts index 155c481..9d7d2e4 100644 --- a/src/hooks/useFullscreenLoading.ts +++ b/src/hooks/useFullscreenLoading.ts @@ -9,6 +9,12 @@ interface ILoadingInstance { close: () => void } +interface IUseFullscreenLoading { + ReturnType>(fn: T, options?: LoadingOptions): ( + ...args: Parameters + ) => Promise> | ReturnType +} + /** * 传入一个函数 fn,在它执行周期内,加上「全屏」loading, * 如果: @@ -19,10 +25,7 @@ interface ILoadingInstance { * @param options LoadingOptions * @returns Function 一个新的函数,去执行它吧 */ -export function useFullscreenLoading( - fn: (...args: any[]) => T | Promise, - options: LoadingOptions = {} -): (...args: any[]) => Promise { +export const useFullscreenLoading: IUseFullscreenLoading = (fn, options = {}) => { let loadingInstance: ILoadingInstance const showLoading = (options: LoadingOptions) => { loadingInstance = ElLoading.service(options) @@ -31,7 +34,7 @@ export function useFullscreenLoading( loadingInstance && loadingInstance.close() } const _options = { ...defaultOptions, ...options } - return (...args: any[]) => { + return (...args) => { try { showLoading(_options) const result = fn(...args)