mirror of
https://github.com/un-pany/v3-admin-vite.git
synced 2025-04-20 19:09:21 +08:00
types: 优化 useFullscreenLoading 的类型(闭包的泛型)
This commit is contained in:
parent
e878399d9e
commit
42a9967952
@ -9,6 +9,12 @@ interface ILoadingInstance {
|
||||
close: () => void
|
||||
}
|
||||
|
||||
interface IUseFullscreenLoading {
|
||||
<T extends (...args: any[]) => ReturnType<T>>(fn: T, options?: LoadingOptions): (
|
||||
...args: Parameters<T>
|
||||
) => Promise<ReturnType<T>> | ReturnType<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* 传入一个函数 fn,在它执行周期内,加上「全屏」loading,
|
||||
* 如果:
|
||||
@ -19,10 +25,7 @@ interface ILoadingInstance {
|
||||
* @param options LoadingOptions
|
||||
* @returns Function 一个新的函数,去执行它吧
|
||||
*/
|
||||
export function useFullscreenLoading<T>(
|
||||
fn: (...args: any[]) => T | Promise<T>,
|
||||
options: LoadingOptions = {}
|
||||
): (...args: any[]) => Promise<T> {
|
||||
export const useFullscreenLoading: IUseFullscreenLoading = (fn, options = {}) => {
|
||||
let loadingInstance: ILoadingInstance
|
||||
const showLoading = (options: LoadingOptions) => {
|
||||
loadingInstance = ElLoading.service(options)
|
||||
@ -31,7 +34,7 @@ export function useFullscreenLoading<T>(
|
||||
loadingInstance && loadingInstance.close()
|
||||
}
|
||||
const _options = { ...defaultOptions, ...options }
|
||||
return (...args: any[]) => {
|
||||
return (...args) => {
|
||||
try {
|
||||
showLoading(_options)
|
||||
const result = fn(...args)
|
||||
|
Loading…
x
Reference in New Issue
Block a user