Skip to content

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选择属性后查询选择列表枚举值-输入框类型时触发条件标识