This commit is contained in:
oneao committed 2025-09-18 17:28:22 +08:00
1 parent 8eedf281fd
commit 35bc29f356
13 files changed
+675 -171

No files matched your search

@@ -31,13 +31,14 @@ export default defineComponent({
type: Boolean,
default: false,
},
loading: {
type: Boolean,
default: false,
},
beforeConfirm: {
type: Function as PropType<() => boolean | Promise<boolean>>,
type: Function as PropType<
(done: (ok: boolean) => void) => void | boolean | Promise<boolean>
>,
},
class: {
type: [String, Array, Object],
@@ -70,12 +71,24 @@ export default defineComponent({
if (props.disabled || isLoading.value)
return
_loading.value = true
let allow = true
if (props.beforeConfirm) {
_loading.value = true
try {
allow = await Promise.resolve(props.beforeConfirm())
// 用一个统一的函数来兼容三种写法
allow = await new Promise<boolean>((resolve) => {
const result = props.beforeConfirm!(ok => resolve(ok))
if (typeof result === 'boolean') {
resolve(result)
}
else if (result instanceof Promise) {
result.then(ok => resolve(ok)).catch(() => resolve(false))
}
// 如果 beforeConfirm 里调用了 done,就等 done 触发
})
}
catch {
allow = false