dialog.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports["default"] = void 0;
  6. var _my = require("../../__antmove/api/index.js")(my);
  7. var wx = _my;
  8. var queue = [];
  9. var defaultOptions = {
  10. show: false,
  11. title: "",
  12. width: null,
  13. theme: "default",
  14. message: "",
  15. zIndex: 100,
  16. overlay: true,
  17. selector: "#van-dialog",
  18. className: "",
  19. asyncClose: false,
  20. transition: "scale",
  21. customStyle: "",
  22. messageAlign: "",
  23. overlayStyle: "",
  24. confirmButtonText: "确认",
  25. cancelButtonText: "取消",
  26. showConfirmButton: true,
  27. showCancelButton: false,
  28. closeOnClickOverlay: false,
  29. confirmButtonOpenType: ""
  30. };
  31. var currentOptions = Object.assign({}, defaultOptions);
  32. function getContext() {
  33. var pages = getCurrentPages();
  34. return pages[pages.length - 1];
  35. }
  36. var Dialog = function Dialog(options) {
  37. options = Object.assign(Object.assign({}, currentOptions), options);
  38. return new Promise(function (resolve, reject) {
  39. var context = options.context || getContext();
  40. var dialog = context.selectComponent(options.selector);
  41. delete options.context;
  42. delete options.selector;
  43. if (dialog) {
  44. dialog.setData(Object.assign({
  45. onCancel: reject,
  46. onConfirm: resolve
  47. }, options));
  48. wx.nextTick(function () {
  49. dialog.setData({
  50. show: true
  51. });
  52. });
  53. queue.push(dialog);
  54. } else {
  55. console.warn("未找到 van-dialog 节点,请确认 selector 及 context 是否正确");
  56. }
  57. });
  58. };
  59. Dialog.alert = function (options) {
  60. return Dialog(options);
  61. };
  62. Dialog.confirm = function (options) {
  63. return Dialog(Object.assign({
  64. showCancelButton: true
  65. }, 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.currentOptions = currentOptions;
  79. Dialog.defaultOptions = defaultOptions;
  80. Dialog.setDefaultOptions = function (options) {
  81. currentOptions = Object.assign(Object.assign({}, currentOptions), options);
  82. Dialog.currentOptions = currentOptions;
  83. };
  84. Dialog.resetDefaultOptions = function () {
  85. currentOptions = Object.assign({}, defaultOptions);
  86. Dialog.currentOptions = currentOptions;
  87. };
  88. Dialog.resetDefaultOptions();
  89. var _default = Dialog;
  90. exports["default"] = _default;