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"
title="Common Modal dialog box title"
@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>
@ -145,6 +147,20 @@
handleSpinShow () {
this.$Spin.show();
},
handleBeforeClose () {
return new Promise((resolve, reject) => {
this.$Modal.confirm({
title: '关闭确认',
content: '您确认要关闭弹窗吗?',
onOk: () => {
resolve();
},
onCancel: () => {
reject();
}
});
});
}
}
}
</script>

View file

@ -150,7 +150,8 @@
zIndex: {
type: Number,
default: 1000
}
},
beforeClose: Function
},
data () {
return {
@ -259,6 +260,21 @@
},
methods: {
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.$emit('input', false);
this.$emit('on-cancel');