nav-bar.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <view class="box-bg" :style="{'height': customBarH + 'px' }">
  3. <uni-nav-bar>
  4. <block class="uni-picker" slot="left">
  5. <picker @change="bindPickerChange" :value="index" :range="array" :range-key="'name'">
  6. <view>{{array[index].name}}</view>
  7. </picker>
  8. <uni-icons type="arrowdown" color="#666" size="18" />
  9. </block>
  10. <view class="input-view">
  11. <uni-icons class="input-uni-icon" type="search" size="18" color="#999" />
  12. <input confirm-type="search" class="nav-bar-input" type="text" placeholder="输入搜索关键词"
  13. @confirm="confirm" @focus="isTag = true" @blur="isTag = false" />
  14. </view>
  15. </uni-nav-bar>
  16. <view v-if="isTag" class="tagMask" :style="{'height': makerHeigth + 'px', 'top': statusBarH + customBarH + 'px' }">
  17. <uni-card :title="title">
  18. <view class="cardBox">
  19. <uni-tag class="tag" v-for="(item, index) in tagList" :key="index" :text="item.name"/>
  20. </view>
  21. </uni-card>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. data() {
  28. return {
  29. title: '热门文章',
  30. isTag: false,
  31. statusBarH: 0,
  32. customBarH: 0,
  33. screenHeight: 0,
  34. makerHeigth: 0,
  35. index: 0,
  36. array: [
  37. { name: '文章', code: 0 },
  38. { name: '期刊', code: 1 }
  39. ],
  40. tagList: [
  41. { name: '标签1', code: '1' },
  42. { name: '标签2', code: '2' },
  43. { name: '标签3', code: '3' },
  44. { name: '标签10', code: '4' },
  45. { name: '标签20', code: '5' },
  46. { name: '标签30', code: '6' },
  47. { name: '标签13', code: '7' },
  48. { name: '标签25', code: '8' },
  49. { name: '标签39', code: '9' },
  50. { name: '标签17', code: '10' },
  51. { name: '标签25', code: '11' },
  52. { name: '标签34', code: '12' }
  53. ]
  54. }
  55. },
  56. methods: {
  57. // 类型选项改变
  58. bindPickerChange(e) {
  59. this.index = e.target.value;
  60. this.type = this.array[e.target.value].code;
  61. this.title = `热门${this.array[e.target.value].name}`
  62. },
  63. // 搜索
  64. confirm(e) {
  65. console.log('搜索');
  66. this.isTag = false;
  67. }
  68. },
  69. // 获取状态栏和导航条高度
  70. created() {
  71. const app = getApp()
  72. this.statusBarH = app.globalData.statusBarH;
  73. this.customBarH = app.globalData.customBarH - this.statusBarH;
  74. this.screenHeight = app.globalData.screenHeight;
  75. this.makerHeigth = this.screenHeight - app.globalData.customBarH;
  76. },
  77. }
  78. </script>
  79. <style lang="scss" scope>
  80. $nav-height: 30px;
  81. .box-bg {
  82. background-color: #F5F5F5;
  83. // padding: 5px 0;
  84. }
  85. .uni-picker {
  86. /* #ifndef APP-PLUS-NVUE */
  87. display: flex;
  88. /* #endif */
  89. flex-direction: row;
  90. align-items: center;
  91. justify-content: flex-start;
  92. width: 160rpx;
  93. margin-left: 4px;
  94. }
  95. .input-view {
  96. /* #ifndef APP-PLUS-NVUE */
  97. display: flex;
  98. /* #endif */
  99. flex-direction: row;
  100. width: 500rpx;
  101. // flex: 1;
  102. background-color: #f8f8f8;
  103. height: $nav-height;
  104. border-radius: 15px;
  105. flex-wrap: nowrap;
  106. margin: 7px 0;
  107. line-height: $nav-height;
  108. // width: 90%;
  109. }
  110. .input-uni-icon {
  111. line-height: $nav-height;
  112. }
  113. .nav-bar-input {
  114. height: $nav-height;
  115. line-height: $nav-height;
  116. width: 80%;
  117. padding: 0 5px;
  118. font-size: 12px;
  119. background-color: #f8f8f8;
  120. }
  121. .tagMask {
  122. width: 100vw;
  123. // height: 100vh;
  124. background: #fff;
  125. position: fixed;
  126. // top: 0;
  127. left: 0;
  128. z-index: 999;
  129. }
  130. .cardBox {
  131. display: flex;
  132. flex-wrap: wrap;
  133. .tag {
  134. margin: 5px;
  135. }
  136. }
  137. </style>