nav-bar.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <uni-nav-bar :class="{'custom_uni_nav_bar':!onlyTitle,'custom_navbar_only_title':onlyTitle}"
  3. :height="`${height}rpx`" :backgroundColor="backgroundColor" :title="title" color="#333333" :fixed="true"
  4. :border="showHeaderborder" :statusBar="true" :leftWidth="leftWidth" :rightWidth="rightWidth" left-icon="left"
  5. @clickLeft="GoBack()">
  6. <!-- 表头内容 -->
  7. <view class="nav_head" v-if="!onlyTitle">
  8. <text class="nav_title">{{title}}</text>
  9. <uni-easyinput class="search_box" v-model="state.searchWord" trim="all" :styles="state.searchInputStyles"
  10. :placeholderStyle="state.searchInputPlaceholderStyle" placeholder="请输入关键字搜索" @input="HandleSearchInput">
  11. <template #left>
  12. <image src="/static/image/overview/search.png" class="search_icon"></image>
  13. </template>
  14. </uni-easyinput>
  15. </view>
  16. <!-- 条件选择器 -->
  17. <view class="filter_picker" v-if="showFilterPicker">
  18. <template v-for="(item,index) in filterPickerData" :key="index">
  19. <picker mode="selector" v-if="item?.list?.length > 0" :range="item.list" :value="item.valueIndex" range-key="label" style="width: calc((100% - 32rpx * 2) / 3);" @change="(e)=>ChangeFilterPicker(e,index)">
  20. <view class="filter_item">
  21. <text class="filter_text">{{ item?.list?.[item.valueIndex]?.label || '' }}</text>
  22. <uni-icons type="down" size="16" color="#999999"></uni-icons>
  23. </view>
  24. </picker>
  25. </template>
  26. </view>
  27. <!-- tabs -->
  28. <scroll-view v-if="showTabs" class="scroll_tabs" scroll-x="true" scroll-left="0" :show-scrollbar="false">
  29. <view :class="['tab_item',{'selected':item.value==state.tabsSelected}]" v-for="item in tabList" :key="item.value" @click="SelectTabsValue(item.value)">
  30. {{item.label}}
  31. </view>
  32. </scroll-view>
  33. </uni-nav-bar>
  34. </template>
  35. <script setup>
  36. import uniNavBar from '@/uni_modules/uni-nav-bar/components/uni-nav-bar/uni-nav-bar.vue';
  37. import uniIcons from '@/uni_modules/uni-icons/components/uni-icons/uni-icons.vue';
  38. import {
  39. reactive,
  40. onMounted
  41. } from 'vue';
  42. const emit = defineEmits(['GoBack','CommonFilterData']);
  43. const props = defineProps({
  44. height: { //高度
  45. type: String,
  46. default: () => ''
  47. },
  48. leftWidth: { //导航栏左侧插槽宽度
  49. type: String,
  50. default: () => '96rpx'
  51. },
  52. rightWidth: { //导航栏右侧插槽宽度
  53. type: String,
  54. default: () => '96rpx'
  55. },
  56. title: { //标题
  57. type: String,
  58. default: () => ''
  59. },
  60. showHeaderborder: { //是否显示边框 默认不显示
  61. type: Boolean,
  62. default: false
  63. },
  64. backgroundColor: { //背景色
  65. type: String,
  66. default: () => '#FFFFFF'
  67. },
  68. backPath: { //返回路径
  69. type: String,
  70. default: () => ''
  71. },
  72. onlyTitle: { //是否只显示标题
  73. type: Boolean,
  74. default: true
  75. },
  76. filterPickerData: { //条件选择器
  77. type: Array,
  78. default: () => []
  79. },
  80. tabList: { //tabs
  81. type: Array,
  82. default: () => []
  83. },
  84. showFilterPicker: { //是否显示条件选择器
  85. type: Boolean,
  86. default: false
  87. },
  88. showTabs: { //是否显示条件选择器tabs
  89. type: Boolean,
  90. default: false
  91. }
  92. });
  93. const state = reactive({
  94. searchWord: '', //关键字
  95. filterPickerValue: [], //条件选择器默认值
  96. tabsSelected: '', //tabs 默认选中
  97. searchInputStyles: { //搜素框样式
  98. borderColor: '#DCDFE6',
  99. color: '#333333'
  100. },
  101. searchInputPlaceholderStyle: 'color: #C0C4CC;fontSize: 28rpx' //搜素框样式
  102. })
  103. //关键字搜索
  104. const HandleSearchInput = (e) => {
  105. state.searchWord = e;
  106. CommonFilterData(state.searchWord, {
  107. filterPickerValue: [...state.filterPickerValue]
  108. }, state.tabsSelected, 'search');
  109. }
  110. //切换条件选择器 index:数组filterPickerData索引
  111. const ChangeFilterPicker = (e, index) => {
  112. const valueIndex = e.detail.value; //下拉框选中值的索引
  113. const selectedValue = props.filterPickerData?.[index]?.list?.[valueIndex]?.value ?? '';
  114. state.filterPickerValue[index] = selectedValue;
  115. CommonFilterData(state.searchWord, {
  116. valueIndex,
  117. index,
  118. filterPickerValue: [...state.filterPickerValue]
  119. }, state.tabsSelected, 'filterPicker');
  120. }
  121. //tabs切换
  122. const SelectTabsValue = (value) => {
  123. state.tabsSelected = value;
  124. CommonFilterData(state.searchWord, {
  125. filterPickerValue: [...state.filterPickerValue]
  126. }, state.tabsSelected, 'tabs');
  127. }
  128. //条件发生改变进行数据查询
  129. const CommonFilterData = (searchWord, filterPickerValue, tabsSelected, type) => {
  130. emit('CommonFilterData', searchWord, filterPickerValue, tabsSelected, type);
  131. }
  132. const GoBack = () => {
  133. if (props.backPath == 'myIndex') {
  134. uni.switchTab({
  135. url: '/pages/my/index'
  136. });
  137. } else if (props.backPath == 'workspace') { //跳转工作台
  138. uni.switchTab({
  139. url: '/pages/workspace/index'
  140. });
  141. } else {
  142. emit('GoBack');
  143. }
  144. }
  145. onMounted(() => {
  146. state.tabsSelected = props?.tabList?.[0]?.value || ''; //tab 默认值
  147. state.filterPickerValue = props.filterPickerData.map(item => item?.defaultValue ?? '');
  148. })
  149. </script>
  150. <style scoped lang="scss">
  151. :deep(.uni-navbar__header) {
  152. padding: 0;
  153. position: relative;
  154. z-index: 999;
  155. }
  156. :deep(.uni-navbar__header-container) {
  157. padding: 0;
  158. }
  159. </style>