Modal add before-close prop

This commit is contained in:
梁灏 2021-09-07 10:32:04 +08:00
parent ce92e4add3
commit 95bf1bfae9
2 changed files with 34 additions and 2 deletions

View file

@ -5,7 +5,9 @@
v-model="modal1" v-model="modal1"
title="Common Modal dialog box title" title="Common Modal dialog box title"
@on-ok="ok" @on-ok="ok"
@on-cancel="cancel"> @on-cancel="cancel"
:before-close="handleBeforeClose"
>
<p>Content of dialog</p> <p>Content of dialog</p>
<p>Content of dialog</p> <p>Content of dialog</p>
<p>Content of dialog</p> <p>Content of dialog</p>
@ -145,6 +147,20 @@
handleSpinShow () { handleSpinShow () {
this.$Spin.show(); this.$Spin.show();
}, },
handleBeforeClose () {
return new Promise((resolve, reject) => {
this.$Modal.confirm({
title: '关闭确认',
content: '您确认要关闭弹窗吗?',
onOk: () => {
resolve();
},
onCancel: () => {
reject();
}
});
});
}
} }
} }
</script> </script>

View file

@ -150,7 +150,8 @@
zIndex: { zIndex: {
type: Number, type: Number,
default: 1000 default: 1000
} },
beforeClose: Function
}, },
data () { data () {
return { return {
@ -259,6 +260,21 @@
}, },
methods: { methods: {
close () { close () {
if (!this.beforeClose) {
return this.handleClose();
}
const before = this.beforeClose();
if (before && before.then) {
before.then(() => {
this.handleClose();
});
} else {
this.handleClose();
}
},
handleClose () {
this.visible = false; this.visible = false;
this.$emit('input', false); this.$emit('input', false);
this.$emit('on-cancel'); this.$emit('on-cancel');