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

下拉框可筛选可树状多选组件

实际效果图片
在这里插入图片描述在这里插入图片描述

父页面

<el-form-item label="转发:" :label-width="formLabelWidth" class="formflex_item"><el-select ref="select" :clearable="true" @clear="clearSelect" @remove-tag="removeTagChange"  v-model="addForm.departmentList" placeholder="请选择" multiple collapse-tags style="width:220px"><el-popoverplacement="right"width="400"trigger="click"v-model="popover"><div class="outer-container" @click="SelectVisible"><div class="inner-container"><div class="sel-input"><el-inputplaceholder="输入关键字进行过滤"v-model="filterTextAll"size="mini"@click="intClick"ref="inputRef"><i slot="suffix" class="el-input__icon el-icon-search"></i></el-input></div><div class="repeatUserStyle"><span>公司成员</span></div><!-- <el-option hidden v-for="item in branchList" :key="item.id" :value="item.id" :label="item.name+'——'+item.deptName" style="height: auto" /> --><el-treeclass="filter-tree":data="branchList2":props="defaultProps"node-key="id"show-checkboxdefault-expand-all:expand-on-click-node="true":filter-node-method="filterNodeAll"@check-change="handleCheckChange"@node-click="handleNodeClick"@check="handleCheckClick"ref="tree1"><span slot-scope="{ data }"><span>{{ data.deptName !== "全选" ? data.name+'——'+data.deptName : data.name}}</span></span></el-tree></div></div><div slot="reference" class="btnStyle"><el-button size="mini">点击选择公司成员</el-button></div></el-popover><div class="sel-input"><el-inputplaceholder="输入关键字进行过滤"v-model="filterText"size="mini"><i slot="suffix" class="el-input__icon el-icon-search"></i></el-input></div><div class="repeatUserStyle"><span>常用转发人</span><el-tooltip class="item" effect="dark" content="点击添加常用转发人" placement="right"><i class="el-icon-plus  cursor_pointer" @click="handleSetForwarderList"></i></el-tooltip></div><el-option hidden v-for="item in branchList" :key="item.id" :value="item.id" :label="item.name+'——'+item.deptName" style="height: auto" /><el-treeclass="filter-tree":data="roleBoolean === true ? receiverList : forwardList2":props="defaultProps"node-key="id"show-checkbox:default-expand-all="roleBoolean === true ? false : true":expand-on-click-node="true":filter-node-method="filterNode"@check-change="handleCheckChange"ref="tree"><!-- :check-strictly="systemNodeFlag" --></el-tree></el-select></el-form-item>

代码部分

export default {data() {return {filterText: "",filterTextAll: "",defaultProps: {value: "id",label: "name"},// 常用转发人数据forwardList2: [{id: "全选",name: "全选",string: "常用转发人",deptName: "全选",children: []}],branchList2: [{id: "全选",name: "全选",string: "公司成员",deptName: "全选",children: []}],selectedData: [], // 选中的节点receiverList: [{id: "全选",name: "市局领导",string: "常用转发人",deptName: "全选",children: []},{id: "全选",name: "部门领导",string: "常用转发人",deptName: "全选",children: []},{id: "全选",name: "县局领导",string: "常用转发人",deptName: "全选",children: []},{id: "全选",name: "其他",string: "常用转发人",deptName: "全选",children: []}]};},computed: {...mapGetters(["permission", "userInfo"]),},watch: {objId(newVal) {console.log(this.objId);this.fileParams.objectId = newVal;},//常用转发人,通过监听方式来代替focus(),//this.$refs.tree.filter(val);触发el-tree的filterNode过滤属性filterText(val) {this.$refs.tree.filter(val);},//filterTextAll(val) {this.$refs.tree1.filter(val);},// 过滤filterNode(value, data) {console.log("filterNode",value)if (!value) return true;return data.name.indexOf(value) !== -1;},filterNodeAll(value, data) {if (!value) return true;let filterRes = data.name.indexOf(value) !== -1 || data.deptName.indexOf(value) !== -1;return filterRes},// 点击tree组件的复选框节点触发handleCheckChange(data,checked) {if(checked === true) {if(data.id !== "全选") {this.addForm.departmentList.push(data.id)if(this.addForm.departmentList)this.SetArray(this.addForm.departmentList)this.$refs.tree.setChecked(data.id, true)this.$refs.tree1.setChecked(data.id, true)} else {// 解决过滤全选后的bugif(data.string === "常用转发人") {let checkKeys = this.$refs.tree.getCheckedKeys()checkKeys.forEach((i, n) => {let node = this.$refs.tree.getNode(i)if(!node.visible && node.checked) {this.$refs.tree.setChecked(i, false)}})} else {let checkKeys = this.$refs.tree1.getCheckedKeys()checkKeys.forEach((i, n) => {let node = this.$refs.tree1.getNode(i)if(!node.visible && node.checked) {this.$refs.tree1.setChecked(i, false)}})}}// this.$refs.tree.} else {if(this.addForm.departmentList.includes(data.id)) {this.addForm.departmentList.forEach((item, index, arr) => {if(item === data.id) {arr.splice(index, 1)}})this.$refs.tree.setChecked(data.id, false)this.$refs.tree1.setChecked(data.id, false)}}// if(data.id !== "全选") {//   this.$refs.select.toggleMenu()// } else {//   this.popover = false// }},// 下拉框清除项触发removeTagChange(val) {this.$refs.tree.setChecked(val, false)this.$refs.tree1.setChecked(val, false)this.$refs.select.blur()this.popover = false},// 点击删除全部clearSelect() {this.$refs.tree.setCheckedKeys([])this.$refs.tree1.setCheckedKeys([])this.addForm.departmentList = []this.popover = false},intClick() {this.$refs.inputRef.focus()},// 去重SetArray(arr) {this.addForm.departmentList = Array.from(new Set(arr))},// 添加常用转发人handleSetForwarderList() {this.dialogTableVisible = falsethis.popover = falsethis.$refs.select.blur()let id = this.$store.getters.userInfo.user_idthis.formInline={companyId:"",deptId:"",realName:"",roleId:""};getForwarderList(id, this.formInline1).then(res => {this.forwarder.forwarderList = res.data.data;this.forwarder.forwarderModel = true;this.forwarder.userName = "";this.forwarder.id = id;this.forwarder.selectionList = [];})this.getCompanyDept()},getCompanyDept(){let vm = thiscompanyOrDept(vm.formInline1.companyId).then(res =>{if(vm.formInline1.companyId === "" || vm.formInline1.companyId === null){vm.companyList = res.data.data;let col = {id: "",deptName: ""};vm.companyList.unshift(col);vm.deptList = [];vm.formInline1 = {companyId:"",deptId:"",realName: vm.formInline1.realName,roleId:vm.ids,}}else {vm.deptList = res.data.data;let col = {key: "",name: ""};vm.deptList.unshift(col);}});},//条件查询未添加到转发人员的列表searchForwarderList(){let that = this;getForwarderList(that.forwarder.id, that.formInline1).then(res => {that.forwarder.forwarderList = res.data.data;}).then(() => {//将已选择的数据选中for(var i=0;i<that.forwarder.forwarderList.length;i++){that.forwarder.selectionList.forEach(function(item){if(item.id === that.forwarder.forwarderList[i].id){that.$refs.table.toggleRowSelection(that.forwarder.forwarderList[i],true);}})}});},//添加转发人员addForwarder(){let that = this;//将已选人员id拼接var idList = "";that.forwarder.selectionList.forEach(function(item){idList = idList + item.id + ",";})addForwarder(that.forwarder.id, idList).then(res => {that.forwarder.forwarderModel = false;this.getForwardList()this.getCode()that.$message({type: "success",message: "操作成功!"});});},//selection状态修改(取消、选中)forwarderChange(selection, row){let that = this;//判断该数据是选中还是取消if(that.forwarder.selectionList == [] || that.forwarder.selectionList == undefined || that.forwarder.selectionList == null){that.forwarder.selectionList = [];that.forwarder.selectionList.push(row);return;}var i = 0;for(; i < that.forwarder.selectionList.length; i++){if(row.id == that.forwarder.selectionList[i].id){break;}}if(i == that.forwarder.selectionList.length){that.forwarder.selectionList.push(row);}else{if(that.forwarder.selectionList.length == 1){that.forwarder.selectionList = [];}else{that.forwarder.selectionList.splice(i, 1);}}},//全选未添加转发人员selectAll(selection){let that = this;if(selection != undefined){that.forwarder.selectionList = [];if(selection != []){that.forwarder.forwarderList.forEach(function(item){that.forwarder.selectionList.push(item);})}}},SelectVisible() {this.$refs.select.toggleMenu()this.$refs.inputRef.focus()},handleNodeClick() {this.$refs.select.toggleMenu()},handleCheckClick() {this.$refs.select.toggleMenu()},// 获取转发人权限getRole() {// 获取转发人的权限let userRoles = JSON.parse(localStorage.getItem("saber-userDetails")).content.roleAliasuserRoles = userRoles.split(',')let roleArr = ['ROLE_COMPANY_BOSS','admin','ROLE_COMPANY_CS','ROLE_DEPART_BOSS']this.roleBoolean = userRoles.some(item => {return roleArr.includes(item) === true})if(this.roleBoolean === true) {this.getRolesList()}},getRolesList() {getReceiverList().then(res => {let obj = res.data.datathis.receiverList[0].children = obj.市局领导this.receiverList[1].children = obj.部门负责人this.receiverList[2].children = obj.县局领导this.receiverList[3].children = obj.其他}).catch(() => {this.$message.error('获取常用转发人数据失败!')})}},},

拆分的组件:

<template><div><!-- 树形下拉框 --><el-select style="width: 100%" ref="select" :multiple="multiple" :clearable="true" @remove-tag="handleRemoveTag" @clear="handleClear" v-model="companyId"><div class="sel-input"><el-inputplaceholder="输入关键字进行过滤"v-model="filterText"size="mini"><i slot="suffix" class="el-input__icon el-icon-search"></i></el-input></div><el-option v-if="mineStatusValue.length == 0" hidden key="id" :value="selectVal" :label="selectName"></el-option><el-option v-else hidden v-for="(item, index) in mineStatusValue" :key="index" :label="parentLableVisble ? (item.parentLable + '——' + item[defaultProps.label]) : item[defaultProps.label]" :value="item[defaultProps.id]"></el-option><el-tree:data="receiverList":props="defaultProps":node-key="defaultProps.id":show-checkbox="multiple":expand-on-click-node="true":filter-node-method="filterNode"@check="handleCheckChange"@node-click="clickUnitTreeNode"ref="tree"></el-tree></el-select></div>
</template><script>
export default {props: {// 树形结构数据receiverList: {type: Array,require: true,default: () => []},// 树形结构默认配置defaultProps: {type: Object,default: () => {return {children: 'children',label: 'label',id: 'id'}}},// 是否多选multiple: {type: Boolean,default: () => {return false;}},// selectInput绑定的值companyId: {type: [Array, String, Number],default: ''},// 是否变成特殊结构:"XX"——"XX"parentLableVisble: {type: Boolean,default: false}},watch: {filterText(val) {this.$refs.tree.filter(val);}},data () {return {filterText: '',mineStatusValue: []}},methods: {// 树形结构数据过滤filterNode(value, data) {if (!value) return true;return data[this.defaultProps.label].indexOf(value) !== -1;},// 多选方法handleCheckChange(data) {if(!this.multiple) {return}let res = this.$refs.tree.getCheckedNodes(true)let key = this.$refs.tree.getCheckedKeys(true)this.mineStatusValue = res;// 全选 全选这里有个bug 记得在外面写方法是时候写一个去重方法if(data.children && data.children.length > 0) {data.children.forEach(items => {let a = this.mineStatusValue.some(item => item.value === items.value)if(a) {this.$emit('handleCheckChange', key, items)return}this.handleRemoveTag(items.value)})return}let a = this.mineStatusValue.some(item => item.value === data.value)if(a) {this.$emit('handleCheckChange', key, data)return}this.handleRemoveTag(data.value)},handleRemoveTag(value) {this.$refs.tree.setChecked(value, false);let res = this.$refs.tree.getCheckedNodes(true)this.mineStatusValue = res;this.$emit('handleRemoveTag', value)},handleClear() {if(this.multiple) {this.$refs.tree.setCheckedKeys([]);}this.mineStatusValue = []this.$emit('handleClear')},handleSelect(value) {this.$refs.tree.setCheckedKeys(value)let res = this.$refs.tree.getCheckedNodes(true)this.mineStatusValue = res;},// 单选方法clickUnitTreeNode(data) {if(this.multiple) {return}if(data && !data.children) {if(this.mineStatusValue.length === 0 || !(this.mineStatusValue.some(item => item.value === data.value))) {this.mineStatusValue.push(data)}this.$emit('clickUnitTreeNode', data)}}}
}
</script><style lang="scss" scoped>
.sel-input {margin: 5px;
}
::v-deep.el-select .el-tag__close.el-icon-close {background-color: #C0C4CC;right: -7px;top: -6px;
}
</style>

相关文章:

下拉框可筛选可树状多选组件

实际效果图片 父页面 <el-form-item label"转发&#xff1a;" :label-width"formLabelWidth" class"formflex_item"><el-select ref"select" :clearable"true" clear"clearSelect" remove-tag"r…...

【LeetCode】70.爬楼梯

题目 假设你正在爬楼梯。需要 n 阶你才能到达楼顶。 每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢&#xff1f; 示例 1&#xff1a; 输入&#xff1a;n 2 输出&#xff1a;2 解释&#xff1a;有两种方法可以爬到楼顶。 1. 1 阶 1 阶 2. 2 阶 示例 2…...

c#中的Math.Ceiling和Math.floor()和Math.Round()

Math.Ceiling(),只要有小数就加1(小数部分不为0&#xff09; 例如&#xff1a; Math.Ceiling(0.0) -> 0 Math.Ceiling(0.1) -> 1 Math.Ceiling(0.2) -> 1 Math.Ceiling(0.3) -> 1 Math.Ceiling(0.4) -> 1 Math.Ceiling(0.5) -> 1 Math.Ceiling(0.6) -> 1…...

C++day7(异常处理机制、Lambda表达式、类型转换、STL标准库模板、迭代器、list)

#include <iostream>using namespace std; template <typename T> class vector { private:T* first;T* last;T* end; public:vector():first(new T),last(first),end(first){cout<<"无参构造"<<endl;}//无参构造vector(T* f):first(f),last…...

性能优化问题

提升首屏的加载速度&#xff0c;是前端性能优化中「最重要」的环节&#xff0c;这里笔者梳理出一些 常规且有效 的首屏优化建议 1、路由懒加载 SPA 项目&#xff0c;一个路由对应一个页面&#xff0c;如果不做处理&#xff0c;项目打包后&#xff0c;会把所有页面打包成一个文…...

【云原生系列】云计算概念与架构设计介绍

1 什么是云计算 云计算是一种基于互联网的计算模式&#xff0c;在这个模式下&#xff0c;各种计算资源&#xff08;例如计算机、存储设备、网络设备、应用程序等&#xff09;可以通过互联网实现共享和交付。云计算架构设计的主要目标是实现高效、可扩展、可靠、安全和经济的计算…...

Swoole协程系统HTTP服务

先启动宝塔 /etc/init.d/bt start 源码参考 https://github.com/zhangyue0503/swoole/tree/main/4.Swoole%E5%8D%8F%E7%A8%8B 对于异步来说&#xff0c;我们需要监听事件&#xff0c;并且监听的进程是并发的&#xff0c;所以会有一个问题&#xff0c;那就是无法保证前后顺…...

SpringCloud学习路线(13)——分布式搜索ElasticSeach集群

前言 单机ES做数据存储&#xff0c;必然面临两个问题&#xff1a;海量数据的存储&#xff0c;单点故障。 如何解决这两个问题&#xff1f; 海量数据的存储问题&#xff1a; 将索引库从逻辑上拆分为N个分片&#xff08;shard&#xff09;&#xff0c;存储到多个节点。单点故障…...

CMIP6数据处理及在气候变化、水文、生态等领域中的应用

目录 专题一 CMIP6中的模式比较计划 专题二 数据下载 专题三 基础知识 专题四 单点降尺度 专题五 统计方法的区域降尺度 专题六 基于WRF模式的动力降尺度动态降尺度 专题七 典型应用案例-气候变化1 专题八 典型应用案例-气候变化2 专题九 典型应用案例-生态领域 专题…...

hadoop之mapreduce详解

一、概述 优化前我们需要知道hadoop适合干什么活&#xff0c;适合什么场景&#xff0c;在工作中&#xff0c;我们要知道业务是怎样的&#xff0c;能才结合平台资源达到最有优化。除了这些我们当然还要知道mapreduce的执行过程&#xff0c;比如从文件的读取&#xff0c;map处理&…...

leetcode做题笔记44

给你一个输入字符串 (s) 和一个字符模式 (p) &#xff0c;请你实现一个支持 ? 和 * 匹配规则的通配符匹配&#xff1a; ? 可以匹配任何单个字符。 * 可以匹配任意字符序列&#xff08;包括空字符序列&#xff09;。 判定匹配成功的充要条件是&#xff1a;字符模式必须能够 完…...

mac brew安装 node 踩坑日记- n切换node不生效

最近用了一个旧电脑开发&#xff0c;发现里面node管理混乱&#xff0c;有nvm、n和homebrew&#xff0c;导致切换node 切换不了&#xff0c;开发也有莫名其妙的错误。所以我打算重新装一下node&#xff0c;使用n做为管理工具。 1. 删除nvm cd ~ rm -rf .nvm2. 删除n sudo rm -…...

数据预处理matlab

matlab数据的获取、预处理、统计、可视化、降维 数据的预处理 - MATLAB & Simulink - MathWorks 中国https://ww2.mathworks.cn/help/matlab/preprocessing-data.html 一、数据的获取 1.1 从Excel中获取 使用readtable() 例1&#xff1a; 使用spreadsheetImportOption…...

ubuntu18.04安装autoware1.15

目录 前言一、准备工作1.安装autoware1.152.安装依赖3.把src/autoware/common/autoware_build_flags/cmake文件夹下的CUDA版本改为11.4&#xff08;或者你电脑上的版本&#xff09; 二、解决报错错误类型1错误类型2错误类型3错误类型4错误类型5错误类型6 前言 本文参考链接&am…...

在CSDN学Golang云原生(Docker基础)

一&#xff0c;docker安装配置 要在golang中使用Docker&#xff0c;需要先安装并配置好Docker。下面是基本的Docker安装和配置步骤&#xff1a; 下载并安装Docker 官方下载地址&#xff1a;https://docs.docker.com/get-docker/ 根据你的操作系统选择对应版本的Docker&…...

Zookeeper命令总结

目录 1、常用命令2、ls path3、create xxx创建持久化节点创建临时节点创建持久化序列节点 4、get path5、set path6、delete path7、监听器总结1&#xff09;节点的值变化监听2&#xff09;节点的子节点变化监听&#xff08;路径变化&#xff09;3&#xff09;当某个节点创建或…...

C语言中的函数(超详细)

C语言中的函数&#xff08;超详细&#xff09; 一、函数概述二、C语言中函数的分类1.库函数2.自定义函数三、函数的参数1.实际参数&#xff08;实参&#xff09;2.形式参数&#xff08;形参&#xff09;四、函数的调用1.传值调用2.传址调用五、函数的嵌套调用和链式访问1.嵌套调…...

华为H3C思科网络设备命令对照表

类别命令功能华为H3C思科通用取消关闭当前设置undoundono通用显示查看displaydisplayshow通用退回上级quitquitquit通用设置设备名称sysnamesysnamehostname通用到全局模式system-viewsystem-viewenable config terminal通用删除文件deletedeletedelete通用重启设备rebootreboo…...

产品需求、系统架构设计经验篇

需求设计思维导图UML 建模原型规范什么样的需求该忽略1.拍拍脑袋得来的想法&#xff0c;往往是没用的2.用户反馈的信息&#xff0c;不应该直接纳入需求3.扭改用户习惯的需求&#xff0c;一律不考虑 什么样的需求该重视1.从运维系统中根据数据结果分析得出的结论2.重视有洞见者的…...

关于websocket的几点注意事项

第一、普通websocket直接集成即可 <!-- Spring Websocket 相关依赖 --> <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-websocket</artifactId> </dependency> 第二、web后端两点,创…...

进程地址空间(比特课总结)

一、进程地址空间 1. 环境变量 1 &#xff09;⽤户级环境变量与系统级环境变量 全局属性&#xff1a;环境变量具有全局属性&#xff0c;会被⼦进程继承。例如当bash启动⼦进程时&#xff0c;环 境变量会⾃动传递给⼦进程。 本地变量限制&#xff1a;本地变量只在当前进程(ba…...

DeepSeek 赋能智慧能源:微电网优化调度的智能革新路径

目录 一、智慧能源微电网优化调度概述1.1 智慧能源微电网概念1.2 优化调度的重要性1.3 目前面临的挑战 二、DeepSeek 技术探秘2.1 DeepSeek 技术原理2.2 DeepSeek 独特优势2.3 DeepSeek 在 AI 领域地位 三、DeepSeek 在微电网优化调度中的应用剖析3.1 数据处理与分析3.2 预测与…...

蓝桥杯 2024 15届国赛 A组 儿童节快乐

P10576 [蓝桥杯 2024 国 A] 儿童节快乐 题目描述 五彩斑斓的气球在蓝天下悠然飘荡&#xff0c;轻快的音乐在耳边持续回荡&#xff0c;小朋友们手牵着手一同畅快欢笑。在这样一片安乐祥和的氛围下&#xff0c;六一来了。 今天是六一儿童节&#xff0c;小蓝老师为了让大家在节…...

【单片机期末】单片机系统设计

主要内容&#xff1a;系统状态机&#xff0c;系统时基&#xff0c;系统需求分析&#xff0c;系统构建&#xff0c;系统状态流图 一、题目要求 二、绘制系统状态流图 题目&#xff1a;根据上述描述绘制系统状态流图&#xff0c;注明状态转移条件及方向。 三、利用定时器产生时…...

鱼香ros docker配置镜像报错:https://registry-1.docker.io/v2/

使用鱼香ros一件安装docker时的https://registry-1.docker.io/v2/问题 一键安装指令 wget http://fishros.com/install -O fishros && . fishros出现问题&#xff1a;docker pull 失败 网络不同&#xff0c;需要使用镜像源 按照如下步骤操作 sudo vi /etc/docker/dae…...

【JavaSE】绘图与事件入门学习笔记

-Java绘图坐标体系 坐标体系-介绍 坐标原点位于左上角&#xff0c;以像素为单位。 在Java坐标系中,第一个是x坐标,表示当前位置为水平方向&#xff0c;距离坐标原点x个像素;第二个是y坐标&#xff0c;表示当前位置为垂直方向&#xff0c;距离坐标原点y个像素。 坐标体系-像素 …...

网络编程(UDP编程)

思维导图 UDP基础编程&#xff08;单播&#xff09; 1.流程图 服务器&#xff1a;短信的接收方 创建套接字 (socket)-----------------------------------------》有手机指定网络信息-----------------------------------------------》有号码绑定套接字 (bind)--------------…...

【无标题】路径问题的革命性重构:基于二维拓扑收缩色动力学模型的零点隧穿理论

路径问题的革命性重构&#xff1a;基于二维拓扑收缩色动力学模型的零点隧穿理论 一、传统路径模型的根本缺陷 在经典正方形路径问题中&#xff08;图1&#xff09;&#xff1a; mermaid graph LR A((A)) --- B((B)) B --- C((C)) C --- D((D)) D --- A A -.- C[无直接路径] B -…...

GitHub 趋势日报 (2025年06月06日)

&#x1f4ca; 由 TrendForge 系统生成 | &#x1f310; https://trendforge.devlive.org/ &#x1f310; 本日报中的项目描述已自动翻译为中文 &#x1f4c8; 今日获星趋势图 今日获星趋势图 590 cognee 551 onlook 399 project-based-learning 348 build-your-own-x 320 ne…...

Web后端基础(基础知识)

BS架构&#xff1a;Browser/Server&#xff0c;浏览器/服务器架构模式。客户端只需要浏览器&#xff0c;应用程序的逻辑和数据都存储在服务端。 优点&#xff1a;维护方便缺点&#xff1a;体验一般 CS架构&#xff1a;Client/Server&#xff0c;客户端/服务器架构模式。需要单独…...