| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
- var queue = [];
- function getContext() {
- var pages = getCurrentPages();
- return pages[pages.length - 1];
- }
- var Dialog = function Dialog(options) {
- options = _extends({}, Dialog.currentOptions, options);
- return new Promise(function (resolve, reject) {
- var context = options.context || getContext();
- var dialog = context.selectComponent(options.selector);
- delete options.selector;
- if (dialog) {
- dialog.set(_extends({
- onCancel: reject,
- onConfirm: resolve
- }, options));
- queue.push(dialog);
- } else {
- console.warn('未找到 van-dialog 节点,请确认 selector 及 context 是否正确');
- }
- });
- };
- Dialog.defaultOptions = {
- show: true,
- title: '',
- message: '',
- zIndex: 100,
- overlay: true,
- asyncClose: false,
- messageAlign: '',
- transition: 'scale',
- selector: '#van-dialog',
- confirmButtonText: '确认',
- cancelButtonText: '取消',
- showConfirmButton: true,
- showCancelButton: false,
- closeOnClickOverlay: false,
- confirmButtonOpenType: ''
- };
- Dialog.alert = Dialog;
- Dialog.confirm = function (options) {
- return Dialog(_extends({
- showCancelButton: true
- }, options));
- };
- Dialog.close = function () {
- queue.forEach(function (dialog) {
- dialog.close();
- });
- queue = [];
- };
- Dialog.stopLoading = function () {
- queue.forEach(function (dialog) {
- dialog.stopLoading();
- });
- };
- Dialog.setDefaultOptions = function (options) {
- Object.assign(Dialog.currentOptions, options);
- };
- Dialog.resetDefaultOptions = function () {
- Dialog.currentOptions = _extends({}, Dialog.defaultOptions);
- };
- Dialog.resetDefaultOptions();
- export default Dialog;
|