index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 open_type_1 = require('../mixins/open-type');
  6. var color_1 = require('../common/color');
  7. var utils_1 = require('../common/utils');
  8. component_1.VantComponent({
  9. mixins: [button_1.button, open_type_1.openType],
  10. props: {
  11. show: {
  12. type: Boolean,
  13. observer: function (show) {
  14. !show && this.stopLoading();
  15. },
  16. },
  17. title: String,
  18. message: String,
  19. theme: {
  20. type: String,
  21. value: 'default',
  22. },
  23. useSlot: Boolean,
  24. className: String,
  25. customStyle: String,
  26. asyncClose: Boolean,
  27. messageAlign: String,
  28. beforeClose: null,
  29. overlayStyle: String,
  30. useTitleSlot: Boolean,
  31. showCancelButton: Boolean,
  32. closeOnClickOverlay: Boolean,
  33. confirmButtonOpenType: String,
  34. width: null,
  35. zIndex: {
  36. type: Number,
  37. value: 2000,
  38. },
  39. confirmButtonText: {
  40. type: String,
  41. value: '确认',
  42. },
  43. cancelButtonText: {
  44. type: String,
  45. value: '取消',
  46. },
  47. confirmButtonColor: {
  48. type: String,
  49. value: color_1.RED,
  50. },
  51. cancelButtonColor: {
  52. type: String,
  53. value: color_1.GRAY,
  54. },
  55. showConfirmButton: {
  56. type: Boolean,
  57. value: true,
  58. },
  59. overlay: {
  60. type: Boolean,
  61. value: true,
  62. },
  63. transition: {
  64. type: String,
  65. value: 'scale',
  66. },
  67. },
  68. data: {
  69. loading: {
  70. confirm: false,
  71. cancel: false,
  72. },
  73. },
  74. methods: {
  75. onConfirm: function () {
  76. this.handleAction('confirm');
  77. },
  78. onCancel: function () {
  79. this.handleAction('cancel');
  80. },
  81. onClickOverlay: function () {
  82. this.onClose('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,
  108. asyncClose = _b.asyncClose,
  109. beforeClose = _b.beforeClose;
  110. if (!asyncClose && !beforeClose) {
  111. this.close(action);
  112. return;
  113. }
  114. this.setData(((_a = {}), (_a['loading.' + action] = true), _a));
  115. if (beforeClose) {
  116. utils_1.toPromise(beforeClose(action)).then(function (value) {
  117. if (value) {
  118. _this.close(action);
  119. } else {
  120. _this.stopLoading();
  121. }
  122. });
  123. }
  124. },
  125. },
  126. });