index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. this.setData({ show: false });
  94. this.closeAction = action;
  95. },
  96. onAfterLeave: function () {
  97. var action = this.closeAction;
  98. this.$emit('close', action);
  99. var callback = this.data.callback;
  100. if (callback) {
  101. callback(action, this);
  102. }
  103. },
  104. stopLoading: function () {
  105. this.setData({
  106. loading: {
  107. confirm: false,
  108. cancel: false,
  109. },
  110. });
  111. },
  112. handleAction: function (action) {
  113. var _a;
  114. var _this = this;
  115. this.$emit(action, { dialog: this });
  116. var _b = this.data, asyncClose = _b.asyncClose, beforeClose = _b.beforeClose;
  117. if (!asyncClose && !beforeClose) {
  118. this.close(action);
  119. return;
  120. }
  121. this.setData((_a = {},
  122. _a["loading.".concat(action)] = true,
  123. _a));
  124. if (beforeClose) {
  125. (0, utils_1.toPromise)(beforeClose(action)).then(function (value) {
  126. if (value) {
  127. _this.close(action);
  128. }
  129. else {
  130. _this.stopLoading();
  131. }
  132. });
  133. }
  134. },
  135. },
  136. });