更新记录
1.0.0(2026-07-29) 下载此版本
平台兼容性
uni-app(3.8.12)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| √ | - | √ | - | √ | - | - | - | - |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| √ | - | - | - | - | - | - | - | - | - | - | - |
uni-query-filter
基于 uni-ui 的可配置多条件查询筛选组件,通过 JSON 配置即可生成完整的筛选面板,支持从顶部滑入、高度由内容撑开。
✨ 特性
- 🔧 完全配置驱动 — 字段名、类型、选项全部通过
fieldConfig配置 - 📦 8 种字段类型 — input / select / radio / checkbox / date / datetime / daterange / datetimerange / switch / cascader
- 🎨 基于 uni-ui — 使用 uni-easyinput / uni-data-select / uni-data-checkbox / uni-datetime-picker / uni-icons
- 📐 顶部弹出 — 从屏幕顶部滑入,动画流畅,高度由内容撑开
- 🛡️ 安全区适配 — 适配刘海屏和 Home Indicator
- 🔄 双向绑定 — 支持
v-model和.sync修饰符 - 📱 多端兼容 — App / H5 / 微信小程序 / 支付宝小程序等
📦 安装
通过 HBuilderX 插件市场搜索 uni-query-filter 导入即可。
依赖的 uni-ui 组件(会自动安装):
uni-easyinputuni-data-selectuni-data-checkboxuni-datetime-pickeruni-icons
🚀 快速上手
1. 在页面中引入
<template>
<view>
<button @click="showFilter = true">打开筛选</button>
<uni-query-filter
:visible.sync="showFilter"
title="用户列表筛选"
:field-config="fieldConfig"
v-model="filterForm"
@confirm="onConfirm"
@reset=""
/>
</view>
</template>
<script>
export default {
data() {
return {
showFilter: false,
filterForm: {
department: '',
username: '',
status: 'normal',
createTime: { start: '', end: '' }
},
fieldConfig: [
{
field: 'department',
label: '部门',
type: 'select',
options: [
{ label: '全部', value: '' },
{ label: '匠人科技', value: 'jr' },
{ label: '研发中心', value: 'rd' }
]
},
{
field: 'username',
label: '用户名',
type: 'input',
placeholder: '请输入用户名',
maxlength: 20
},
{
field: 'status',
label: '状态',
type: 'radio',
radioMode: 'button',
options: [
{ label: '正常', value: 'normal' },
{ label: '停用', value: 'disabled' }
],
defaultValue: 'normal'
},
{
field: 'createTime',
label: '创建时间',
type: 'daterange',
start: '2020-01-01',
end: '2030-12-31',
startPlaceholder: '开始日期',
endPlaceholder: '结束日期'
}
]
}
},
methods: {
onConfirm(form) {
console.log('确认筛选:', form)
// form = {
// department: 'jr',
// username: '演示',
// status: 'normal',
// createTime: { start: '2024-01-01', end: '2024-01-25' }
// }
},
(form) {
console.log('已重置:', form)
}
}
}
</script>
📋 Props
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
visible |
Boolean | false |
是否显示面板,支持 .sync |
title |
String | '筛选条件' |
面板标题 |
fieldConfig |
Array | [] |
字段配置数组(核心) |
value / v-model |
Object | {} |
表单数据 |
confirmText |
String | '确认' |
确认按钮文字 |
resetText |
String | '重置' |
重置按钮文字 |
maxHeight |
String | '80vh' |
面板最大高度 |
confirmBtnStyle |
Object | {} |
确认按钮自定义样式 |
resetBtnStyle |
Object | {} |
重置按钮自定义样式 |
📡 Events
| 事件 | 参数 | 说明 |
|---|---|---|
confirm |
(formData) |
点击确认按钮 |
reset |
(formData) |
点击重置按钮 |
close |
- |
关闭面板 |
change |
({ field, value, form }) |
任意字段值变化 |
⚙️ fieldConfig 配置说明
通用字段
| 字段 | 说明 |
|---|---|
field |
绑定到 v-model 的字段名 |
label |
左侧标签文字 |
type |
字段类型(见下表) |
defaultValue |
默认值 |
placeholder |
占位提示文字 |
optionLabel |
选项标签字段名(默认 label) |
optionValue |
选项值字段名(默认 value) |
各类型特有配置
| type | 使用组件 | 特有字段 |
|---|---|---|
input |
uni-easyinput | inputType(text/number/password), maxlength |
select |
uni-data-select | options, disabledSelect |
radio |
uni-data-checkbox | options, radioMode(default/button/tag) |
checkbox |
uni-data-checkbox | options, checkboxMode, min, max |
date |
uni-datetime-picker | start, end, returnType |
datetime |
uni-datetime-picker | start, end, returnType |
daterange |
uni-datetime-picker | start, end, startPlaceholder, endPlaceholder |
datetimerange |
uni-datetime-picker | 同上 |
switch |
原生 switch | switchColor |
cascader |
uni-data-select | options(树形含 children) |
📊 数据格式
// v-model 绑定的数据格式
{
department: 'jr', // select / cascader → 字符串
username: '演示', // input → 字符串
status: 'normal', // radio → 字符串
role: ['admin', 'editor'], // checkbox → 数组
createTime: { start: '2024-01-01', end: '2024-01-25' }, // range → 对象
loginTime: '2024-01-24 16:36:02', // datetime → 字符串
enableNotify: true // switch → 布尔值
}
🎨 自定义按钮样式
<uni-query-filter
:visible.sync="showFilter"
:field-config="fieldConfig"
v-model="filterForm"
:confirm-btn-style="{ background: '#ff6a00', borderRadius: '40rpx' }"
:reset-btn-style="{ background: '#e8e8e8', color: '#333' }"
confirm-text="搜索"
reset-text="清空"
/>
📁 目录结构
uni_modules/uni-query-filter/
├── components/
│ └── uni-query-filter/
│ └── uni-query-filter.vue # 组件主体
├── pages/
│ └── demo/
│ └── demo.vue # 示例页面
├── package.json # uni_modules 元信息
├── CHANGELOG.md # 更新日志
└── README.md # 本文档
💡 常见问题
Q: 为什么不用原生 picker?
A: 原生 picker 的 mode 不支持 daterange / datetimerange,会导致 Vue 校验报错。本组件使用 uni-datetime-picker,原生支持范围选择,无报错。
Q: 面板高度怎么控制?
A: 面板高度完全由内容撑开,不设固定高度。当条件很多时,max-height: 80vh 兜底,内部自动滚动。
Q: 支持哪些端?
A: App(Vue)、H5、微信小程序、支付宝小程序、百度小程序、头条小程序、QQ小程序均支持。
📄 License
MIT

收藏人数:
下载插件并导入HBuilderX
下载插件ZIP
赞赏(0)
下载 0
赞赏 0
下载 12465920
赞赏 1936
赞赏
京公网安备:11010802035340号