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

element select + tree

element select + tree的使用

在这里插入图片描述

<template slot="action1" slot-scope="text, record, index"><el-select v-model="record.tagValue" multiple placeholder="请选择":filter-method="(e) => filterTree(e, index)" filterable @remove-tag="(e) => removeTag(e, index)"><el-option><template slot="default"><div><el-tree :data="record.option" show-checkbox node-key="id":props="defaultProps" :ref="'tree' + index":filter-node-method="filterNode"@check-change="(data, isSelect, childSelect) => handleCurrentChange(data, isSelect, childSelect, index)"><template #default="{ node }"><div v-html='highlightName(node,searchVal)'></div></template></el-tree></div></template></el-option></el-select>
</template>
// 搜索
filterNode(value, data) {if (!value) return true;return data.name.indexOf(value) !== -1;
},
filterTree(val, index) {this.searchVal = vallet tree = 'tree' + indexthis.$refs[tree].filter(this.searchVal);
},
// 搜索字体高亮
highlightName (item,val) {let textHtml = "";if (val) {let highlightTextList = val.split("#~~~~");let newName = item.data.name;highlightTextList.forEach((text) => {if (item.data.name.indexOf(text) > -1) {newName = newName.replaceAll(text,`<span class="minddleContent">${text}</span>`);}});textHtml += newName;} else {textHtml += item.data.name;}return textHtml;
},
// 获取知识树选中值
handleCurrentChange(data, isSelect, childSelect, index) {let tree = 'tree' + indexlet nodes = this.$refs[tree].getCheckedNodes()let arrId = []if (nodes.length > 0) {nodes.map(item => {arrId.push(item.id)})}let listData = this.dataSource[index].optionlet listText = this.getStructuredKeys(arrId, nodes, listData)this.dataSource[index].tagValue = listText.map(item => {return item.name})
},
// 知识树选中值递归,选中子集只展示子集,父级全选只展示父级
getStructuredKeys(keys, list, listData) {const result = [];const processNode = (nodes) => {nodes.forEach((node) => {if (keys.includes(node.id)) {result.push(node);} else {if (node.children) {const childKeys = this.getStructuredKeys(keys, list, node.children);console.log(childKeys)if (childKeys.length > 0) {result.push(...childKeys);}}}});};processNode(listData);return this.sortSelectedItems(result, list);
},
// 选中项排序
sortSelectedItems(result, list) {const SelectedItems = result.map(v => v.id)const sortList = [];list.filter(item => {if (SelectedItems.includes(item.id)) {sortList.push(item);}})return sortList
},
// 移除select-tree选中值
removeTag(tag, index) {let tree = 'tree' + indexconst checkNodes = this.$refs[tree].getCheckedNodes();const newCheckNodes = checkNodes.filter(item => {return item.name !== tag})const removeIds = [];const removeNodes = checkNodes.filter(item => {return item.name === tag});this.getNodeChildIds(removeNodes, removeIds)const checkIds = []newCheckNodes.forEach(item => {if (!removeIds.includes(item.id)) {checkIds.push(item.id);}})this.$refs[tree].setCheckedKeys(checkIds)
},
// 移除选中递归
getNodeChildIds(nodes, result) {nodes.forEach(item => {result.push(item.id)if (item.children && item.children.length > 0) {this.getNodeChildIds(item.children, result)}})
},
http://www.lryc.cn/news/434137.html

相关文章:

  • LeetCode之矩阵
  • Windows文件系统介绍与基本概念解析
  • 使用 Apache POI 实现 Java Word 模板占位符替换功能
  • 第三届人工智能与智能信息处理国际学术会议(AIIIP 2024)
  • 【动手学深度学习】04 数据操作 + 数据预处理(个人向笔记)
  • 本地搭建 Whisper 语音识别模型
  • 数据集成-缝合一套数据仓库Infra的臆想
  • 运营有哪几种?
  • Android视频编辑:利用FFmpeg实现高级功能
  • 图片无损缩放PhotoZoom Pro 9.0.2绿色版 +免费赠送PhotoZoom激活优惠代码
  • tekton pipelineresources
  • OFDM系统PAPR算法的MATLAB仿真,对比SLM,PTS以及CAF,对比不同傅里叶变换长度
  • 常见概念 -- 光回波损耗
  • uni-app环境搭建
  • 数据结构 栈 队列
  • 嵌入式学习路线+嵌入式校招建议 嵌入式学习面试规划
  • 服务器深度学习环境配置
  • 使用 Parallel 类进行多线程编码(下)
  • 基于微信小程序+Java+SSM+Vue+MySQL的药店管理系统
  • C#使用MQTT(一):MQTT服务端
  • AD原理图update为pcb
  • 应用海外仓系统后,可以改善哪些海外仓的核心业务流程?
  • SQL进阶技巧:截止当前批次前的批次量与订单量 | 移动窗口问题
  • C#中的Graphics类和SetQuality()自定义方法
  • 圣诞节:白酒与西式料理的异国风情
  • 2.ChatGPT的发展历程:从GPT-1到GPT-4(2/10)
  • yjs01——机器学习的过程
  • Git工作流程
  • Qt-QWidget的font属性(18)
  • Go语言概述