filter-condition 条件过滤器(齐思博)
基础用法
用于筛选条件选择
--基础用法--
--可自定义操作符,支持枚举值查询--
<template>
<div>
<div>--基础用法--</div>
<h-filter-condition
:conditionOptions="conditionOptions"
@search="fnSearch"
></h-filter-condition>
<div>--可自定义操作符,支持枚举值查询--</div>
<h-filter-condition
:conditionOptions="conditionOptions"
:operationOptions="operationOptions"
:filData="filData"
@fnSearchFilData="fnSearchFilData"
@search="fnSearch"
></h-filter-condition>
</div>
</template>
<script setup>
import {
reactive,
toRefs
} from 'vue';
const data = reactive({
operationOptions: [
{
label: '等于(=)',
value: '='
},
{
label: '不等于(<>)',
value: '<>'
},
{
label: '模糊匹配(like)',
value: 'like'
},
{
label: '模糊匹配排除(not like)',
value: 'not like'
},
],
conditionOptions: [
{
label: '模版名称',
value: 'modelName',
type: 'input'
},
{
label: '物理表',
value: 'dataBaseName',
type: 'input'
},
{
label: '创建人',
value: 'creator',
type: 'input'
},
{
label: '创建时间',
value: 'createDate',
type: 'date-range'
},
{
label: '修改人',
value: 'updateUser',
type: 'input'
},
{
label: '修改时间',
value: 'updateDate',
type: 'date-range'
}
], // 查询条件
searchParams: [],
filData: {} // 用户记录筛选里的所查询到的枚举值
});
const {
operationOptions,
conditionOptions,
filData
} = toRefs(data)
const fnSearchFilData = async (key) => {
let totaldata = [];
try {
if (!data.filData[key]) {
// 查询枚举值-实例
// let resdata = await apiSearchColumnEnum({
// columnName: key,
// defaultValue: true
// })
// totaldata = resdata.data.values || [];
// data.filData[key] = totaldata.map(item => {
// return {
// label: item,
// value: item
// }
// });
}
} catch (e) {
console.log(e)
}
}
// 查询
const fnSearch = (condition) => {
data.searchParams = condition.map(item => {
return {
name: item.name,
condition: item.condition,
values: item.values
}
});
// fnSearchTable(1); // 查询表格数据
}
</script>操作符列表默认值
[ { label: '等于(=)', value: '=' }, { label: '不等于(<>)', value: '<>' }, { label: '大于(>)', value: '>' }, { label: '小于(<)', value: '<' }, { label: '大于等于(>=)', value: '>=' }, { label: '小于等于(<=)', value: '<=' }, { label: '多选(in)', value: 'in' }, { label: '排除(not in)', value: 'notin' }, { label: '模糊匹配(like)', value: 'like' }, { label: '模糊匹配排除(not like)', value: 'notlike' }, ]
Attributes
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---|---|---|---|---|
| filData | 用户记录筛选里的所查询到的枚举值 | object | [label:'',value:''] | — |
| conditionOptions | 可选条件列表 | array | — | — |
| operationOptions | 操作符列表 | array | — | 见上面 |
| defaultValue | 筛选默认值 | array | — | — |
conditionOptions
| 参数 | 说明 |
|---|---|
| label | 条件名称 |
| value | 条件标识 |
| type | 条件类型(输入框:input\textarea\number; 多选框:radio\checkbox\select; 日期:date; 日期范围:date-range) |
| options | 条件选项({label: ,value: }) |
defaultValue
| 参数 | 说明 |
|---|---|
| key | 属性值 |
| operate | 操作符值 |
| value | 属性对应填写的值 |
| type | 条件类型 |
Events
| 方法名 | 说明 | 参数 |
|---|---|---|
| search | 查询时触发 | 列表值:属性包括name,condition,values,type |
| fnSearchFilData | 选择属性后查询选择列表枚举值-输入框类型时触发 | 条件标识 |