u
This commit is contained in:
1 parent
8eedf281fd
commit
35bc29f356
13 files changed
+675
-171
No files matched your search
@@ -38,9 +38,10 @@ export default defineComponent({
|
||||
type: null,
|
||||
default: () => ({ label: '取消', type: 'solid', status: 'default' }),
|
||||
},
|
||||
asyncConfirm: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
beforeConfirm: {
|
||||
type: Function as PropType<
|
||||
(done: (ok: boolean) => void) => void | boolean | Promise<boolean>
|
||||
>,
|
||||
},
|
||||
maskClose: {
|
||||
type: Boolean,
|
||||
@@ -83,17 +84,36 @@ export default defineComponent({
|
||||
return `${defaultPx}px`
|
||||
}
|
||||
|
||||
const handleConfirm = () => {
|
||||
if (props.asyncConfirm) {
|
||||
const handleConfirm = async () => {
|
||||
let allow = true
|
||||
|
||||
if (props.beforeConfirm) {
|
||||
confirmLoading.value = true
|
||||
emit('confirm', close, () => {
|
||||
confirmLoading.value = false
|
||||
})
|
||||
|
||||
try {
|
||||
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))
|
||||
}
|
||||
// 如果是用 done 回调,就等调用方触发 resolve
|
||||
})
|
||||
}
|
||||
catch {
|
||||
allow = false
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
if (allow) {
|
||||
close()
|
||||
emit('confirm')
|
||||
}
|
||||
|
||||
confirmLoading.value = false
|
||||
}
|
||||
|
||||
const handleCancel = () => {
|
||||
|
||||
Reference in new issue
Block a user