nav-bar.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <view class="box-bg" :style="{'height': customBarH + 'px', 'padding-top': statusBarH + '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="focus" />
  14. </view>
  15. </uni-nav-bar>
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. data() {
  21. return {
  22. statusBarH: 0,
  23. customBarH: 0,
  24. index: 0,
  25. array: [
  26. { name: '文章', code: 0 },
  27. { name: '期刊', code: 1 }
  28. ]
  29. }
  30. },
  31. methods: {
  32. // 类型选项改变
  33. bindPickerChange(e) {
  34. this.index = e.target.value;
  35. this.type = this.array[e.target.value].code;
  36. },
  37. // 搜索
  38. confirm(e) {
  39. console.log('搜索');
  40. },
  41. // 聚焦
  42. focus(e) {
  43. console.log('聚焦');
  44. }
  45. },
  46. // 获取状态栏和导航条高度
  47. created() {
  48. const app = getApp()
  49. this.statusBarH = app.globalData.statusBarH
  50. this.customBarH = app.globalData.customBarH - this.statusBarH
  51. },
  52. }
  53. </script>
  54. <style lang="scss" scope>
  55. $nav-height: 30px;
  56. .box-bg {
  57. background-color: #F5F5F5;
  58. padding: 5px 0;
  59. }
  60. .uni-picker {
  61. /* #ifndef APP-PLUS-NVUE */
  62. display: flex;
  63. /* #endif */
  64. flex-direction: row;
  65. align-items: center;
  66. justify-content: flex-start;
  67. // width: 160rpx;
  68. margin-left: 4px;
  69. }
  70. .input-view {
  71. /* #ifndef APP-PLUS-NVUE */
  72. display: flex;
  73. /* #endif */
  74. flex-direction: row;
  75. // width: 500rpx;
  76. // flex: 1;
  77. background-color: #f8f8f8;
  78. height: $nav-height;
  79. border-radius: 15px;
  80. flex-wrap: nowrap;
  81. margin: 7px 0;
  82. line-height: $nav-height;
  83. width: 90%;
  84. }
  85. .input-uni-icon {
  86. line-height: $nav-height;
  87. }
  88. .nav-bar-input {
  89. height: $nav-height;
  90. line-height: $nav-height;
  91. width: 80%;
  92. padding: 0 5px;
  93. font-size: 12px;
  94. background-color: #f8f8f8;
  95. }
  96. </style>