[Improvement] Dialog: add setDefaultOptions method (#539)

This commit is contained in:
neverland
2018-01-17 18:54:12 +08:00
committed by GitHub
parent 567db144be
commit b7282356ee
3 changed files with 24 additions and 3 deletions

View File

@@ -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;