tui-top-dropdown.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. 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: '#f2f2f2'
  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. },
  53. methods: {
  54. handleClose() {
  55. if (!this.show) {
  56. return;
  57. }
  58. this.$emit('close', {});
  59. },
  60. px(num) {
  61. return uni.upx2px(num) + 'px';
  62. }
  63. }
  64. };
  65. </script>
  66. <style scoped>
  67. .tui-dropdown-box {
  68. width: 100%;
  69. position: fixed;
  70. box-sizing: border-box;
  71. border-bottom-right-radius: 24rpx;
  72. border-bottom-left-radius: 24rpx;
  73. transform: translateZ(0);
  74. overflow: hidden;
  75. /* visibility: hidden; */
  76. transition: all 0.3s ease-in-out;
  77. z-index: 996;
  78. top: 0;
  79. }
  80. .tui-dropdown-show {
  81. /* visibility: visible; */
  82. }
  83. .tui-dropdown-mask {
  84. position: fixed;
  85. top: 0;
  86. left: 0;
  87. right: 0;
  88. bottom: 0;
  89. background-color: rgba(0, 0, 0, 0.6);
  90. z-index: 986;
  91. transition: all 0.3s ease-in-out;
  92. opacity: 0;
  93. visibility: hidden;
  94. }
  95. .tui-mask-show {
  96. opacity: 1;
  97. visibility: visible;
  98. }
  99. </style>