tui-top-dropdown.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <view>
  3. <view
  4. class="tui-top-dropdown tui-dropdown-box"
  5. :class="[show ? 'tui-dropdown-show' : '']"
  6. :style="{
  7. height: height ? px(height) : 'auto',
  8. backgroundColor: backgroundColor,
  9. paddingBottom: px(paddingbtm),
  10. transform: 'translateZ(0) translateY(' + (show ? px(translatey) : '-100%') + ')'
  11. }"
  12. >
  13. <slot></slot>
  14. </view>
  15. <view @touchmove.stop.prevent class="tui-dropdown-mask" :class="[mask && show ? 'tui-mask-show' : '']" @tap="handleClose"></view>
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. name: 'tuiTopDropdown',
  21. emits: ['close'],
  22. props: {
  23. //是否需要mask
  24. mask: {
  25. type: Boolean,
  26. default: true
  27. },
  28. //控制显示
  29. show: {
  30. type: Boolean,
  31. default: false
  32. },
  33. //背景颜色
  34. backgroundColor: {
  35. type: String,
  36. default: '#f2f2f2'
  37. },
  38. //padding-bottom rpx
  39. paddingbtm: {
  40. type: Number,
  41. default: 0
  42. },
  43. //高度 rpx
  44. height: {
  45. type: Number,
  46. default: 580
  47. },
  48. //移动距离 需要计算
  49. translatey: {
  50. type: Number,
  51. default: 0
  52. }
  53. },
  54. methods: {
  55. handleClose() {
  56. if (!this.show) {
  57. return;
  58. }
  59. this.$emit('close', {});
  60. },
  61. px(num) {
  62. return uni.upx2px(num) + 'px';
  63. }
  64. }
  65. };
  66. </script>
  67. <style scoped>
  68. .tui-dropdown-box {
  69. width: 100%;
  70. position: fixed;
  71. box-sizing: border-box;
  72. border-bottom-right-radius: 24rpx;
  73. border-bottom-left-radius: 24rpx;
  74. transform: translateZ(0);
  75. overflow: hidden;
  76. /* visibility: hidden; */
  77. transition: all 0.3s ease-in-out;
  78. z-index: 996;
  79. top: 0;
  80. }
  81. .tui-dropdown-show {
  82. /* visibility: visible; */
  83. }
  84. .tui-dropdown-mask {
  85. position: fixed;
  86. top: 0;
  87. left: 0;
  88. right: 0;
  89. bottom: 0;
  90. background-color: rgba(0, 0, 0, 0.6);
  91. z-index: 986;
  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>