menuTopDropdown.vue 1.9 KB

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