小程序app封裝公用頂部篩選區uv-drop-down

參考ui:DropDown 下拉篩選 | 我的資料管理-uv-ui 是全面兼容vue3+2、nvue、app、h5、小程序等多端的uni-app生態框架

樣式示例:

封裝公用文件代碼??dropDownTemplete

<template><!-- 頂部下拉篩選區封裝公用組件 --><view><uv-drop-down ref="dropDown" sign="dropDown_1" :defaultValue="defaultValue" @click="selectMenu"><uv-drop-down-item v-for="(item,index) in uvDropDownItem" :name="item.name" type="2":label="dropItem(item.name,index).label" :value="dropItem(item.name,index).value"></uv-drop-down-item><uv-drop-down-item name="more" type="1" label='更多' extra-icon='empty-search' :value="0"></uv-drop-down-item></uv-drop-down><uv-drop-down-popup sign="dropDown_1" :click-overlay-on-close="true" :currentDropItem="currentDropItem"@clickItem="clickItem"></uv-drop-down-popup><!-- 更多搜索 --><view class="popupPosition"><uv-popup ref="popup" :safeAreaInsetTop="true"><view class="content"><view style="padding: 20rpx;"><uv-form labelPosition="left" :model="filterSheetData" ref="form"><uv-form-item v-for="(item,index) in formItem" :label="item.label" :prop="item.vModel"labelWidth="120" borderBottom width="150rpx" @click="handleItemClick(item)"><uv-input v-model="filterSheetData[item.vModel]" disabled disabledColor="#ffffff":placeholder="item.placeholder" border="none"></uv-input><uv-icon v-if="item.selectIcon" name="arrow-right"style="float: right;margin-right: 20rpx;"></uv-icon></uv-form-item><uv-button type="primary" text="搜索" customStyle="margin-top: 10px"@click="searchSheet"></uv-button><uv-button type="error" text="重置" customStyle="margin-top: 10px"@click="resetSearchSheet"></uv-button></uv-form></view></view></uv-popup><uv-popup ref="calendarsPopup" mode="bottom"><view class="calendarPopupStyle"><view class="cancel" @click="calendarsCancel">取消</view><view class="confirm" @click="calendarsConfirm">確定</view></view><uv-calendars ref="calendars" insert mode="range" @confirm="(e)=>timeConfirm(e,calendarsType)"@change="(e)=>timeConfirm(e,calendarsType)" /></uv-popup><uv-picker v-if="pickerShow" ref="picker" :columns="pickerColumns" keyName="label"@confirm="(e)=>pickerConfirm(e,pickerType)" @close="pickerClose"></uv-picker><uv-input v-if="pickerInputShow" placeholder="請輸入篩選內容" border="surround" clearable v-model="pickerValue"@change="pickerSearchChange" @clear="pickerSearchClear" :customStyle="pickerIptStyle"></uv-input></view></view></view>
</template><script>export default {data() {return {// 表示value等于這些值,就屬于默認值defaultValue: [0, 'all', '0'],result: [],activeName: '',pickerType: "",pickerShow: false,pickerInputShow: false,pickerIptStyle: {position: 'fixed',bottom: '220px',transform: 'translate(-50%)',zIndex: 997},pickerColumns: [[{label: '數據加載失敗',id: 0}]],queryParams: {json: {conditions: [],formId: '',orderBys: [],}},pickerValue: ''}},props: {// 下拉選項數據uvDropDownItem: {type: Array,default: () => ([])},// 更多下拉選中表單數據filterSheetData: {type: Object,default: () => ({})},filternetworkData: {type: Object,default: () => ({})},filterinitialData: {type: Object,default: () => ({})},// 表單項字段formItem: {type: Array,default: () => ([])},// 更多篩選中下拉數據列表olumnscData: {type: Array,default: () => ([])},},computed: {dropItem(name, index) {return (name, index) => {const result = {};const find = this.result.find(item => item.name === name);if (find) {result.label = find.label;result.value = find.value;} else {result.label = this.uvDropDownItem[index][name].label;result.value = this.uvDropDownItem[index][name].value;}return result;}},// 獲取當前下拉篩選項currentDropItem() {let data = this.uvDropDownItem.find(item => item.name === this.activeName)// console.log(data&&data.name);//拿到name字段// console.log(data&&data[data.name]);//獲取name字段中的數組return data && data[data.name]}},created() {},methods: {// 更多篩選中表單點擊事件handleItemClick(item) {if (item.selectIcon) {if (item.type === 'text') {this.chooseSearchSelect(item.vModel);} else if (item.type === 'time') {this.chooseSearchTime(item.vModel);}}},// 選擇內容(下拉選)chooseSearchSelect(type) {this.pickerType = typethis.pickerColumnsAssignment()this.pickerShow = truethis.$nextTick(() => {this.$refs.picker.open();})setTimeout(() => {this.pickerIptStyle['left'] = window.innerWidth / 2 + 'px'this.pickerInputShow = true}, 300)},pickerColumnsAssignment() {this.olumnscData.forEach(item => {if (item.name == this.pickerType) {this.$set(this.pickerColumns, 0, item.list)}})},// 快速過濾選擇項pickerSearchChange(e) {if (e === '') {this.pickerColumnsAssignment()} else {this.olumnscData.forEach(item => {if (item.name == this.pickerType) {this.$set(this.pickerColumns, 0, item.list.filter((item) => item.label.includes(e)))}})}},// 快速過濾選擇項清除pickerSearchClear() {this.pickerColumnsAssignment()},// 選擇項確定pickerConfirm(e, type) {this.filternetworkData[type] = e.value[0]this.filterSheetData[type] = e.value[0].label},// 選擇項取消pickerClose() {this.pickerShow = falsethis.pickerInputShow = false},// 選擇時間chooseSearchTime(type) {this.calendarsType = typethis.$refs.calendarsPopup.open();},// 選擇時間取消calendarsCancel() {this.filternetworkData[this.calendarsType] = ""this.filterSheetData[this.calendarsType] = ""this.$refs.calendarsPopup.close();},// 選擇時間確定calendarsConfirm() {this.$refs.calendarsPopup.close();},timeConfirm(e, type) {this.filternetworkData[type] = e.rangethis.filterSheetData[type] = e.range.before + ' / ' + e.range.after},//更多--搜索searchSheet() {this.queryParams.json.conditions = []this.formItem.forEach(item => {// 判斷查詢表單項是否有值if (this.filternetworkData[item.vModel]&&item.type=='text') {// 如果value有值說明是對象格式  將value值傳遞if (this.filternetworkData[item.vModel].value) {this.queryParams.json.conditions.push({field: item.vModel,operation: "like",value: this.filternetworkData[item.vModel].value})// 如果只是字段有值 說明是文本框} else {this.queryParams.json.conditions.push({field: item.vModel,operation: "like",value: this.filternetworkData[item.vModel]})}}if (this.filternetworkData[item.vModel]&&item.type=='time') {this.queryParams.json.conditions.push({field: item.vModel,operation: "<>",value: this.filternetworkData[item.vModel].before,value2: this.filternetworkData[item.vModel].after})}})this.$refs.popup.close()// 將查詢條件傳遞給父組件this.$emit('searchSheet', this.queryParams.json)},resetSearchSheet() {this.$emit('resetSearchSheet')this.queryParams.json.conditions = []this.$refs.popup.close()},/*** 點擊每個篩選項回調* @param {Object} e { name, active, type } = e*/selectMenu(e) {const {name,active,type} = e;this.activeName = name;// type 等于1 的需要特殊處理:type不等于1可以忽略if (type == 1) {this.$refs.popup.open('top');} else {// 找到 name 屬性等于 this.activeName 的對象const dropDownItem = this.uvDropDownItem.find(item => item.name === this.activeName);if (dropDownItem) {const find = this.result.find(item => item.name == this.activeName);if (find) {const findIndex = dropDownItem.child.findIndex(item => item.label == find.label && item.value == find.value);dropDownItem.activeIndex = findIndex;} else {dropDownItem.activeIndex = 0;}}}},/*** 點擊菜單回調處理* @param {Object} item 選中項 { label,value } = e*/clickItem(e) {// 下面有重新賦值,所以用letlet {label,value} = e;const findIndex = this.result.findIndex(item => item.name == this.activeName);if (this.defaultValue.indexOf(value) > -1 && this[this.activeName].label) {label = this[this.activeName].label;}// 已經存在篩選項if (findIndex > -1) {this.$set(this.result, findIndex, {name: this.activeName,label,value})} else {this.result.push({name: this.activeName,label,value});}this.result = this.result.filter(item => this.defaultValue.indexOf(item.value) == -1);this.result.forEach(item => {if (item.name) {if (item.label == '全部') {if (this.queryParams.json.conditions.length) {this.queryParams.json.conditions.forEach((itens,indexs)=>{if(itens.field === item.name){this.queryParams.json.conditions.splice(indexs,1)}})	}} else {// 添加篩選參數if (this.queryParams.json.conditions.length) {this.queryParams.json.conditions.forEach((itens,indexs)=>{if(itens.field === item.name){this.queryParams.json.conditions.splice(indexs,1)}})this.queryParams.json.conditions.push({field: item.name,operation: "=",value: item.value})} else {this.queryParams.json.conditions.push({field: item.name,operation: "=",value: item.value})}}}})
// 將查詢條件傳遞給父組件this.$emit('searchSheet', this.queryParams.json)},}}
</script><style lang="scss" scoped>// 下拉選項滾動區域::v-deep .uv-dp__container {height: 400rpx !important;overflow-y: auto;}uni-view[data-v-4cc3c370] {top: 0 !important;}.calendarPopupStyle {display: flex;justify-content: space-between;border-bottom: 1rpx solid #ccc;>view {font-size: 34rpx;color: #909399;padding: 20rpx 20rpx;}}
</style>

父組件調用:

<view class="header-fixed"><dropDownTemplete :uvDropDownItem="uvDropDownItem" :filterSheetData="filterSheetData" :filternetworkData="filternetworkData" :filterinitialData="filterinitialData" :formItem="formItem" :olumnscData="olumnscData" @searchSheet="searchSheet" @resetSearchSheet="resetSearchSheet"></dropDownTemplete></view>

data數據:

// 下拉選項數據uvDropDownItem: [{name: 'brand',brand: {label: '品牌',value: 'all',activeIndex: 0,color: '#333',activeColor: '#2878ff',child: [{label: '全部',value: 'allto'}]},},{name: 'categoryId',categoryId: {label: '品類',value: 'all',activeIndex: 0,color: '#333',activeColor: '#2878ff',child: [{label: '全部',value: 'allto'}]}}],// 更多下拉選項數據formItem:[{label:'品類',vModel:'categoryId',type:'text',placeholder:'請選擇品類',selectIcon:true},{label:'品牌',vModel:'brand',type:'text',placeholder:'請選擇品牌',selectIcon:true},{label:'更新時間',vModel:'updateTime',type:'time',placeholder:'請選擇更新時間',selectIcon:true},{label:'創建時間',vModel:'createTime',type:'time',placeholder:'請選擇創建時間',selectIcon:true}],filterSheetData: {categoryId: "",brand: "",updateTime: "",createTime: ""},filternetworkData: {categoryId: "",brand: "",updateTime: "",createTime: ""},filterinitialData: {categoryId: "",brand: "",updateTime: "",createTime: ""},olumnscData:[{name:'categoryId',list:[{label:'1',vaule:'fff'},{label:'2',vaule:'dfvdgf'}],},{name:'brand',list:[{label:'里奈',vaule:'里奈'},{label:'舞曲',vaule:'舞曲'}],}]

搜索和清除事件:

// 更多-搜索searchSheet(data){console.log(data);//這里可進行搜索操作},// 更多-清除resetSearchSheet(){// 清空數據this.filterSheetData = this.filterinitialDatathis.filternetworkData = {categoryId: {label:'',value:''},brand: {label:'',value:''},updateTime: "",createTime: ""}},

最終樣式圖示例:

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/63890.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/63890.shtml
英文地址,請注明出處:http://en.pswp.cn/web/63890.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

LeetCode:101. 對稱二叉樹

跟著carl學算法&#xff0c;本系列博客僅做個人記錄&#xff0c;建議大家都去看carl本人的博客&#xff0c;寫的真的很好的&#xff01; 代碼隨想錄 LeetCode&#xff1a;101. 對稱二叉樹 給你一個二叉樹的根節點 root &#xff0c; 檢查它是否軸對稱。 示例 1&#xff1a; 輸…

Docker-如何啟動docker

作者介紹&#xff1a;簡歷上沒有一個精通的運維工程師。希望大家多多關注作者&#xff0c;下面的思維導圖也是預計更新的內容和當前進度(不定時更新)。 我們在上一章&#xff0c;講了虛擬化&#xff0c;虛擬化是把硬件虛擬化&#xff0c;然后創建出來的虛擬機完全隔離&#xff…

COMSOL with Matlab

文章目錄 基本介紹COMSOL with MatlabCOMSOL主Matlab輔Matlab為主Comsol為輔 操作步驟常用指令mphopenmphgeommghmeshmphmeshstatsmphnavigatormphplot常用指令mphsavemphlaunchModelUtil.clear 實例教學自動另存新檔**把語法套用到邊界條件**把語法套用到另存新檔 函數及其微分…

游戲關卡設計方法的雜感

1、正規思路是&#xff1a;先寫設計文檔&#xff0c;畫平面圖&#xff0c;再做白模關卡&#xff0c;再做正規模型的關卡。 一步步擴大。 當然是有道理的&#xff0c;從小到大&#xff0c; 但實際上這需要很強的想象力&#xff0c;很多細節靠腦補&#xff0c;初學者很難做好。…

JVM系列(十二) -常用調優命令匯總

最近對 JVM 技術知識進行了重新整理&#xff0c;再次獻上 JVM系列文章合集索引&#xff0c;感興趣的小伙伴可以直接點擊如下地址快速閱讀。 JVM系列(一) -什么是虛擬機JVM系列(二) -類的加載過程JVM系列(三) -內存布局詳解JVM系列(四) -對象的創建過程JVM系列(五) -對象的內存分…

bmp390l傳感器的IIC命令通信(學習匯總)

參考鏈接&#xff1a; BMP390高精度壓力傳感器數據讀取與處理&#xff08;基于STM32&#xff09;-CSDN博客 https://blog.csdn.net/qq_43862401/article/details/106502397 利用usb轉iic模塊測試bmp390l傳感器采集當前環境的溫度和氣壓數據&#xff0c;下圖中reserved表示…

C/C++基礎知識復習(43)

1) 什么是運算符重載&#xff1f;如何在 C 中進行運算符重載&#xff1f; 運算符重載是指在 C 中為現有的運算符定義新的行為&#xff0c;使得它們能夠用于用戶定義的數據類型&#xff08;如類或結構體&#xff09;。通過運算符重載&#xff0c;可以讓自定義類型像內置數據類型…

Windows11 家庭版安裝配置 Docker

1. 安裝WSL WSL 是什么&#xff1a; WSL 是一個在 Windows 上運行 Linux 環境的輕量級工具&#xff0c;它可以讓用戶在 Windows 系統中運行 Linux 工具和應用程序。Docker 為什么需要 WSL&#xff1a; Docker 依賴 Linux 內核功能&#xff0c;WSL 2 提供了一個高性能、輕量級的…

2025系統架構師(一考就過):案例題之一:嵌入式架構、大數據架構、ISA

一、嵌入式系統架構 軟件脆弱性是軟件中存在的弱點(或缺陷)&#xff0c;利用它可以危害系統安全策略&#xff0c;導致信息丟失、系統價值和可用性降低。嵌入式系統軟件架構通常采用分層架構&#xff0c;它可以將問題分解為一系列相對獨立的子問題&#xff0c;局部化在每一層中…

新手SEO指南如何快速入門與提升網站排名

內容概要 搜索引擎優化&#xff08;SEO&#xff09;是提高網站可見度和排名的重要手段&#xff0c;尤其對新手來說&#xff0c;掌握其基本概念和實用技巧至關重要。本文將針對新手提供一系列的指導&#xff0c;幫助你快速入門并逐步提升網站排名。 首先&#xff0c;了解SEO的…

Oracle下載安裝(保姆級教學)

方法1 1. 官網下載安裝包 對于 Oracle 軟件的下載&#xff0c;建議通過官網免費下載&#xff0c;安全且有保證。 下載地址&#xff1a; https://www.oracle.com/database/technologies/oracle19c-windows-downloads.html 通過下載頁面可以選擇安裝壓縮包&#xff08; WIND…

第22天:信息收集-Web應用各語言框架安全組件聯動系統數據特征人工分析識別項目

#知識點 1、信息收集-Web應用-開發框架-識別安全 2、信息收集-Web應用-安全組件-特征分析 一、ICO圖標&#xff1a; 1、某個應用系統的標示&#xff0c;如若依系統有自己特點的圖標&#xff1b;一旦該系統出問題&#xff0c;使用該系統的網站都會受到影響&#xff1b; 2、某個公…

重溫設計模式--建造者模式

文章目錄 建造者模式&#xff08;Builder Pattern&#xff09;概述建造者模式UML圖作用&#xff1a;建造者模式的結構產品&#xff08;Product&#xff09;&#xff1a;抽象建造者&#xff08;Builder&#xff09;&#xff1a;具體建造者&#xff08;Concrete Builder&#xff…

每日一題(4)

有一只蝸牛位于二維坐標系的原點(0,0)&#xff0c;在x軸上有n根平行于y軸的竹竿&#xff0c;它們底部的縱坐標為0&#xff0c;橫坐標分別為x_1,x_2,\cdots,x_n。蝸牛想要從原點走到第n根竹竿的底部(x_n,0)。蝸牛在x軸上的移動速度是1單位每秒&#xff0c;在竹竿上向上爬的速度是…

arcgisPro相接多個面要素轉出為完整獨立線要素

1、使用【面轉線】工具&#xff0c;并取消勾選“識別和存儲面鄰域信息”&#xff0c;如下&#xff1a; 2、得到的線要素&#xff0c;如下&#xff1a;

51單片機仿真搖號抽獎機源程序 12864液晶顯示

資料下載地址&#xff1a;51單片機仿真搖號抽獎機源程序12864液晶顯示仿真程序 一、功能介紹 單片機連接12864&#xff08;st7920&#xff09;液晶顯示器和1個按鍵接INT0&#xff0c;模擬一個抽獎機。 實現效果&#xff1a; 1、液晶初始顯示“祝你好運&#xff01;”&#xff…

如何在 Ubuntu 22.04 上安裝 Graylog 開源日志管理平臺

簡介 Graylog 的開源特性、豐富的功能、靈活性和可擴展性使其成為一個流行的日志管理平臺。在本教程中&#xff0c;我將向你展示如何在 Ubuntu 22.04 上安裝 Graylog&#xff0c;包括配置 Graylog 服務器軟件包和訪問 Graylog Web UI。 Graylog 是什么&#xff1f; Graylog …

技術發展歷程:從 CORBA 到微服務

CORBA CORBA&#xff08;Common Object Request Broker Architecture&#xff09;誕生于上世紀 90 年代初期&#xff0c;由 OMG 組織提出&#xff0c;它作為一種開創性的分布式對象技術規范&#xff0c;在當時的計算機領域引起了轟動。其核心構成部分——接口定義語言&#xf…

搶單人機交互「新紅利」!哪些細分賽道“多金”?

受終端用戶的智能座艙體驗需求驅動&#xff0c;視覺、聽覺、觸覺等人機交互方式加速煥新。 一方面&#xff0c;人機多模交互引領&#xff0c;車載聲學進入新周期。根據高工智能汽車研究院統計數據&#xff0c;單車的車載揚聲器搭載量正在快速起量。 很顯然&#xff0c;作為智…

記錄vue+elementUI table的組件

可展示圖片&#xff0c; 可使用slot插槽添加邏輯&#xff0c; 循環表cloumn&#xff0c; 循環添加操作配置actionButtons <el-tablev-loading"loading":data"tableData"borderstyle"width: 100%"selection-change"selectChange"…