RAGflow/management/web/src/common/composables/useFullscreenLoading.ts

37 lines
951 B
TypeScript
Raw Normal View History

2025-03-28 22:45:42 +08:00
import type { LoadingOptions } from "element-plus"
interface UseFullscreenLoading {
<T extends (...args: Parameters<T>) => ReturnType<T>>(
fn: T,
options?: LoadingOptions
): (...args: Parameters<T>) => Promise<ReturnType<T>>
}
interface LoadingInstance {
close: () => void
}
const DEFAULT_OPTIONS = {
lock: true,
text: "加载中..."
}
/**
* @name Composable
* @description fnLoading
* @param fn
* @param options LoadingOptions
* @returns Promise
*/
export const useFullscreenLoading: UseFullscreenLoading = (fn, options = {}) => {
let loadingInstance: LoadingInstance
return async (...args) => {
try {
loadingInstance = ElLoading.service({ ...DEFAULT_OPTIONS, ...options })
return await fn(...args)
} finally {
loadingInstance.close()
}
}
}