index.js 3.6 KB

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