dialog.js 2.2 KB

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