当前位置: 首页 > news >正文

vue+element-ui的列表查询条件/筛选条件太多以下拉选择方式动态添加条件(支持全选、反选、清空)

1、此功能已集成到TQueryCondition组件中

2、最终效果

在这里插入图片描述

3、具体源码(新增moreChoose.vue)

<template><el-popoverpopper-class="t_query_condition_more":bind="popoverAttrsBind"ref="popover"v-if="allcheckList.length>0"><div class="inside_box"><div class="inside_box_title"><div>{{popoverAttrsBind.title||'所有条件'}}</div><div class="check-box"><el-buttonsize="mini"type="text"@click="handlecheckAll">{{popoverAttrsBind.allTxt||'全选'}}</el-button><el-buttonsize="mini"type="text"@click="handleReset">{{popoverAttrsBind.clearTxt||'清空'}}</el-button><el-buttonsize="mini"type="text"@click="handleReverseCheck">{{popoverAttrsBind.reverseTxt||'反选'}}</el-button></div></div><el-checkbox-group v-model="checkList" class="inside_box_main" @change="getcheck"><el-checkbox v-for="item of allcheckList" :key="item.name" :label="item.label"></el-checkbox></el-checkbox-group></div><span class="more_dropdown_icon" slot="reference"><span class="out_box">{{popoverAttrsBind.showTxt||'更多'}}</span><i class="el-icon-arrow-down"></i></span></el-popover>
</template>
<script>
export default {name: 'MoreChoose',props: {// 以下拉方式展示更多条件---数据源moreCheckList: {type: Array,default: () => []},// 更多条件--el-popover属性popoverAttrs: {type: Object,default: () => ({})}},data() {return {checkList: [],isCheckList: [], // 已选中allcheckList: this.moreCheckList // 全部可选项}},watch: {// 全部可选项moreCheckList: {handler(list) {this.allcheckList = list},deep: true},// 选中项checkList: {handler(nval, oval) {let list = []oval.forEach(ele => {if (!nval.some(val => val == ele)) {list.push(ele)}})this.isCheckList.forEach((ele, j) => {if (list.filter(val => val == ele.label)[0]) {delete this.isCheckList[j]}})}}},computed: {// 以下拉方式展示更多条件--属性popoverAttrsBind() {const popoverAttrs = { showTxt: '更多', title: '所有条件', allTxt: '全选', reverseTxt: '反选', clearTxt: '清空', ...this.popoverAttrs }return { placement: 'bottom', width: 240, trigger: 'click', ...popoverAttrs }}},methods: {// 全选handlecheckAll() {this.checkList = this.allcheckList.map((item) => item.label)// console.log('全选', this.checkList)this.isCheckList = this.allcheckListconst checkObj = this.analysisObj(this.isCheckList)this.$emit('getCheckList', checkObj)},// 反选handleReverseCheck() {const checkList = JSON.parse(JSON.stringify(this.checkList))this.checkList = []this.isCheckList = []this.allcheckList.forEach((ele, j) => {if (!checkList.filter((item1) => item1 == ele.label)[0]) {this.checkList.push(ele.label)this.isCheckList.push(ele)}})const checkObj = this.analysisObj(this.isCheckList)// console.log('反选', checkObj)this.$emit('getCheckList', checkObj)},// 清空handleReset() {// console.log('清空')this.checkList = []this.isCheckList = []this.$emit('getCheckList', {})},// 单选getcheck(val) {this.allcheckList.forEach((ele, j) => {if (val.filter(item1 => item1 == ele.label)[0]) {this.isCheckList.push(ele)}})// console.log('isCheckList---', this.isCheckList, this.checkList)const checkObj = this.analysisObj(this.isCheckList)// console.log('checkObj--222', checkObj)this.$emit('getCheckList', checkObj)},// 格式化analysisObj(val) {return val.reduce((obj, item) => {obj[item.prop] = {label: item.label,comp: item.comp,bind: item.bind,child: item && item.child,slotName: item && item.slotName,span: item && item.span,defaultVal: item && item.defaultVal}if (item.comp === 'el-select') {obj[item.prop].child = item.list.reduce((acc, cur) => {acc.push({comp: 'el-option',value: cur[item.valueKey || 'key'],bind: {label: cur[item.labelKey || 'label'],key: cur[item.valueKey || 'key']}})return acc}, [])}return obj}, {})}}
}
</script>
<style lang="scss">
.t_query_condition_more.el-popover {padding: 10px 15px;padding-top: 5px;.inside_box {display: flex;flex-direction: column;.inside_box_title {display: flex;justify-content: space-between;align-items: center;}.inside_box_main {display: grid;grid-template-columns: repeat(2, minmax(100px, 50%));.el-checkbox {display: flex;align-items: center;.el-checkbox__label {-webkit-box-sizing: border-box;box-sizing: border-box;overflow: hidden;text-overflow: ellipsis;word-break: break-all;min-width: 90px;}}}}
}
</style>

4、集成到TQueryCondition组件

在这里插入图片描述

注意点:开启以下拉方式展示更多条件禁用展开&收起功能

代码示例

<template><t-layout-page><t-layout-page-item><t-query-conditionref="queryCondition":opts="opts"isDropDownSelectMore:loading="loading":moreCheckList="moreCheckList"@submit="conditionEnter"@getCheckList="getChildCheck"><template #likeTransportNo="{param}"><el-input v-model="param.likeTransportNo" clearable placeholder="自定义插槽输入框" /></template></t-query-condition></t-layout-page-item></t-layout-page>
</template>
<script>
const ADDRESS_TYPES = [{label: '前纺一车间',key: 'W1'},{label: '前纺二车间',key: 'W2'},{label: '前纺三车间',key: 'W3'}
]
export default {name: 'queryData',data() {return {loading: false,queryData: {likeCargoNo: null,likeBookNo: null,likeTransportNo: null,likeCargoName: null,workshopNum: null,workshopNum1: null,date1: null,// date: null,},sexList: [],hobbyList: [],opts: {likeCargoNo: {label: '货源编号',comp: 'el-input'},likeBookNo: {labelRender: () => {return (<el-tooltip content={'自定义label'} placement="top"><div>订单编号</div></el-tooltip>)},placeholder: '自定义label',comp: 'el-input'},likeTransportNo: {label: '运单编号',comp: 'el-input',slotName: 'likeTransportNo',},likeCargoName: {label: '货品名称',comp: 'el-input',bind: {}},workshopNum1: {label: '车间2',comp: 'el-select',child: ADDRESS_TYPES.reduce((acc, cur) => {acc.push({comp: 'el-option',value: cur.key,bind: {label: cur.label,key: cur.key}})return acc}, [])},workshopNum: {label: '车间',comp: 'el-select',changeEvent: 'change',// defaultVal: 'W1',bind: {},child: [{comp: 'el-option',value: 'W1',bind: {label: '前纺一车间',key: 'W1'}},{comp: 'el-option',value: 'W2',bind: {label: '前纺二车间',key: 'W2'}},{comp: 'el-option',value: 'W3',bind: {label: '前纺三车间',key: 'W3'}}]},date1: {label: '日期',comp: 'el-date-picker',bind: {valueFormat: 'yyyy-MM-dd'}},},checkQuery: {}}},computed: {moreCheckList() {return [{ label: '姓名', comp: 'el-input', prop: 'name' },{ label: '年龄', comp: 'el-input', prop: 'age' },{ label: '性别', comp: 'el-select', prop: 'sex', valueKey: "value", list: this.sexList },{label: "爱好", comp: "t-select", prop: 'hobby', span: 2, bind: { multiple: true, optionSource: this.hobbyList, valueKey: "value", },},{ label: '合同号', comp: 'el-input', prop: 'contractNo' },{ label: '供应商', comp: 'el-input', prop: 'supplier' },{ label: '磅单号', comp: 'el-input', prop: 'balanceCode' },{ label: '车牌号', comp: 'el-input', prop: 'license' },{ label: '备注', comp: 'el-input', prop: 'remark' },{ label: '检验员', comp: 'el-input', prop: 'inspector' },{ label: '取样人', comp: 'el-input', prop: 'sampler' },{ label: '审核人', comp: 'el-input', prop: 'reviewer' },{ label: '其他检验项', comp: 'el-input', prop: 'physicsInspection' },{ label: '实际数量', comp: 'el-input', prop: 'factQuantity' }]}},watch: {checkQuery: {handler(nval, oval) {for (let i = 0; i < Object.keys(oval).length; i++) {this.$delete(this.opts, Object.keys(oval)[i])}this.opts = Object.assign({}, this.opts, nval)for (let i = 0; i < Object.keys(this.opts).length; i++) {this.queryData[Object.keys(this.opts)[i]] = null}},deep: true}},created() {this.getList()},// 方法methods: {getList() {this.sexList = [{ label: '男', value: '1' }, { label: '女', value: '2' }]this.hobbyList = [{ label: '吉他', value: '0' },{ label: '看书', value: '1' },{ label: '美剧', value: '2' },{ label: '旅游', value: '3' },{ label: '音乐', value: '4' }]},getChildCheck(val) {this.checkQuery = val},// 点击查询按钮conditionEnter(data) {this.loading = truethis.queryData = dataconsole.log('最终条件', this.queryData)setTimeout(() => {this.loading = false}, 2000)}}
}
</script>

5、以下拉方式展示更多条件–配置参数(Attributes)

参数说明类型默认值
popoverAttrsel-popover配置及中文文案object具体看源码
moreCheckList数据源Array-
-----label标题string-
-----comp组件名称,可直接指定全局注册的组件string,component-
-----prop接收字段(即后台接收字段)string-
-----bind组件配置参数(Attributes)object-
-----slotName自定义输入框插槽string-
-----span控件占用的列宽,默认占用 1 列,最多 4 列 (独占一行)number1
-----defaultVal默认值string-
-----listel-select 组件options 数据Array-

6. 事件(events)

事件名说明回调参数
getCheckList下拉动态添加条件返回选中的条件项

7、demo地址

GitHub源码地址

Gitee源码地址

相关文章

基于ElementUi或Antd再次封装基础组件文档

vue3+ts基于Element-plus再次封装基础组件文档

http://www.lryc.cn/news/410940.html

相关文章:

  • LLM的训练与推断
  • uniapp使用WebSocket uniapp使用WebSocket Uniapp整合WebSocket uniapp使用 websocket
  • SSH Exporter:基于Prometheus的远程系统性能监控神器
  • Docker基础概念
  • 小白进阶为大神
  • 2024最新Python和PyCharm的安装教程
  • 数据库死锁:深入解析与应对策略
  • Python入门宝藏《看漫画学Python》,495页漫画带你弄清python知识点!简单易懂 | 附PDF全彩版
  • Webshell管理工具:AntSword(中国蚁剑)
  • Java 中的File类
  • java将map转json字符串或者再将json字符串转回map,java将对象转json字符串或者互想转换,对象集合和json字符串互转
  • 数据库管理-第225期 Oracle DB 23.5新特性一览(20240730)
  • 提高生产效率:最佳7大Bug记录工具
  • DDOS攻击学习 - kali初学
  • 【C++】类和对象——流插入和流提取运算符重载
  • Vmware ubuntu20.04 虚拟文件夹
  • 人工智能学习笔记 - 初级篇Ⅱ - 图形可视化 - 第11节: 绘制带填充区域的图表
  • 使用STM32实现一个线性代数计算器
  • 我在高职教STM32——串口通信(4)
  • Redis 缓存中间件 缓存数据库
  • 51、PHP 实现简单的快速排序
  • 如何应对机器视觉软件中时间篡改与许可绕过的挑战?
  • python文件的读写
  • 2024下《网络工程师》案例简答题,刷这些就够了!
  • Astro 实现TodoList网页应用案例
  • 计算机毕业设计Hadoop+Spark旅游景点可视化 旅游景点推荐系统 景区游客满意度预测与优化 Apriori算法 景区客流量预测 旅游大数据 景点规划
  • MySQL存储
  • 手势传感器 - 从零开始认识各种传感器【第十八期】
  • 【未来餐饮】 配送设置
  • 移动式气象设备:灵活应对,精准监测的气象先锋