drawer.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <view
  3. class="tui-drawer-class tui-drawer"
  4. :class="[visible ? 'tui-drawer-show' : '', 'tui-drawer-' + mode]"
  5. >
  6. <view
  7. v-if="mask"
  8. class="tui-drawer-mask"
  9. @tap="handleMaskClick"
  10. @touchmove.stop.prevent
  11. ></view>
  12. <view class="tui-drawer-container" @touchmove.stop.prevent>
  13. <slot></slot>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  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. mode: {
  34. type: String,
  35. default: 'left' // left right
  36. }
  37. },
  38. methods: {
  39. handleMaskClick() {
  40. if (!this.maskClosable) {
  41. return;
  42. }
  43. this.$emit('close', {});
  44. }
  45. }
  46. };
  47. </script>
  48. <style>
  49. .tui-drawer {
  50. visibility: hidden;
  51. }
  52. .tui-drawer-show {
  53. visibility: visible;
  54. }
  55. .tui-drawer-show .tui-drawer-mask {
  56. display: block;
  57. opacity: 1;
  58. }
  59. .tui-drawer-show .tui-drawer-container {
  60. opacity: 1;
  61. }
  62. .tui-drawer-show.tui-drawer-left .tui-drawer-container,
  63. .tui-drawer-show.tui-drawer-right .tui-drawer-container {
  64. transform: translate3d(0, -50%, 0);
  65. }
  66. .tui-drawer-mask {
  67. opacity: 0;
  68. position: fixed;
  69. top: 0;
  70. left: 0;
  71. right: 0;
  72. bottom: 0;
  73. z-index: 8888;
  74. background: rgba(0, 0, 0, 0.6);
  75. transition: all 0.3s ease-in-out;
  76. }
  77. .tui-drawer-container {
  78. position: fixed;
  79. left: 50%;
  80. height: 100.2%;
  81. top: 0;
  82. transform: translate3d(-50%, -50%, 0);
  83. transform-origin: center;
  84. transition: all 0.3s ease-in-out;
  85. z-index: 99999;
  86. opacity: 0;
  87. overflow-y: scroll;
  88. background: #fff;
  89. -webkit-overflow-scrolling: touch;
  90. -ms-touch-action: pan-y cross-slide-y;
  91. -ms-scroll-chaining: none;
  92. -ms-scroll-limit: 0 50 0 50;
  93. }
  94. .tui-drawer-left .tui-drawer-container {
  95. left: 0;
  96. top: 50%;
  97. transform: translate3d(-100%, -50%, 0);
  98. }
  99. .tui-drawer-right .tui-drawer-container {
  100. right: 0;
  101. top: 50%;
  102. left: auto;
  103. transform: translate3d(100%, -50%, 0);
  104. }
  105. </style>