index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. classes: ['cancle-button-class', 'confirm-button-class'],
  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. confirmButtonId: String,
  24. className: String,
  25. customStyle: String,
  26. asyncClose: Boolean,
  27. messageAlign: String,
  28. beforeClose: null,
  29. overlayStyle: String,
  30. useSlot: Boolean,
  31. useTitleSlot: Boolean,
  32. useConfirmButtonSlot: Boolean,
  33. useCancelButtonSlot: Boolean,
  34. showCancelButton: Boolean,
  35. closeOnClickOverlay: Boolean,
  36. confirmButtonOpenType: String,
  37. width: null,
  38. zIndex: {
  39. type: Number,
  40. value: 2000,
  41. },
  42. confirmButtonText: {
  43. type: String,
  44. value: '确认',
  45. },
  46. cancelButtonText: {
  47. type: String,
  48. value: '取消',
  49. },
  50. confirmButtonColor: {
  51. type: String,
  52. value: color_1.RED,
  53. },
  54. cancelButtonColor: {
  55. type: String,
  56. value: color_1.GRAY,
  57. },
  58. showConfirmButton: {
  59. type: Boolean,
  60. value: true,
  61. },
  62. overlay: {
  63. type: Boolean,
  64. value: true,
  65. },
  66. transition: {
  67. type: String,
  68. value: 'scale',
  69. },
  70. rootPortal: {
  71. type: Boolean,
  72. value: false,
  73. },
  74. },
  75. data: {
  76. loading: {
  77. confirm: false,
  78. cancel: false,
  79. },
  80. callback: (function () { }),
  81. },
  82. methods: {
  83. onConfirm: function () {
  84. this.handleAction('confirm');
  85. },
  86. onCancel: function () {
  87. this.handleAction('cancel');
  88. },
  89. onClickOverlay: function () {
  90. this.close('overlay');
  91. },
  92. close: function (action) {
  93. var _this = this;
  94. this.setData({ show: false });
  95. wx.nextTick(function () {
  96. _this.$emit('close', action);
  97. var callback = _this.data.callback;
  98. if (callback) {
  99. callback(action, _this);
  100. }
  101. });
  102. },
  103. stopLoading: function () {
  104. this.setData({
  105. loading: {
  106. confirm: false,
  107. cancel: false,
  108. },
  109. });
  110. },
  111. handleAction: function (action) {
  112. var _a;
  113. var _this = this;
  114. this.$emit(action, { dialog: this });
  115. var _b = this.data, asyncClose = _b.asyncClose, beforeClose = _b.beforeClose;
  116. if (!asyncClose && !beforeClose) {
  117. this.close(action);
  118. return;
  119. }
  120. this.setData((_a = {},
  121. _a["loading.".concat(action)] = true,
  122. _a));
  123. if (beforeClose) {
  124. (0, utils_1.toPromise)(beforeClose(action)).then(function (value) {
  125. if (value) {
  126. _this.close(action);
  127. }
  128. else {
  129. _this.stopLoading();
  130. }
  131. });
  132. }
  133. },
  134. },
  135. });