tui-drawer.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <view @touchmove.stop.prevent>
  3. <view v-if="mask" class="tui-drawer-mask" :class="{'tui-drawer-mask_show':visible}" @tap="handleMaskClick"></view>
  4. <view class="tui-drawer-container" :class="[mode=='left'?'tui-drawer-container_left':'tui-drawer-container_right',visible?'tui-drawer-container_show':'']">
  5. <slot></slot>
  6. </view>
  7. </view>
  8. </template>
  9. <script>
  10. /**
  11. * 超过一屏时插槽使用scroll-view
  12. **/
  13. export default {
  14. name:"tuiDrawer",
  15. props: {
  16. visible: {
  17. type: Boolean,
  18. default: false
  19. },
  20. mask: {
  21. type: Boolean,
  22. default: true
  23. },
  24. maskClosable: {
  25. type: Boolean,
  26. default: true
  27. },
  28. mode: {
  29. type: String,
  30. default: 'true' // left right
  31. }
  32. },
  33. methods: {
  34. handleMaskClick() {
  35. if (!this.maskClosable) {
  36. return;
  37. }
  38. this.$emit('close', {});
  39. }
  40. }
  41. }
  42. </script>
  43. <style scoped>
  44. .tui-drawer-mask {
  45. opacity: 0;
  46. visibility: hidden;
  47. position: fixed;
  48. top: 0;
  49. left: 0;
  50. right: 0;
  51. bottom: 0;
  52. z-index: 8888;
  53. background-color: rgba(0, 0, 0, 0.6);
  54. transition: all 0.3s ease-in-out;
  55. }
  56. .tui-drawer-mask_show {
  57. display: block;
  58. visibility: visible;
  59. opacity: 1;
  60. }
  61. .tui-drawer-container {
  62. position: fixed;
  63. left: 50%;
  64. height: 100.2%;
  65. top: 0;
  66. transform: translate3d(-50%, -50%, 0);
  67. transform-origin: center;
  68. transition: all 0.3s ease-in-out;
  69. z-index: 99999;
  70. opacity: 0;
  71. overflow-y: scroll;
  72. background-color: #fff;
  73. -webkit-overflow-scrolling: touch;
  74. -ms-touch-action: pan-y cross-slide-y;
  75. -ms-scroll-chaining: none;
  76. -ms-scroll-limit: 0 50 0 50;
  77. }
  78. .tui-drawer-container_left {
  79. left: 0;
  80. top: 50%;
  81. transform: translate3d(-100%, -50%, 0);
  82. }
  83. .tui-drawer-container_right {
  84. right: 0;
  85. top: 50%;
  86. left: auto;
  87. transform: translate3d(100%, -50%, 0);
  88. }
  89. .tui-drawer-container_show {
  90. opacity: 1;
  91. transform: translate3d(0, -50%, 0);
  92. }
  93. </style>