index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 = {},
  82. _a["loading." + action] = true,
  83. _a));
  84. }
  85. this.onClose(action);
  86. },
  87. close: function () {
  88. this.setData({
  89. show: false
  90. });
  91. },
  92. stopLoading: function () {
  93. this.setData({
  94. loading: {
  95. confirm: false,
  96. cancel: false
  97. }
  98. });
  99. },
  100. onClose: function (action) {
  101. if (!this.data.asyncClose) {
  102. this.close();
  103. }
  104. this.$emit('close', action);
  105. // 把 dialog 实例传递出去,可以通过 stopLoading() 在外部关闭按钮的 loading
  106. this.$emit(action, { dialog: this });
  107. var callback = this.data[action === 'confirm' ? 'onConfirm' : 'onCancel'];
  108. if (callback) {
  109. callback(this);
  110. }
  111. }
  112. }
  113. });