dialog.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. "use strict";
  2. var __assign = (this && this.__assign) || function () {
  3. __assign = Object.assign || function(t) {
  4. for (var s, i = 1, n = arguments.length; i < n; i++) {
  5. s = arguments[i];
  6. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  7. t[p] = s[p];
  8. }
  9. return t;
  10. };
  11. return __assign.apply(this, arguments);
  12. };
  13. Object.defineProperty(exports, "__esModule", { value: true });
  14. var queue = [];
  15. function getContext() {
  16. var pages = getCurrentPages();
  17. return pages[pages.length - 1];
  18. }
  19. var Dialog = function (options) {
  20. options = __assign({}, Dialog.currentOptions, options);
  21. return new Promise(function (resolve, reject) {
  22. var context = options.context || getContext();
  23. var dialog = context.selectComponent(options.selector);
  24. delete options.context;
  25. delete options.selector;
  26. if (dialog) {
  27. dialog.set(__assign({ onCancel: reject, onConfirm: resolve }, options));
  28. queue.push(dialog);
  29. }
  30. else {
  31. console.warn('未找到 van-dialog 节点,请确认 selector 及 context 是否正确');
  32. }
  33. });
  34. };
  35. Dialog.defaultOptions = {
  36. show: true,
  37. title: '',
  38. message: '',
  39. zIndex: 100,
  40. overlay: true,
  41. className: '',
  42. customStyle: '',
  43. asyncClose: false,
  44. messageAlign: '',
  45. transition: 'scale',
  46. selector: '#van-dialog',
  47. confirmButtonText: '确认',
  48. cancelButtonText: '取消',
  49. showConfirmButton: true,
  50. showCancelButton: false,
  51. closeOnClickOverlay: false,
  52. confirmButtonOpenType: ''
  53. };
  54. Dialog.alert = Dialog;
  55. Dialog.confirm = function (options) {
  56. return Dialog(__assign({ showCancelButton: true }, options));
  57. };
  58. Dialog.close = function () {
  59. queue.forEach(function (dialog) {
  60. dialog.close();
  61. });
  62. queue = [];
  63. };
  64. Dialog.stopLoading = function () {
  65. queue.forEach(function (dialog) {
  66. dialog.stopLoading();
  67. });
  68. };
  69. Dialog.setDefaultOptions = function (options) {
  70. Object.assign(Dialog.currentOptions, options);
  71. };
  72. Dialog.resetDefaultOptions = function () {
  73. Dialog.currentOptions = __assign({}, Dialog.defaultOptions);
  74. };
  75. Dialog.resetDefaultOptions();
  76. exports.default = Dialog;