index.js 2.6 KB

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