bottom-popup.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <view @touchmove.stop.prevent>
  3. <view class="tui-popup-class tui-bottom-popup" :class="{'tui-popup-show':show}" :style="{background:bgcolor,height:height?height+'upx':'auto'}">
  4. <slot></slot>
  5. </view>
  6. <view class="tui-popup-mask" :style="{background: maskBgcolor}" :class="[show?'tui-mask-show':'']" 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. bgcolor: {
  25. type: String,
  26. default: '#fff'
  27. },
  28. // 蒙版背景颜色
  29. maskBgcolor: {
  30. type: String,
  31. default: 'rgba(0, 0, 0, 0.6)'
  32. },
  33. // 高度 upx
  34. height: {
  35. type: Number,
  36. default: 0
  37. }
  38. },
  39. methods: {
  40. handleClose() {
  41. if (!this.show) {
  42. return
  43. }
  44. this.$emit('close', {})
  45. }
  46. }
  47. }
  48. </script>
  49. <style lang="scss" scoped>
  50. .tui-bottom-popup {
  51. width: 100%;
  52. position: fixed;
  53. left: 0;
  54. right: 0;
  55. bottom: 0;
  56. z-index: 999;
  57. visibility: hidden;
  58. transform: translate3d(0, 100%, 0);
  59. transform-origin: center;
  60. transition: all 0.3s ease-in-out;
  61. min-height: 20upx;
  62. // 适配iphoneX
  63. padding-bottom: env(safe-area-inset-bottom);
  64. }
  65. .tui-popup-show {
  66. transform: translate3d(0, 0, 0);
  67. visibility: visible;
  68. }
  69. .tui-popup-mask {
  70. position: fixed;
  71. top: 0;
  72. left: 0;
  73. right: 0;
  74. bottom: 0;
  75. background: rgba(0, 0, 0, 0.6);
  76. z-index: 996;
  77. transition: all 0.3s ease-in-out;
  78. opacity: 0;
  79. visibility: hidden;
  80. }
  81. .tui-mask-show {
  82. opacity: 1;
  83. visibility: visible;
  84. }
  85. </style>