dt-dropdown.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view>
  3. <view @click="showShadow" class="dropWrap">{{title}}
  4. <!-- <view class="sanjiao"></view> -->
  5. <uni-icons class='icon' type="arrowdown" v-if="!showIf"></uni-icons>
  6. <uni-icons class='icon' type="arrowup" v-else></uni-icons>
  7. </view>
  8. <view class="dropdown">
  9. <view :class="showIf ? 'dropdown-mask' : 'undropdown-mask'" @click="hideShadow"></view>
  10. <!-- <view class="ul" :style="showIf?'height:'+list.length*30+'px':''"> -->
  11. <view class="ul" :style="'--i:'+list.length" :class="showIf?'show':''">
  12. <!-- 不支持就用上面那种 -->
  13. <view class="li" v-for="(item, index) in list" :key="index" @click="handlerItem(item)">{{ item.name }}
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. name: 'dropdown',
  22. props: {
  23. list: {
  24. type: Array,
  25. default: () => []
  26. },
  27. current: {
  28. type: [String, Number],
  29. default: 0
  30. },
  31. title: {
  32. type: String,
  33. default: '全局操作'
  34. }
  35. },
  36. data() {
  37. return {
  38. showIf: false
  39. };
  40. },
  41. methods: {
  42. handlerItem(value) {
  43. this.showIf = false
  44. console.log(value)
  45. this.$emit('onClick', value);
  46. },
  47. hideShadow() {
  48. this.showIf = false;
  49. },
  50. showShadow() {
  51. this.showIf = true;
  52. // this.$emit('titleClick', value);
  53. }
  54. }
  55. };
  56. </script>
  57. <style scoped lang="scss">
  58. .dropWrap {
  59. box-sizing: border-box;
  60. // width: 96px;
  61. // height: 26px;
  62. // border: 1px solid #e8ecef;
  63. font-size: 12px;
  64. color: #666666;
  65. padding: 4px 8px;
  66. display: flex;
  67. align-items: center;
  68. justify-content: space-between;
  69. .icon {
  70. font-size: 20rpx;
  71. padding-left: 10rpx;
  72. color: rgba(216, 216, 216, 1) !important;
  73. }
  74. // .sanjiao {
  75. // width: 0;
  76. // height: 0;
  77. // border-left: 6px solid transparent;
  78. // border-right: 6px solid transparent;
  79. // border-top: 6px solid #C5CFD5;
  80. // border-bottom: 6px solid transparent;
  81. // transform: translateY(3px);
  82. // }
  83. }
  84. .dropdown {
  85. position: absolute;
  86. z-index: 100;
  87. .ul {
  88. width: 136rpx;
  89. position: relative;
  90. z-index: 101;
  91. list-style: none;
  92. background-color: #fff;
  93. border-radius: 4rpx;
  94. padding-left: 0;
  95. box-shadow: 6rpx 6rpx 10rpx rgba(122, 122, 122, 0.2);
  96. transition: all 0.2s;
  97. height: 0;
  98. overflow: hidden;
  99. .li {
  100. box-sizing: border-box;
  101. color: #000;
  102. height: 30px;
  103. // border-bottom: 1px solid #e6eaeb;
  104. font-size: 24rpx;
  105. line-height: 30px; //与下面的高度保持一致
  106. padding-left: 8px;
  107. text-align: center;
  108. &:hover {
  109. background-color: rgba(243, 243, 243, 1);
  110. }
  111. }
  112. // .li:last-child {
  113. // border-bottom: none;
  114. // }
  115. }
  116. .show {
  117. height: calc(var(--i) * 30px); //与上面的高度保持一致
  118. }
  119. .dropdown-mask {
  120. top: 0;
  121. left: 0;
  122. position: fixed;
  123. width: 100vw;
  124. height: 100vh;
  125. z-index: 100;
  126. pointer-events: auto;
  127. }
  128. .undropdown-mask {
  129. pointer-events: none;
  130. }
  131. }
  132. </style>