mirror of
https://github.com/youzan/vant.git
synced 2025-10-18 17:51:54 +00:00
[new feature] Dialog: support component call (#593)
This commit is contained in:
@@ -1,31 +1,10 @@
|
||||
import Vue from 'vue';
|
||||
import DialogComponent from './dialog';
|
||||
import VanDialog from './dialog';
|
||||
|
||||
let instance;
|
||||
|
||||
const defaultOptions = {
|
||||
value: true,
|
||||
title: '',
|
||||
message: '',
|
||||
overlay: true,
|
||||
lockOnScroll: true,
|
||||
confirmButtonText: '',
|
||||
cancelButtonText: '',
|
||||
showConfirmButton: true,
|
||||
showCancelButton: false,
|
||||
closeOnClickOverlay: false,
|
||||
callback: action => {
|
||||
instance[action === 'confirm' ? 'resolve' : 'reject'](action);
|
||||
}
|
||||
};
|
||||
|
||||
let currentDefaultOptions = {
|
||||
...defaultOptions
|
||||
};
|
||||
|
||||
const initInstance = () => {
|
||||
const DialogConstructor = Vue.extend(DialogComponent);
|
||||
instance = new DialogConstructor({
|
||||
instance = new (Vue.extend(VanDialog))({
|
||||
el: document.createElement('div')
|
||||
});
|
||||
|
||||
@@ -50,13 +29,29 @@ const Dialog = options => {
|
||||
});
|
||||
};
|
||||
|
||||
Dialog.defaultOptions = {
|
||||
value: true,
|
||||
title: '',
|
||||
message: '',
|
||||
overlay: true,
|
||||
lockOnScroll: true,
|
||||
confirmButtonText: '',
|
||||
cancelButtonText: '',
|
||||
showConfirmButton: true,
|
||||
showCancelButton: false,
|
||||
closeOnClickOverlay: false,
|
||||
callback: action => {
|
||||
instance[action === 'confirm' ? 'resolve' : 'reject'](action);
|
||||
}
|
||||
};
|
||||
|
||||
Dialog.alert = options => Dialog({
|
||||
...currentDefaultOptions,
|
||||
...Dialog.currentOptions,
|
||||
...options
|
||||
});
|
||||
|
||||
Dialog.confirm = options => Dialog({
|
||||
...currentDefaultOptions,
|
||||
...Dialog.currentOptions,
|
||||
showCancelButton: true,
|
||||
...options
|
||||
});
|
||||
@@ -65,22 +60,19 @@ Dialog.close = () => {
|
||||
instance.value = false;
|
||||
};
|
||||
|
||||
Dialog.setDefaultOptions = (options = {}) => {
|
||||
currentDefaultOptions = {
|
||||
...currentDefaultOptions,
|
||||
...options
|
||||
};
|
||||
Dialog.setDefaultOptions = options => {
|
||||
Object.assign(Dialog.currentOptions, options);
|
||||
};
|
||||
|
||||
Dialog.resetDefaultOptions = () => {
|
||||
currentDefaultOptions = {
|
||||
...defaultOptions
|
||||
};
|
||||
Dialog.currentOptions = { ...Dialog.defaultOptions };
|
||||
};
|
||||
|
||||
Dialog.install = () => {
|
||||
Vue.component(VanDialog.name, VanDialog);
|
||||
};
|
||||
|
||||
Vue.prototype.$dialog = Dialog;
|
||||
Dialog.resetDefaultOptions();
|
||||
|
||||
export default Dialog;
|
||||
export {
|
||||
DialogComponent as Dialog
|
||||
};
|
||||
|
Reference in New Issue
Block a user