index.js 2.0 KB

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