selectInput.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <view class="mask" @tap="clickMask" :class="show?'mask-show':''">
  3. <view style="position: relative;top:0;left:0;text-align:right">
  4. <view class="triangle" :style="{'top':triangle_styles}" ></view>
  5. </view>
  6. <view class="uni-combox__selector" :style="{'top':__selector_styles}" >
  7. <scroll-view scroll-y="true" class="uni-combox__selector-scroll">
  8. <view class="uni-combox__selector-item" v-for="(item, index) in list" :key="index" @tap.stop="onSelectorClick(index)" hover-class="select-hover-class" >
  9. <u-icon :name="item.icon" v-if="item.icon" class="uni-combox__selector-item-icon"></u-icon>
  10. <text>{{ item[listKey] }}</text>
  11. </view>
  12. </scroll-view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. props: {
  19. list: {
  20. type: Array,
  21. default() {
  22. return [];
  23. }
  24. },
  25. listKey: {
  26. type: String,
  27. default: ''
  28. },
  29. show: {
  30. type: Boolean,
  31. default: false
  32. }
  33. },
  34. watch: {
  35. show(val) {
  36. val && this.$emit('on-open');
  37. }
  38. },
  39. data() {
  40. return {
  41. statusBarHeight:0
  42. };
  43. },
  44. methods: {
  45. onSelectorClick(index) {
  46. setTimeout(()=>{
  47. this.$emit('on-select',index)
  48. this.clickMask();
  49. },80)
  50. },
  51. clickMask() {
  52. this.$emit('update:show')
  53. // #ifdef MP-WEIXIN
  54. this.$emit('close',false)
  55. // #endif
  56. }
  57. },
  58. created() {
  59. uni.getSystemInfo({
  60. success:(res)=>{
  61. //状态栏的高度 将用来适配刘海屏
  62. this.statusBarHeight = res.statusBarHeight;
  63. }
  64. })
  65. },
  66. computed:{
  67. __selector_styles(){
  68. // #ifdef MP-WEIXIN
  69. return this.statusBarHeight+48+uni.upx2px(10)+'px'
  70. // #endif
  71. // #ifndef MP-WEIXIN
  72. return '10rpx'
  73. // #endif
  74. },
  75. triangle_styles(){
  76. // #ifdef MP-WEIXIN
  77. return this.statusBarHeight+48+uni.upx2px(1)+'px'
  78. // #endif
  79. // #ifndef MP-WEIXIN
  80. return '0rpx'
  81. // #endif
  82. }
  83. }
  84. };
  85. </script>
  86. <style lang="scss" scoped>
  87. .mask {
  88. width: 100%;
  89. height: 100%;
  90. overflow: hidden;
  91. position: absolute;
  92. top: 0;
  93. left: 0;
  94. z-index: 0;
  95. background-color: transparent;
  96. box-sizing: border-box;
  97. opacity: 0;
  98. transition: all 0.15s ease-in-out;
  99. }
  100. .mask-show{
  101. opacity: 1;
  102. z-index: 1000;
  103. }
  104. .uni-combox__selector {
  105. position: absolute;
  106. top: 10rpx;
  107. right: 20rpx;
  108. /* #ifdef MP-WEIXIN */
  109. right: 40rpx;
  110. /* #endif */
  111. box-sizing: border-box;
  112. width: 28%; // 下拉框宽度
  113. background-color: $u-main-color;
  114. border-radius: 3px;
  115. box-shadow: #dddddd 2px 2px 4px, #dddddd -2px -2px 4px;
  116. z-index: 998;
  117. }
  118. .triangle{
  119. position: absolute;
  120. width: 0;
  121. height: 0;
  122. // $u-main-color
  123. border-bottom: solid 5px $u-main-color;
  124. border-right: solid 5px transparent;
  125. border-left: solid 5px transparent;
  126. right: 30rpx;
  127. top: 0rpx;
  128. /* #ifdef MP-WEIXIN */
  129. right: 29%;
  130. /* #endif */
  131. z-index: 999;
  132. }
  133. .uni-combox__selector-scroll {
  134. max-height: 150px;
  135. box-sizing: border-box;
  136. }
  137. .uni-combox__selector-item {
  138. /* #ifdef APP-NVUE || MP-WEIXIN */
  139. display: flex;
  140. /* #endif */
  141. font-size: 24rpx;
  142. padding: 30rpx ;
  143. color: #ffffff;
  144. border-bottom: 1rpx solid $u-type-info;
  145. &-icon {
  146. padding-right: 10rpx;
  147. }
  148. }
  149. .uni-combox__selector-item:last-child {
  150. border-bottom: none;
  151. }
  152. </style>