index.js 2.5 KB

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