graceSelectMenu.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <view class="grace-select-menu-wrap">
  3. <view class="grace-select-menu-title" @click.stop="showMenu" id="menuMain">
  4. <text :style="{fontSize:fontSize}">{{items[currentIndex]}}</text>
  5. <text class="grace-select-menu-icon icon-allow-b" v-if="!show"></text>
  6. <text class="grace-select-menu-icon icon-allow-t" v-if="show"></text>
  7. </view>
  8. <view class="grace-select-menu" :style="{top : top +'px'}" @click.stop="close" @touchmove.stop="" v-if="show">
  9. <view style="height:92rpx; width:100%;"></view>
  10. <scroll-view scroll-y class="grace-select-menus" :style="{padding:padding}">
  11. <view :class="['grace-select-item', index == currentIndex ? 'grace-selected' : '']"
  12. v-for="(item, index) in items" :style="{color : index == currentIndex ? activeColor : color}"
  13. :key="index" :data-index="index" @click.stop="select">
  14. <text class="grace-selected-icon" v-if="index == currentIndex"></text>
  15. <text :style="{fontSize:fontSize}">{{item}}</text>
  16. </view>
  17. <view style="height:100rpx;"></view>
  18. </scroll-view>
  19. </view>
  20. </view>
  21. </template>
  22. <script scoped>
  23. export default {
  24. props:{
  25. items : {
  26. type : Array,
  27. default : function () {
  28. return []
  29. }
  30. },
  31. show : {
  32. type : Boolean,
  33. default : false
  34. },
  35. height : {
  36. type : Number,
  37. default : 300
  38. },
  39. color : {
  40. type : String,
  41. default : "#333333"
  42. },
  43. activeColor : {
  44. type : String,
  45. default : "#3688FF"
  46. },
  47. selectIndex : {
  48. type : Number,
  49. default : 0
  50. },
  51. isH5header : {
  52. type : Boolean,
  53. default : true
  54. },
  55. fontSize : {
  56. type : String,
  57. default : '26rpx'
  58. },
  59. padding:{
  60. type : String,
  61. default : "0 20rpx"
  62. }
  63. },
  64. data() {
  65. return {
  66. currentIndex : 0,
  67. top : 0
  68. }
  69. },
  70. watch:{
  71. selectIndex : function () {
  72. this.currentIndex = this.selectIndex;
  73. }
  74. },
  75. created : function () {
  76. this.currentIndex = this.selectIndex;
  77. },
  78. methods:{
  79. showMenu:function () {
  80. uni.createSelectorQuery().in(this).select('#menuMain').fields(
  81. {rect: true}, (res) => {
  82. this.top = res.top;
  83. // #ifdef H5
  84. if(this.isH5header){this.top += 44;}
  85. // #endif
  86. }
  87. ).exec();
  88. this.$emit('showMenu');
  89. },
  90. close : function(){
  91. this.$emit('close');
  92. },
  93. select : function(e){
  94. var index = Number(e.currentTarget.dataset.index);
  95. this.currentIndex = index;
  96. this.$emit('select', index);
  97. this.close();
  98. }
  99. }
  100. }
  101. </script>
  102. <style>
  103. .grace-select-menu-wrap{width:100%; position:relative;}
  104. .grace-select-menu-title{height:90rpx; line-height:90rpx; font-size:28rpx; color:#333333; width:100%; text-align:center; overflow:hidden;}
  105. .grace-select-menu-icon{font-family:"grace-iconfont"; margin-left:10rpx; font-size:22rpx;}
  106. .icon-allow-b:after{content:"\e603";}
  107. .icon-allow-t:after{content:"\e654";}
  108. .grace-select-menu{position:fixed; width:750rpx; left:0; top:0; flex:1; bottom:0; box-sizing:border-box; z-index:1; overflow:hidden;}
  109. .grace-select-menus{height:260rpx; background:#FFFFFF; padding:0; height:100%; flex:1;}
  110. .grace-select-item{line-height:100rpx; width:700rpx; padding:0 10rpx; font-size:28rpx; color:#333333; border-bottom:1px solid #F8F8F8;}
  111. .grace-select-item:last-child{border:0;}
  112. .grace-selected{font-weight:bold;}
  113. .grace-selected-icon{margin-right:15rpx; font-family:"grace-iconfont";}
  114. .grace-selected-icon:after{content:"\e7f8";}
  115. </style>