index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var component_1 = require("../common/component");
  4. var button_1 = require("../mixins/button");
  5. var color_1 = require("../common/color");
  6. var utils_1 = require("../common/utils");
  7. (0, component_1.VantComponent)({
  8. mixins: [button_1.button],
  9. props: {
  10. show: {
  11. type: Boolean,
  12. observer: function (show) {
  13. !show && this.stopLoading();
  14. },
  15. },
  16. title: String,
  17. message: String,
  18. theme: {
  19. type: String,
  20. value: 'default',
  21. },
  22. useSlot: Boolean,
  23. className: String,
  24. customStyle: String,
  25. asyncClose: Boolean,
  26. messageAlign: String,
  27. beforeClose: null,
  28. overlayStyle: String,
  29. useTitleSlot: Boolean,
  30. showCancelButton: Boolean,
  31. closeOnClickOverlay: Boolean,
  32. confirmButtonOpenType: String,
  33. width: null,
  34. zIndex: {
  35. type: Number,
  36. value: 2000,
  37. },
  38. confirmButtonText: {
  39. type: String,
  40. value: '确认',
  41. },
  42. cancelButtonText: {
  43. type: String,
  44. value: '取消',
  45. },
  46. confirmButtonColor: {
  47. type: String,
  48. value: color_1.RED,
  49. },
  50. cancelButtonColor: {
  51. type: String,
  52. value: color_1.GRAY,
  53. },
  54. showConfirmButton: {
  55. type: Boolean,
  56. value: true,
  57. },
  58. overlay: {
  59. type: Boolean,
  60. value: true,
  61. },
  62. transition: {
  63. type: String,
  64. value: 'scale',
  65. },
  66. },
  67. data: {
  68. loading: {
  69. confirm: false,
  70. cancel: false,
  71. },
  72. callback: (function () { }),
  73. },
  74. methods: {
  75. onConfirm: function () {
  76. this.handleAction('confirm');
  77. },
  78. onCancel: function () {
  79. this.handleAction('cancel');
  80. },
  81. onClickOverlay: function () {
  82. this.close('overlay');
  83. },
  84. close: function (action) {
  85. var _this = this;
  86. this.setData({ show: false });
  87. wx.nextTick(function () {
  88. _this.$emit('close', action);
  89. var callback = _this.data.callback;
  90. if (callback) {
  91. callback(action, _this);
  92. }
  93. });
  94. },
  95. stopLoading: function () {
  96. this.setData({
  97. loading: {
  98. confirm: false,
  99. cancel: false,
  100. },
  101. });
  102. },
  103. handleAction: function (action) {
  104. var _a;
  105. var _this = this;
  106. this.$emit(action, { dialog: this });
  107. var _b = this.data, asyncClose = _b.asyncClose, beforeClose = _b.beforeClose;
  108. if (!asyncClose && !beforeClose) {
  109. this.close(action);
  110. return;
  111. }
  112. this.setData((_a = {},
  113. _a["loading.".concat(action)] = true,
  114. _a));
  115. if (beforeClose) {
  116. (0, utils_1.toPromise)(beforeClose(action)).then(function (value) {
  117. if (value) {
  118. _this.close(action);
  119. }
  120. else {
  121. _this.stopLoading();
  122. }
  123. });
  124. }
  125. },
  126. },
  127. });