From 5ef3d0ec8d02872fc5de51d16ffe36af2700b11c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=A5=95?= Date: Tue, 3 Jul 2018 12:02:21 +0800 Subject: [PATCH] MessageBox: add distinguishCancelAndClose (#11831) --- examples/docs/en-US/message-box.md | 75 ++++++++++++++++++++++++++-- examples/docs/es/message-box.md | 77 ++++++++++++++++++++++++++--- examples/docs/zh-CN/message-box.md | 77 ++++++++++++++++++++++++++--- packages/message-box/src/main.js | 5 +- packages/message-box/src/main.vue | 9 ++-- test/unit/specs/message-box.spec.js | 18 +++++++ types/message-box.d.ts | 2 +- 7 files changed, 239 insertions(+), 24 deletions(-) diff --git a/examples/docs/en-US/message-box.md b/examples/docs/en-US/message-box.md index 9f15b836..a79aea98 100644 --- a/examples/docs/en-US/message-box.md +++ b/examples/docs/en-US/message-box.md @@ -100,6 +100,28 @@ }, open6() { + this.$confirm('You have unsaved changes, save and proceed?', 'Confirm', { + distinguishCancelAndClose: true, + confirmButtonText: 'Save', + cancelButtonText: 'Discard Changes' + }) + .then(() => { + this.$message({ + type: 'info', + message: 'Changes saved. Proceeding to a new route.' + }); + }) + .catch(action => { + this.$message({ + type: 'info', + message: action === 'cancel' + ? 'Changes discarded. Proceeding to a new route.' + : 'Stay in the current route' + }) + }); + }, + + open7() { this.$confirm('This will permanently delete the file. Continue?', 'Warning', { confirmButtonText: 'OK', cancelButtonText: 'Cancel', @@ -292,6 +314,7 @@ The content of MessageBox can be `VNode`, allowing us to pass custom components. ::: ### Use HTML String + `message` supports HTML string. :::demo Set `dangerouslyUseHTMLString` to true and `message` will be treated as an HTML string. @@ -319,10 +342,11 @@ The content of MessageBox can be `VNode`, allowing us to pass custom components. Although `message` property supports HTML strings, dynamically rendering arbitrary HTML on your website can be very dangerous because it can easily lead to [XSS attacks](https://en.wikipedia.org/wiki/Cross-site_scripting). So when `dangerouslyUseHTMLString` is on, please make sure the content of `message` is trusted, and **never** assign `message` to user-provided content. ::: -### Centered content -Content of MessageBox can be centered. +### Distinguishing cancel and close -:::demo Setting `center` to `true` will center the content +In some cases, clicking the cancel button and close button may have different meanings. + +:::demo By default, the parameters of Promise's reject callback and `callback` are 'cancel' when the user cancels (clicking the cancel button) and closes (clicking the close button or mask layer, pressing the ESC key) the MessageBox. If `distinguishCancelAndClose` is set to true, the parameters of the above two operations are 'cancel' and 'close' respectively. ```html