123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- import _extends from "@babel/runtime/helpers/esm/extends";
- import Vue from 'vue';
- import VanDialog from './Dialog';
- import { isServer } from '../utils';
- var instance;
- function isInDocument(element) {
- return document.body.contains(element);
- }
- function initInstance() {
- if (instance) {
- instance.$destroy();
- }
- instance = new (Vue.extend(VanDialog))({
- el: document.createElement('div'),
- // avoid missing animation when first rendered
- propsData: {
- lazyRender: false
- }
- });
- instance.$on('input', function (value) {
- instance.value = value;
- });
- }
- function Dialog(options) {
- /* istanbul ignore if */
- if (isServer) {
- return Promise.resolve();
- }
- return new Promise(function (resolve, reject) {
- if (!instance || !isInDocument(instance.$el)) {
- initInstance();
- }
- _extends(instance, Dialog.currentOptions, options, {
- resolve: resolve,
- reject: reject
- });
- });
- }
- Dialog.defaultOptions = {
- value: true,
- title: '',
- width: '',
- theme: null,
- message: '',
- overlay: true,
- className: '',
- allowHtml: true,
- lockScroll: true,
- transition: 'van-dialog-bounce',
- beforeClose: null,
- overlayClass: '',
- overlayStyle: null,
- messageAlign: '',
- getContainer: 'body',
- cancelButtonText: '',
- cancelButtonColor: null,
- confirmButtonText: '',
- confirmButtonColor: null,
- showConfirmButton: true,
- showCancelButton: false,
- closeOnPopstate: true,
- closeOnClickOverlay: false,
- callback: function callback(action) {
- instance[action === 'confirm' ? 'resolve' : 'reject'](action);
- }
- };
- Dialog.alert = Dialog;
- Dialog.confirm = function (options) {
- return Dialog(_extends({
- showCancelButton: true
- }, options));
- };
- Dialog.close = function () {
- if (instance) {
- instance.value = false;
- }
- };
- Dialog.setDefaultOptions = function (options) {
- _extends(Dialog.currentOptions, options);
- };
- Dialog.resetDefaultOptions = function () {
- Dialog.currentOptions = _extends({}, Dialog.defaultOptions);
- };
- Dialog.resetDefaultOptions();
- Dialog.install = function () {
- Vue.use(VanDialog);
- };
- Dialog.Component = VanDialog;
- Vue.prototype.$dialog = Dialog;
- export default Dialog;
|