index.js 2.8 KB

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