graceSelectMenu.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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', height:heightIn+'px', zIndex:zIndex}" @click.stop="close" v-if="show">
  9. <view style="height:92rpx; width:100%; flex-shrink:0;"></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; width:100%"></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. zIndex:{
  64. type : Number,
  65. default : 9999
  66. }
  67. },
  68. data() {
  69. return {
  70. currentIndex : 0,
  71. top : 0,
  72. heightIn : 200
  73. }
  74. },
  75. watch:{
  76. selectIndex : function () {
  77. this.currentIndex = this.selectIndex;
  78. }
  79. },
  80. created : function () {
  81. this.currentIndex = this.selectIndex;
  82. },
  83. methods:{
  84. showMenu:function () {
  85. uni.createSelectorQuery().in(this).select('#menuMain').fields(
  86. {rect: true}, (res) => {
  87. var system = uni.getSystemInfoSync();
  88. var wHeight = system.windowHeight;
  89. this.top = res.top;
  90. this.heightIn = wHeight - this.top;
  91. // #ifdef H5
  92. if(this.isH5header){
  93. this.top += 44;
  94. this.heightIn -= 44;
  95. }
  96. // #endif
  97. }
  98. ).exec();
  99. this.$emit('showMenu');
  100. },
  101. close : function(){
  102. this.$emit('close');
  103. },
  104. select : function(e){
  105. var index = Number(e.currentTarget.dataset.index);
  106. this.currentIndex = index;
  107. this.$emit('select', index);
  108. this.close();
  109. }
  110. }
  111. }
  112. </script>
  113. <style>
  114. .grace-select-menu-wrap{width:100%; position:relative;}
  115. .grace-select-menu-title{height:90rpx; line-height:90rpx; font-size:28rpx; color:#333333; width:100%; text-align:center; overflow:hidden;}
  116. .grace-select-menu-icon{font-family:"grace-iconfont"; margin-left:10rpx; font-size:22rpx;}
  117. .icon-allow-b:after{content:"\e603";}
  118. .icon-allow-t:after{content:"\e654";}
  119. .grace-select-menu{position:fixed; width:750rpx; left:0; top:0; box-sizing:border-box; z-index:9999; overflow:hidden; display:flex; flex-direction:column;}
  120. .grace-select-menus{background:#FFFFFF; padding:0; height:300px; flex:1;}
  121. .grace-select-item{line-height:100rpx; width:700rpx; padding:0 10rpx; font-size:28rpx; color:#333333; border-bottom:1px solid #F8F8F8;}
  122. .grace-select-item:last-child{border:0;}
  123. .grace-selected{font-weight:bold;}
  124. .grace-selected-icon{margin-right:15rpx; font-family:"grace-iconfont";}
  125. .grace-selected-icon:after{content:"\e7f8";}
  126. </style>