index.js 2.7 KB

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