From 6d74198e27633d04fcd1faea7a93cad7c47e78f6 Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 17 Apr 2018 14:16:28 +0800 Subject: [PATCH] [Improvement] Dialog: add before-close prop (#881) --- docs/demos/views/dialog.vue | 17 +++++------ docs/markdown/en-US/dialog.md | 14 +++++---- docs/markdown/zh-CN/dialog.md | 21 ++++++++------ packages/dialog/dialog.vue | 53 ++++++++++++++++++----------------- packages/dialog/index.js | 1 + test/specs/dialog.spec.js | 26 +++++++++++++++-- types/dialog.d.ts | 1 + 7 files changed, 82 insertions(+), 51 deletions(-) diff --git a/docs/demos/views/dialog.vue b/docs/demos/views/dialog.vue index 052dad95b..38cc7762d 100644 --- a/docs/demos/views/dialog.vue +++ b/docs/demos/views/dialog.vue @@ -13,7 +13,8 @@ {{ $t('advancedUsage') }} { - setTimeout(() => { - resolve() - }, 1000) - }) + beforeClose(action, done) { + if (action === 'confirm') { + setTimeout(done, 1000); + } else { + done(); + } } } }; diff --git a/docs/markdown/en-US/dialog.md b/docs/markdown/en-US/dialog.md index 66544b325..f2b03d6eb 100644 --- a/docs/markdown/en-US/dialog.md +++ b/docs/markdown/en-US/dialog.md @@ -77,6 +77,7 @@ export default { | overlay | Whether to show overlay | `Boolean` | `true` | - | | closeOnClickOverlay | Whether to close when click overlay | `Boolean` | `false` | - | | lockScroll | Whether to lock body scroll | `Boolean` | `true` | - | +| beforeClose | Callback before close,call done to close dialog | (action: string, done: function) => void | - | - | #### Advanced Usage If you need to render vue components within a dialog, you can use dialog component. @@ -110,12 +111,12 @@ export default { }, methods: { - onClickConfirmAsync() { - return new Promise((resolve, reject) => { - setTimeout(() => { - resolve() - }, 1000) - }) + beforeClose() { + if (action === 'confirm') { + setTimeout(done, 1000); + } else { + done(); + } } } } @@ -136,6 +137,7 @@ export default { | overlay | Whether to show overlay | `Boolean` | `true` | - | | close-on-click-overlay | Whether to close when click overlay | `Boolean` | `false` | - | | lock-scroll | Whether to lock background scroll | `Boolean` | `true` | - | +| before-close | Callback before close,call done to close dialog | (action: string, done: function) => void | - | - | ### Event diff --git a/docs/markdown/zh-CN/dialog.md b/docs/markdown/zh-CN/dialog.md index 06b366a1b..876e55144 100644 --- a/docs/markdown/zh-CN/dialog.md +++ b/docs/markdown/zh-CN/dialog.md @@ -78,13 +78,18 @@ export default { | overlay | 是否展示蒙层 | `Boolean` | `true` | - | | closeOnClickOverlay | 点击蒙层时是否关闭弹窗 | `Boolean` | `false` | - | | lockScroll | 是否锁定背景滚动 | `Boolean` | `true` | - | +| beforeClose | 关闭前的回调函数,调用 done 后关闭弹窗 | (action: string, done: function) => void | - | - | #### 高级用法 如果需要在弹窗内实现更复杂的交互,可以通过组件形式来调用 Dialog ```html - + { - setTimeout(() => { - resolve(); - }, 1000) - }); + beforeClose() { + if (action === 'confirm') { + setTimeout(done, 1000); + } else { + done(); + } } } } @@ -130,7 +135,6 @@ export default { | v-model | 是否显示弹窗 | `Boolean` | - | - | | title | 标题 | `String` | - | - | | message | 内容 | `String` | - | - | -| async-confirm | dialog是否异步关闭,传入一个返回Promise的函数,在点击确定时触发。 | `Function` | - | - | | show-confirm-button | 是否展示确认按钮 | `Boolean` | `true` | - | | show-cancel-button | 是否展示取消按钮 | `Boolean` | `false` | - | | confirm-button-text | 确认按钮的文案 | `String` | `确认` | - | @@ -138,6 +142,7 @@ export default { | overlay | 是否展示蒙层 | `Boolean` | `true` | - | | close-on-click-overlay | 点击蒙层时是否关闭弹窗 | `Boolean` | `false` | - | | lock-scroll | 是否锁定背景滚动 | `Boolean` | `true` | - | +| before-close | 关闭前的回调函数,调用 done 后关闭弹窗 | (action: string, done: function) => void | - | - | ### Event diff --git a/packages/dialog/dialog.vue b/packages/dialog/dialog.vue index c7bd80062..8446fa7e9 100644 --- a/packages/dialog/dialog.vue +++ b/packages/dialog/dialog.vue @@ -9,19 +9,20 @@