index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  17. // +----------------------------------------------------------------------
  18. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  19. // +----------------------------------------------------------------------
  20. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  21. // +----------------------------------------------------------------------
  22. // | Author: CRMEB Team <admin@crmeb.com>
  23. // +----------------------------------------------------------------------
  24. /**
  25. * 超过一屏时插槽使用scroll-view
  26. **/
  27. export default {
  28. name: 'tuiDrawer',
  29. emits: ['close'],
  30. props: {
  31. visible: {
  32. type: Boolean,
  33. default: false
  34. },
  35. mask: {
  36. type: Boolean,
  37. default: true
  38. },
  39. maskClosable: {
  40. type: Boolean,
  41. default: true
  42. },
  43. // left right bottom top
  44. mode: {
  45. type: String,
  46. default: 'right'
  47. },
  48. //drawer z-index
  49. zIndex: {
  50. type: [Number, String],
  51. default: 9999
  52. },
  53. //mask z-index
  54. maskZIndex: {
  55. type: [Number, String],
  56. default: 9998
  57. },
  58. backgroundColor: {
  59. type: String,
  60. default: '#fff'
  61. }
  62. },
  63. methods: {
  64. handleMaskClick() {
  65. if (!this.maskClosable) {
  66. return;
  67. }
  68. this.$emit('close', {});
  69. }
  70. }
  71. };
  72. </script>
  73. <style scoped>
  74. .tui-drawer-mask {
  75. opacity: 0;
  76. visibility: hidden;
  77. position: fixed;
  78. top: 0;
  79. left: 0;
  80. right: 0;
  81. bottom: 0;
  82. background-color: rgba(0, 0, 0, 0.6);
  83. transition: all 0.3s ease-in-out;
  84. }
  85. .tui-drawer-mask_show {
  86. display: block;
  87. visibility: visible;
  88. opacity: 1;
  89. }
  90. .tui-drawer-container {
  91. position: fixed;
  92. left: 50%;
  93. height: 100.2%;
  94. top: 0;
  95. transform: translate3d(-50%, -50%, 0);
  96. transform-origin: center;
  97. transition: all 0.3s ease-in-out;
  98. opacity: 0;
  99. overflow-y: scroll;
  100. -webkit-overflow-scrolling: touch;
  101. -ms-touch-action: pan-y cross-slide-y;
  102. -ms-scroll-chaining: none;
  103. -ms-scroll-limit: 0 50 0 50;
  104. }
  105. .tui-drawer-container_left {
  106. left: 0;
  107. top: 50%;
  108. transform: translate3d(-100%, -50%, 0);
  109. }
  110. .tui-drawer-container_right {
  111. right: 0;
  112. top: 50%;
  113. left: auto;
  114. transform: translate3d(100%, -50%, 0);
  115. }
  116. .tui-drawer-container_bottom,
  117. .tui-drawer-container_top {
  118. width: 100%;
  119. height: auto !important;
  120. min-height: 20rpx;
  121. left: 0;
  122. right: 0;
  123. transform-origin: center;
  124. transition: all 0.3s ease-in-out;
  125. }
  126. .tui-drawer-container_bottom {
  127. bottom: 0;
  128. top: auto;
  129. transform: translate3d(0, 100%, 0);
  130. }
  131. .tui-drawer-container_top {
  132. transform: translate3d(0, -100%, 0);
  133. }
  134. .tui-drawer-left__show,
  135. .tui-drawer-right__show {
  136. opacity: 1;
  137. transform: translate3d(0, -50%, 0);
  138. }
  139. .tui-drawer-top__show,
  140. .tui-drawer-bottom__show {
  141. opacity: 1;
  142. transform: translate3d(0, 0, 0);
  143. }
  144. </style>