diff --git a/docs/markdown/en-US/dialog.md b/docs/markdown/en-US/dialog.md index 2af868d6f..350783cbb 100644 --- a/docs/markdown/en-US/dialog.md +++ b/docs/markdown/en-US/dialog.md @@ -59,6 +59,8 @@ export default { |-----------|-----------|-----------|-------------| | Dialog.alert | options | `Promise` | Show alert dialog | | Dialog.confirm | options | `Promise` | Show confim dialog | +| Dialog.setDefaultOptions | options | `void` | Set default options of all dialogs | +| Dialog.resetDefaultOptions | - | `void` | Reset default options of all dialogs | | Dialog.close | - | `void` | Close dialog | ### Options diff --git a/docs/markdown/zh-CN/dialog.md b/docs/markdown/zh-CN/dialog.md index 924ddbd01..4260f3b70 100644 --- a/docs/markdown/zh-CN/dialog.md +++ b/docs/markdown/zh-CN/dialog.md @@ -59,6 +59,8 @@ export default { |-----------|-----------|-----------|-------------| | Dialog.alert | options | `Promise` | 展示消息提示弹窗 | | Dialog.confirm | options | `Promise` | 展示消息确认弹窗 | +| Dialog.setDefaultOptions | options | `void` | 修改默认配置,对所有 Dialog 生效 | +| Dialog.resetDefaultOptions | - | `void` | 重置默认配置,对所有 Dialog 生效 | | Dialog.close | - | `void` | 关闭弹窗 | ### Options diff --git a/packages/dialog/index.js b/packages/dialog/index.js index d9934f2b4..a52b5b916 100644 --- a/packages/dialog/index.js +++ b/packages/dialog/index.js @@ -3,7 +3,7 @@ import DialogComponent from './dialog'; let instance; -const defaultConfig = { +const defaultOptions = { value: true, title: '', message: '', @@ -19,6 +19,10 @@ const defaultConfig = { } }; +let currentDefaultOptions = { + ...defaultOptions +}; + const initInstance = () => { const DialogConstructor = Vue.extend(DialogComponent); instance = new DialogConstructor({ @@ -47,12 +51,12 @@ const Dialog = options => { }; Dialog.alert = options => Dialog({ - ...defaultConfig, + ...currentDefaultOptions, ...options }); Dialog.confirm = options => Dialog({ - ...defaultConfig, + ...currentDefaultOptions, showCancelButton: true, ...options }); @@ -61,6 +65,19 @@ Dialog.close = () => { instance.value = false; }; +Dialog.setDefaultOptions = (options = {}) => { + currentDefaultOptions = { + ...currentDefaultOptions, + ...options + }; +}; + +Dialog.resetDefaultOptions = () => { + currentDefaultOptions = { + ...defaultOptions + }; +}; + Vue.prototype.$dialog = Dialog; export default Dialog;