navbar-tab-search.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <view class="slot">
  3. <view class="slot-inner" :style="[showSearch ? { minHeight: navBarHeight + 'px' } : { height: navBarHeight + 'px' }]">
  4. <view
  5. v-if="showSearch"
  6. class="inner-showSearch"
  7. :style="[
  8. { minHeight: menuHeight + 'px' },
  9. { lineHeight: menuHeight + 'px' },
  10. { paddingLeft: menuRight * 2 + 'px' },
  11. { paddingRight: menuRight * 2 + 'px' },
  12. { paddingTop: navBarHeight - menuHeight - menuTop + 'px' },
  13. { paddingBottom: '20rpx' }
  14. ]"
  15. >
  16. <view class="page_title"
  17. :style="[
  18. { minHeight: menuHeight + 'px' },
  19. { lineHeight: menuHeight + 'px' },
  20. ]"
  21. >
  22. {{pageTitle}}
  23. </view>
  24. <view class="search-slot" :style="{ paddingTop: '16px' }">
  25. <!-- shape="square"
  26. borderRadius="0rpx"-->
  27. <u-search
  28. class="search-components"
  29. @click="goSearchPage(url)"
  30. disabled
  31. :placeholder="placeholder"
  32. :showAction="false"
  33. :bg-color="searchBgColor"
  34. :class="showSlot ? 'active' : ''"
  35. ></u-search>
  36. <slot showSlot></slot>
  37. </view>
  38. </view>
  39. <view class="inner" v-else>
  40. <view
  41. @click="$u.route({ type: 'navigateBack', delta: 1 })"
  42. class="left"
  43. v-if="showBack"
  44. :style="[{ minHeight: menuHeight + 'px' }, { lineHeight: menuHeight + 'px' }, { left: menuRight * 2 + 'px' }, { bottom: menuBotton + 'px' }]"
  45. >
  46. <u-icon size="32" name="arrow-leftward"></u-icon>
  47. </view>
  48. <view class="page_title"
  49. :style="[
  50. { minHeight: menuHeight + 'px' },
  51. { lineHeight: menuHeight + 'px' },
  52. ]"
  53. >
  54. <!-- { left: showBack ? menuRight * 2 + 40 + 'px' : menuRight * 2 + 'px' },
  55. { bottom: menuBotton + 'px' } -->
  56. {{pageTitle}}
  57. </view>
  58. </view>
  59. </view>
  60. <!-- + 27 -->
  61. <view class="slot-height" v-if="showSearch" :style="[{ height: navBarHeight + menuHeight+statusBarHeight + 'px' }]"></view>
  62. <view class="slot-height" v-else :style="[{ height: navBarHeight + 'px' }]"></view>
  63. </view>
  64. </template>
  65. <script>
  66. const app = getApp();
  67. export default {
  68. name: 'navbar-tab-search',
  69. props: {
  70. // 配置项
  71. tabOps: {
  72. type: Array,
  73. default: () => {
  74. return ['tab1', 'tab2'];
  75. }
  76. },
  77. pageTitle:{
  78. type: String,
  79. default: '书嗨',
  80. },
  81. // 占位内容
  82. placeholder: {
  83. type: String,
  84. default: '请输入'
  85. },
  86. // 是否显示插槽,用于输入框右侧内容的显示
  87. showSlot: {
  88. type: Boolean,
  89. default: false
  90. },
  91. // 是否显示搜索框
  92. showSearch: {
  93. type: Boolean,
  94. default: false
  95. },
  96. // 跳转的url
  97. url: {
  98. type: String,
  99. default: ''
  100. },
  101. // 是否显示返回按钮
  102. showBack: {
  103. type: Boolean,
  104. default: false
  105. }
  106. },
  107. data() {
  108. return {
  109. // 导航栏高度
  110. navBarHeight: app.globalData.navBarHeight,
  111. statusBarHeight: app.globalData.statusBarHeight,
  112. menuRight: app.globalData.menuRight,
  113. menuBotton: app.globalData.menuBotton,
  114. menuHeight: app.globalData.menuHeight,
  115. menuTop: app.globalData.menuTop,
  116. // 当前tab
  117. current: 0,
  118. // 背景色
  119. searchBgColor: this.$appTheme.appThemeSearchBgColor
  120. };
  121. },
  122. methods: {
  123. // 切换tab
  124. change(index) {
  125. this.current = index;
  126. this.$emit('change', index);
  127. },
  128. // 去搜索页面
  129. goSearchPage(url) {
  130. uni.navigateTo({
  131. url
  132. });
  133. }
  134. }
  135. };
  136. </script>
  137. <style lang="scss" scoped>
  138. .page_title{
  139. text-align: center;
  140. font-size: 32rpx;
  141. }
  142. .slot {
  143. width: 100vw;
  144. }
  145. .slot-inner {
  146. width: 100%;
  147. position: fixed;
  148. top: 0;
  149. left: 0;
  150. z-index: 899;
  151. overflow: hidden;
  152. }
  153. /* .tabList {
  154. display: flex;
  155. align-items: center;
  156. .tab {
  157. font-size: 36rpx;
  158. font-weight: 400;
  159. margin-right: 48rpx;
  160. color: $app-theme-navbar-tab-color;
  161. &.active {
  162. font-weight: 500;
  163. color: $app-theme-navbar-tab-color-active;
  164. font-size: 40rpx;
  165. position: relative;
  166. &::before {
  167. content: '';
  168. width: 16rpx;
  169. height: 6rpx;
  170. background: $app-theme-navbar-tab-color-active;
  171. border-radius: 1px;
  172. position: absolute;
  173. bottom: -10rpx;
  174. left: 50%;
  175. transform: translate(-50%, 0);
  176. }
  177. }
  178. }
  179. }
  180. */
  181. .inner {
  182. width: 100%;
  183. position: relative;
  184. height: 100%;
  185. background-color: $app-theme-bg-color;
  186. .left {
  187. position: absolute;
  188. z-index: 999;
  189. display: flex;
  190. align-items: center;
  191. // 防误触
  192. width: 30x;
  193. margin-right: 10px;
  194. }
  195. /* .tabList {
  196. width: 50%;
  197. position: absolute;
  198. z-index: 999;
  199. display: flex;
  200. align-items: center;
  201. } */
  202. }
  203. .inner-showSearch {
  204. width: 100%;
  205. height: 100%;
  206. background-color: $app-theme-bg-color;
  207. .tabList {
  208. display: flex;
  209. align-items: center;
  210. }
  211. }
  212. .search-slot {
  213. width: 100%;
  214. display: flex;
  215. justify-content: space-between;
  216. align-items: center;
  217. .search-components {
  218. width: 100%;
  219. &.active {
  220. width: 86%;
  221. }
  222. }
  223. }
  224. </style>