index.js 2.9 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 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. callback: function () {},
  74. },
  75. methods: {
  76. onConfirm: function () {
  77. this.handleAction('confirm');
  78. },
  79. onCancel: function () {
  80. this.handleAction('cancel');
  81. },
  82. onClickOverlay: function () {
  83. this.close('overlay');
  84. },
  85. close: function (action) {
  86. var _this = this;
  87. this.setData({ show: false });
  88. wx.nextTick(function () {
  89. _this.$emit('close', action);
  90. var callback = _this.data.callback;
  91. if (callback) {
  92. callback(action, _this);
  93. }
  94. });
  95. },
  96. stopLoading: function () {
  97. this.setData({
  98. loading: {
  99. confirm: false,
  100. cancel: false,
  101. },
  102. });
  103. },
  104. handleAction: function (action) {
  105. var _a;
  106. var _this = this;
  107. this.$emit(action, { dialog: this });
  108. var _b = this.data,
  109. asyncClose = _b.asyncClose,
  110. beforeClose = _b.beforeClose;
  111. if (!asyncClose && !beforeClose) {
  112. this.close(action);
  113. return;
  114. }
  115. this.setData(((_a = {}), (_a['loading.' + action] = true), _a));
  116. if (beforeClose) {
  117. utils_1.toPromise(beforeClose(action)).then(function (value) {
  118. if (value) {
  119. _this.close(action);
  120. } else {
  121. _this.stopLoading();
  122. }
  123. });
  124. }
  125. },
  126. },
  127. });