tui-drawer.vue 2.5 KB

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