tui-bottom-popup.vue 2.0 KB

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