index.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. background: bgcolor,
  9. paddingBottom: px(paddingbtm),
  10. transform:
  11. 'translateZ(0) translateY(' + (show ? px(translatey) : '-100%') + ')'
  12. }"
  13. >
  14. <slot></slot>
  15. </view>
  16. <view
  17. class="tui-dropdown-mask"
  18. :class="[mask && show ? 'tui-mask-show' : '']"
  19. @tap="handleClose"
  20. ></view>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. name: 'tuiTopDropdown',
  26. props: {
  27. // 是否需要mask
  28. mask: {
  29. type: Boolean,
  30. default: true
  31. },
  32. // 控制显示
  33. show: {
  34. type: Boolean,
  35. default: false
  36. },
  37. // 背景颜色
  38. bgcolor: {
  39. type: String,
  40. default: '#f2f2f2'
  41. },
  42. // padding-bottom rpx
  43. paddingbtm: {
  44. type: Number,
  45. default: 0
  46. },
  47. // 高度 upx
  48. height: {
  49. type: Number,
  50. default: 580
  51. },
  52. // 移动距离 需要计算
  53. translatey: {
  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>
  72. .tui-dropdown-box {
  73. width: 100%;
  74. position: fixed;
  75. box-sizing: border-box;
  76. border-bottom-right-radius: 24upx;
  77. border-bottom-left-radius: 24upx;
  78. transform: translateZ(0);
  79. overflow: hidden;
  80. visibility: hidden;
  81. transition: all 0.3s ease-in-out;
  82. z-index: 989;
  83. top: 0;
  84. }
  85. .tui-dropdown-show {
  86. visibility: visible;
  87. }
  88. .tui-dropdown-mask {
  89. position: fixed;
  90. top: 0;
  91. left: 0;
  92. right: 0;
  93. bottom: 0;
  94. background: 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. .tui-mask-show {
  101. opacity: 1;
  102. visibility: visible;
  103. }
  104. </style>