finance-pay-admin/pc/composables/useLockFn.ts

20 lines
459 B
TypeScript
Raw Permalink Normal View History

2023-11-08 18:02:55 +08:00
export function useLockFn(fn: (...args: any[]) => Promise<any>) {
const isLock = ref(false)
const lockFn = async (...args: any[]) => {
if (isLock.value) return
isLock.value = true
try {
const res = await fn(...args)
isLock.value = false
return res
} catch (e) {
isLock.value = false
throw e
}
}
return {
isLock,
lockFn
}
}