tui-drawer.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <!-- @touchmove.stop.prevent -->
  3. <view>
  4. <view v-if="mask" class="tui-drawer-mask" :class="{ 'tui-drawer-mask_show': visible }" :style="{ zIndex: maskZIndex }" @tap="handleMaskClick"></view>
  5. <view
  6. class="tui-drawer-container"
  7. :class="[`tui-drawer-container_${mode}`, visible ? `tui-drawer-${mode}__show` : '']"
  8. :style="{ zIndex: zIndex, backgroundColor: backgroundColor }"
  9. >
  10. <slot></slot>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. /**
  16. * 超过一屏时插槽使用scroll-view
  17. **/
  18. export default {
  19. name: 'tuiDrawer',
  20. emits: ['close'],
  21. props: {
  22. visible: {
  23. type: Boolean,
  24. default: false
  25. },
  26. mask: {
  27. type: Boolean,
  28. default: true
  29. },
  30. maskClosable: {
  31. type: Boolean,
  32. default: true
  33. },
  34. // left right bottom top
  35. mode: {
  36. type: String,
  37. default: 'right'
  38. },
  39. //drawer z-index
  40. zIndex: {
  41. type: [Number, String],
  42. default: 9999
  43. },
  44. //mask z-index
  45. maskZIndex: {
  46. type: [Number, String],
  47. default: 9998
  48. },
  49. backgroundColor: {
  50. type: String,
  51. default: '#fff'
  52. }
  53. },
  54. methods: {
  55. handleMaskClick() {
  56. if (!this.maskClosable) {
  57. return;
  58. }
  59. this.$emit('close', {});
  60. }
  61. }
  62. };
  63. </script>
  64. <style scoped>
  65. .tui-drawer-mask {
  66. opacity: 0;
  67. visibility: hidden;
  68. position: fixed;
  69. top: 0;
  70. left: 0;
  71. right: 0;
  72. bottom: 0;
  73. background-color: rgba(0, 0, 0, 0.6);
  74. transition: all 0.3s ease-in-out;
  75. }
  76. .tui-drawer-mask_show {
  77. display: block;
  78. visibility: visible;
  79. opacity: 1;
  80. }
  81. .tui-drawer-container {
  82. position: fixed;
  83. left: 50%;
  84. height: 100.2%;
  85. top: 0;
  86. transform: translate3d(-50%, -50%, 0);
  87. transform-origin: center;
  88. transition: all 0.3s ease-in-out;
  89. opacity: 0;
  90. overflow-y: scroll;
  91. -webkit-overflow-scrolling: touch;
  92. -ms-touch-action: pan-y cross-slide-y;
  93. -ms-scroll-chaining: none;
  94. -ms-scroll-limit: 0 50 0 50;
  95. }
  96. .tui-drawer-container_left {
  97. left: 0;
  98. top: 50%;
  99. transform: translate3d(-100%, -50%, 0);
  100. }
  101. .tui-drawer-container_right {
  102. right: 0;
  103. top: 50%;
  104. left: auto;
  105. transform: translate3d(100%, -50%, 0);
  106. }
  107. .tui-drawer-container_bottom,
  108. .tui-drawer-container_top {
  109. width: 100%;
  110. height: auto !important;
  111. min-height: 20rpx;
  112. left: 0;
  113. right: 0;
  114. transform-origin: center;
  115. transition: all 0.3s ease-in-out;
  116. }
  117. .tui-drawer-container_bottom {
  118. bottom: 0;
  119. top: auto;
  120. transform: translate3d(0, 100%, 0);
  121. }
  122. .tui-drawer-container_top {
  123. transform: translate3d(0, -100%, 0);
  124. }
  125. .tui-drawer-left__show,
  126. .tui-drawer-right__show {
  127. opacity: 1;
  128. transform: translate3d(0, -50%, 0);
  129. }
  130. .tui-drawer-top__show,
  131. .tui-drawer-bottom__show {
  132. opacity: 1;
  133. transform: translate3d(0, 0, 0);
  134. }
  135. </style>