index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. component_1.VantComponent({
  8. mixins: [button_1.button, open_type_1.openType],
  9. props: {
  10. show: {
  11. type: Boolean,
  12. observer: function (show) {
  13. !show && this.stopLoading();
  14. },
  15. },
  16. title: String,
  17. message: String,
  18. theme: {
  19. type: String,
  20. value: 'default',
  21. },
  22. useSlot: Boolean,
  23. className: String,
  24. customStyle: String,
  25. asyncClose: Boolean,
  26. messageAlign: String,
  27. overlayStyle: String,
  28. useTitleSlot: Boolean,
  29. showCancelButton: Boolean,
  30. closeOnClickOverlay: Boolean,
  31. confirmButtonOpenType: String,
  32. width: null,
  33. zIndex: {
  34. type: Number,
  35. value: 2000,
  36. },
  37. confirmButtonText: {
  38. type: String,
  39. value: '确认',
  40. },
  41. cancelButtonText: {
  42. type: String,
  43. value: '取消',
  44. },
  45. confirmButtonColor: {
  46. type: String,
  47. value: color_1.RED,
  48. },
  49. cancelButtonColor: {
  50. type: String,
  51. value: color_1.GRAY,
  52. },
  53. showConfirmButton: {
  54. type: Boolean,
  55. value: true,
  56. },
  57. overlay: {
  58. type: Boolean,
  59. value: true,
  60. },
  61. transition: {
  62. type: String,
  63. value: 'scale',
  64. },
  65. },
  66. data: {
  67. loading: {
  68. confirm: false,
  69. cancel: false,
  70. },
  71. },
  72. methods: {
  73. onConfirm: function () {
  74. this.handleAction('confirm');
  75. },
  76. onCancel: function () {
  77. this.handleAction('cancel');
  78. },
  79. onClickOverlay: function () {
  80. this.onClose('overlay');
  81. },
  82. handleAction: function (action) {
  83. var _a;
  84. if (this.data.asyncClose) {
  85. this.setData(((_a = {}), (_a['loading.' + action] = true), _a));
  86. }
  87. this.onClose(action);
  88. },
  89. close: function () {
  90. this.setData({
  91. show: false,
  92. });
  93. },
  94. stopLoading: function () {
  95. this.setData({
  96. loading: {
  97. confirm: false,
  98. cancel: false,
  99. },
  100. });
  101. },
  102. onClose: function (action) {
  103. if (!this.data.asyncClose) {
  104. this.close();
  105. }
  106. this.$emit('close', action);
  107. // 把 dialog 实例传递出去,可以通过 stopLoading() 在外部关闭按钮的 loading
  108. this.$emit(action, { dialog: this });
  109. var callback = this.data[action === 'confirm' ? 'onConfirm' : 'onCancel'];
  110. if (callback) {
  111. callback(this);
  112. }
  113. },
  114. },
  115. });