index.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { VantComponent } from '../common/component';
  2. import { transition } from '../mixins/transition';
  3. VantComponent({
  4. classes: [
  5. 'enter-class',
  6. 'enter-active-class',
  7. 'enter-to-class',
  8. 'leave-class',
  9. 'leave-active-class',
  10. 'leave-to-class',
  11. 'close-icon-class',
  12. ],
  13. mixins: [transition(false)],
  14. props: {
  15. round: Boolean,
  16. closeable: Boolean,
  17. customStyle: String,
  18. overlayStyle: String,
  19. transition: {
  20. type: String,
  21. observer: 'observeClass',
  22. },
  23. zIndex: {
  24. type: Number,
  25. value: 100,
  26. },
  27. overlay: {
  28. type: Boolean,
  29. value: true,
  30. },
  31. closeIcon: {
  32. type: String,
  33. value: 'cross',
  34. },
  35. closeIconPosition: {
  36. type: String,
  37. value: 'top-right',
  38. },
  39. closeOnClickOverlay: {
  40. type: Boolean,
  41. value: true,
  42. },
  43. position: {
  44. type: String,
  45. value: 'center',
  46. observer: 'observeClass',
  47. },
  48. safeAreaInsetBottom: {
  49. type: Boolean,
  50. value: true,
  51. },
  52. safeAreaInsetTop: {
  53. type: Boolean,
  54. value: false,
  55. },
  56. safeAreaTabBar: {
  57. type: Boolean,
  58. value: false,
  59. },
  60. lockScroll: {
  61. type: Boolean,
  62. value: true,
  63. },
  64. rootPortal: {
  65. type: Boolean,
  66. value: false,
  67. },
  68. },
  69. created() {
  70. this.observeClass();
  71. },
  72. methods: {
  73. onClickCloseIcon() {
  74. this.$emit('close');
  75. },
  76. onClickOverlay() {
  77. this.$emit('click-overlay');
  78. if (this.data.closeOnClickOverlay) {
  79. this.$emit('close');
  80. }
  81. },
  82. observeClass() {
  83. const { transition, position, duration } = this.data;
  84. const updateData = {
  85. name: transition || position,
  86. };
  87. if (transition === 'none') {
  88. updateData.duration = 0;
  89. this.originDuration = duration;
  90. }
  91. else if (this.originDuration != null) {
  92. updateData.duration = this.originDuration;
  93. }
  94. this.setData(updateData);
  95. },
  96. },
  97. });