top-dropdown.vue 1.7 KB

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