tui-drawer.vue 2.6 KB

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