nav-bar.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 && tabList.length > 0" 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 uniEasyinput from '@/uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue';
  39. import {
  40. reactive,
  41. onMounted,
  42. watch
  43. } from 'vue';
  44. const emit = defineEmits(['GoBack','CommonFilterData']);
  45. const props = defineProps({
  46. height: { //高度
  47. type: String,
  48. default: () => ''
  49. },
  50. leftWidth: { //导航栏左侧插槽宽度
  51. type: String,
  52. default: () => '96rpx'
  53. },
  54. rightWidth: { //导航栏右侧插槽宽度
  55. type: String,
  56. default: () => '96rpx'
  57. },
  58. title: { //标题
  59. type: String,
  60. default: () => ''
  61. },
  62. showHeaderborder: { //是否显示边框 默认不显示
  63. type: Boolean,
  64. default: false
  65. },
  66. backgroundColor: { //背景色
  67. type: String,
  68. default: () => '#FFFFFF'
  69. },
  70. backPath: { //返回路径
  71. type: String,
  72. default: () => ''
  73. },
  74. onlyTitle: { //是否只显示标题
  75. type: Boolean,
  76. default: true
  77. },
  78. filterPickerData: { //条件选择器
  79. type: Array,
  80. default: () => []
  81. },
  82. tabList: { //tabs
  83. type: Array,
  84. default: () => []
  85. },
  86. showFilterPicker: { //是否显示条件选择器
  87. type: Boolean,
  88. default: false
  89. },
  90. showTabs: { //是否显示条件选择器tabs
  91. type: Boolean,
  92. default: false
  93. }
  94. });
  95. const state = reactive({
  96. searchWord: '', //关键字
  97. filterPickerValue: [], //条件选择器默认值
  98. tabsSelected: '', //tabs 默认选中
  99. searchInputStyles: { //搜素框样式
  100. borderColor: '#DCDFE6',
  101. color: '#333333'
  102. },
  103. searchInputPlaceholderStyle: 'color: #C0C4CC;fontSize: 28rpx' //搜素框样式
  104. })
  105. watch(()=>props.tabList,(newVal, oldVal)=>{
  106. if(newVal){
  107. state.tabsSelected = props?.tabList?.[0]?.value || ''; //tab 默认值
  108. }
  109. })
  110. //关键字搜索
  111. const HandleSearchInput = (e) => {
  112. state.searchWord = e;
  113. CommonFilterData(state.searchWord, {
  114. filterPickerValue: [...state.filterPickerValue]
  115. }, state.tabsSelected, 'search');
  116. }
  117. //切换条件选择器 index:数组filterPickerData索引
  118. const ChangeFilterPicker = (e, index) => {
  119. const valueIndex = e.detail.value; //下拉框选中值的索引
  120. const selectedValue = props.filterPickerData?.[index]?.list?.[valueIndex]?.value ?? '';
  121. state.filterPickerValue[index] = selectedValue;
  122. //处理下一级默认值
  123. for(let i = 0; i < props.filterPickerData.length; i++){
  124. if(i > index){
  125. const list = props.filterPickerData?.[i]?.list || [];
  126. state.filterPickerValue[i] = list.length > 0 ? list[0].value : '';
  127. }
  128. }
  129. console.log(state.filterPickerValue,props.filterPickerData,37888)
  130. CommonFilterData(state.searchWord, {
  131. valueIndex,
  132. index,
  133. filterPickerValue: [...state.filterPickerValue]
  134. }, state.tabsSelected, 'filterPicker');
  135. }
  136. //tabs切换
  137. const SelectTabsValue = (value) => {
  138. state.tabsSelected = value;
  139. CommonFilterData(state.searchWord, {
  140. filterPickerValue: [...state.filterPickerValue]
  141. }, state.tabsSelected, 'tabs');
  142. }
  143. //条件发生改变进行数据查询
  144. const CommonFilterData = (searchWord, filterPickerValue, tabsSelected, type) => {
  145. emit('CommonFilterData', searchWord, filterPickerValue, tabsSelected, type);
  146. }
  147. const GoBack = () => {
  148. if (props.backPath == 'myIndex') {
  149. uni.switchTab({
  150. url: '/pages/my/index'
  151. });
  152. } else if (props.backPath == 'workspace') { //跳转工作台
  153. uni.switchTab({
  154. url: '/pages/workspace/index'
  155. });
  156. } else {
  157. emit('GoBack');
  158. }
  159. }
  160. onMounted(() => {
  161. state.tabsSelected = props?.tabList?.[0]?.value || ''; //tab 默认值
  162. state.filterPickerValue = props.filterPickerData.map(item => item?.defaultValue ?? '');
  163. })
  164. </script>
  165. <style scoped lang="scss">
  166. :deep(.uni-navbar__header) {
  167. padding: 0;
  168. position: relative;
  169. z-index: 999;
  170. }
  171. :deep(.uni-navbar__header-container) {
  172. padding: 0;
  173. }
  174. </style>