tui-bottom-popup.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view @touchmove.stop.prevent>
  3. <view class="tui-popup-class tui-bottom-popup" :class="{ 'tui-popup-show': show, 'tui-popup-radius': radius }" :style="{ background: backgroundColor, height: height ? height + 'rpx' : 'auto', zIndex: zIndex,transform:`translate3d(0, ${show?translateY:'100%'}, 0)`}">
  4. <slot></slot>
  5. </view>
  6. <view class="tui-popup-mask" :class="[show ? 'tui-mask-show' : '']" :style="{ zIndex: maskZIndex }" v-if="mask" @tap="handleClose"></view>
  7. </view>
  8. </template>
  9. <script>
  10. export default {
  11. name: 'tuiBottomPopup',
  12. emits: ['close'],
  13. props: {
  14. //是否需要mask
  15. mask: {
  16. type: Boolean,
  17. default: true
  18. },
  19. //控制显示
  20. show: {
  21. type: Boolean,
  22. default: false
  23. },
  24. //背景颜色
  25. backgroundColor: {
  26. type: String,
  27. default: '#fff'
  28. },
  29. //高度 rpx
  30. height: {
  31. type: Number,
  32. default: 0
  33. },
  34. //设置圆角
  35. radius: {
  36. type: Boolean,
  37. default: true
  38. },
  39. zIndex: {
  40. type: [Number, String],
  41. default: 997
  42. },
  43. maskZIndex: {
  44. type: [Number, String],
  45. default: 996
  46. },
  47. //弹层显示时,垂直方向移动的距离
  48. translateY: {
  49. type: String,
  50. default: '0'
  51. }
  52. },
  53. methods: {
  54. handleClose() {
  55. if (!this.show) {
  56. return;
  57. }
  58. this.$emit('close', {});
  59. }
  60. }
  61. };
  62. </script>
  63. <style scoped>
  64. .tui-bottom-popup {
  65. width: 100%;
  66. position: fixed;
  67. left: 0;
  68. right: 0;
  69. bottom: 0;
  70. opacity: 0;
  71. transform: translate3d(0, 100%, 0);
  72. transform-origin: center;
  73. transition: all 0.3s ease-in-out;
  74. min-height: 20rpx;
  75. padding-bottom: env(safe-area-inset-bottom);
  76. }
  77. .tui-popup-radius {
  78. border-top-left-radius: 24rpx;
  79. border-top-right-radius: 24rpx;
  80. overflow: hidden;
  81. }
  82. .tui-popup-show {
  83. opacity: 1;
  84. /* transform: translate3d(0, 0, 0); */
  85. }
  86. .tui-popup-mask {
  87. position: fixed;
  88. top: 0;
  89. left: 0;
  90. right: 0;
  91. bottom: 0;
  92. background-color: rgba(0, 0, 0, 0.6);
  93. transition: all 0.3s ease-in-out;
  94. opacity: 0;
  95. visibility: hidden;
  96. }
  97. .tui-mask-show {
  98. opacity: 1;
  99. visibility: visible;
  100. }
  101. </style>