dialog.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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(__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.setData(__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. width: null,
  39. message: '',
  40. zIndex: 100,
  41. overlay: true,
  42. selector: '#van-dialog',
  43. className: '',
  44. asyncClose: false,
  45. transition: 'scale',
  46. customStyle: '',
  47. messageAlign: '',
  48. overlayStyle: '',
  49. confirmButtonText: '确认',
  50. cancelButtonText: '取消',
  51. showConfirmButton: true,
  52. showCancelButton: false,
  53. closeOnClickOverlay: false,
  54. confirmButtonOpenType: ''
  55. };
  56. Dialog.alert = Dialog;
  57. Dialog.confirm = function (options) {
  58. return Dialog(__assign({ showCancelButton: true }, options));
  59. };
  60. Dialog.close = function () {
  61. queue.forEach(function (dialog) {
  62. dialog.close();
  63. });
  64. queue = [];
  65. };
  66. Dialog.stopLoading = function () {
  67. queue.forEach(function (dialog) {
  68. dialog.stopLoading();
  69. });
  70. };
  71. Dialog.setDefaultOptions = function (options) {
  72. Object.assign(Dialog.currentOptions, options);
  73. };
  74. Dialog.resetDefaultOptions = function () {
  75. Dialog.currentOptions = __assign({}, Dialog.defaultOptions);
  76. };
  77. Dialog.resetDefaultOptions();
  78. exports.default = Dialog;