navBar.vue 5.6 KB

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