Vue-easy-tree封装及使用

1.使用及安装

下载依赖
npm install @wchbrad/vue-easy-tree引入俩种方案
1.在main.js中引入
import VueEasyTree from "@wchbrad/vue-easy-tree";
import "@wchbrad/vue-easy-tree/src/assets/index.scss"
Vue.use(VueEasyTree)2.当前页面引入
import VueEasyTree from "@wchbrad/vue-easy-tree";
import "@wchbrad/vue-easy-tree/src/assets/index.scss"

2.封装vue-easy-tree

<template><div class='select-tree-container' ref="selectMutiple"><el-inputautocomplete="off":placeholder="loading?'正在加载数据···':placeholder":readonly="true":disabled="loading":value="checkedTreeData"><i v-show="loading" slot="suffix" class="el-input__icon el-icon-loading"></i></el-input><transition name="sub-comments"><divclass="scroll-container"v-show="selectTreeFlag"><el-inputplaceholder="输入关键字进行过滤"v-model="filterText"></el-input><VueEasyTree:data="treeData"show-checkboxheight="500px":node-key="treeProps.value":props="treeProps":default-checked-keys="newArr"ref="selectMutipleTree"@check="handleCheck":filter-node-method="filterNode":check-strictly="checkStrictly"></VueEasyTree></div></transition></div>
</template><script>
import VueEasyTree from "@wchbrad/vue-easy-tree";
// 样式文件,可以根据需要自定义样式或主题
import "@wchbrad/vue-easy-tree/src/assets/index.scss"
import {debounce} from '@/shared/debounceAndtThrottle.js'
export default {name: 'SelectMutipleTree',components: {VueEasyTree},props: {treeData: {type: Array,required: true,default:[],},treeProps: {type: Object,default: function () {return {value: 'id',label: 'orgName',checkStrictly: true}}},checkedTreeData: {type: String,required: true},placeholder: {type: String,default: '请输入'},checkStrictly: {type: Boolean,default: false},loading: {type: Boolean,default: true},defaultCheckedKeys:{type: Array,default:() => {return []},}},data () {return {selectTreeFlag: false,filterText: '',filterText_:null,newArr:[]}},watch: {checkedTreeData: function (newValue) {if (!newValue) {this.$nextTick(() => {this.$refs.selectMutipleTree.setCheckedKeys([])})}},filterText(val) {this.filterText_(val)},treeData(val){var num = 0this.chuli(val,num)},defaultCheckedKeys(val){if(val.length == 0) {this.newArr =[]}else{this.chuliCheckedKeys(this.treeData, val)}}},methods: {chuliCheckedKeys(list, val){list.forEach(item => {val.forEach(i => {if(item[this.treeProps.value].split('-')[0] === i){i= item[this.treeProps.value]this.newArr.push(i)}})if(item[this.treeProps.children]){this.chuliCheckedKeys(item[this.treeProps.children], val)}})},chuli(list,num){list.forEach(i=>{num++i[this.treeProps.value] = i[this.treeProps.value] + "-" + num;if(i[this.treeProps.children]){this.chuli(i[this.treeProps.children],num)}})},handleCheck (checkedNodes, checkedKeys) {checkedKeys.checkedNodes.forEach((f) => {f[this.treeProps.value] =  f[this.treeProps.value].split('-')[0]});this.$emit('handleCheckData', checkedKeys.checkedNodes)},filterNode(value, data) {if (!value) return true;return data[this.treeProps.label].includes(value);}},created () {},mounted () {if (!this.checkedTreeData) {this.$nextTick(() => {this.$refs.selectMutipleTree.setCheckedKeys([])})}this.$refs.selectMutiple && this.$refs.selectMutiple.addEventListener('click', (event) => {const ev = event || window.eventif (ev.stopPropagation) {ev.stopPropagation()} else {ev.cancelable = true}this.selectTreeFlag =  !this.loading && true})this.$root.$el.addEventListener('click', (event) => {this.selectTreeFlag = false})this.filterText_ = debounce((val)=>this.$refs.selectMutipleTree.filter(val), 1000)},destroyed () {}
}
</script>
<style lang="scss" scoped>
.scroll-container {max-height: 600px;overflow-y: auto;position: absolute;z-index: 10;width: 100%;border: 1px solid #eeeeee;border-top: none;background: #ffffff;::v-deep {.el-scrollbar__wrap {overflow-x: hidden;}}
}
.sub-comments-leave-active,.sub-comments-enter-active {transition: max-height 0.1s linear;
}
.sub-comments-enter,.sub-comments-leave-to {max-height:0 ;opacity: 0;
}
.sub-comments-enter-to,.sub-comments-leave {max-height: 136px ;
}
</style>

3.具体页面该如何使用

<select-mutiple-tree  size="mini" style="display: inline-block" :treeData="organizationTree" :treeProps="releaseTreeProps" :loading="treeLoading" :checkedTreeData="addCaseForm.copyToUserListName" 
placeholder="请选择"  @handleCheckData="handleCheck" :checkStrictly="releaseTreeProps.checkStrictly">
</select-mutiple-tree>1.data中定义organizationTree: [],treeLoading: true, //控制人员树加载状态releaseTreeProps: {value: "nodeIdAndType",label: "nodeName",children: "organizationTreeUserSingeNodeList",checkStrictly: false,},addCaseForm: {copyToUserListName:'',copyToUserList:[], //抄送人}
2.引入及注册import SelectMutipleTree from "@/components/selectMutipleTree";components:{SelectMutipleTree }
3.接口中写接口名字().then((response) => {const { data, success } = response;if (success) {this.organizationTree = data;this.treeLoading = false;} else {this.organizationTree = [];this.treeLoading = false;}}).catch((error) => {this.organizationTree = [];this.treeLoading = false;});
4.方法handleCheck(checkedData) {if (checkedData.length > 0) {// 集合var namesArr = [];var idsArr = [];var userName = [];checkedData.forEach((f) => {if (f.nodeType !== 0) {namesArr.push(f.nodeName);idsArr.push(f.nodeId)userName.push({id: f.nodeId,name: f.nodeName,});}});this.addCaseForm.copyToUserListName = namesArr.join(";");this.addCaseForm.copyToUserList = idsArr;} else {this.addCaseForm.copyToUserListName = '';this.addCaseForm.copyToUserList = [];}},

 5.具体返回的后台格式

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/454654.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

PiflowX新增Apache Beam引擎支持

参考资料&#xff1a; Apache Beam 架构原理及应用实践-腾讯云开发者社区-腾讯云 (tencent.com) 在之前的文章中有介绍过&#xff0c;PiflowX是支持spark和flink计算引擎&#xff0c;其架构图如下所示&#xff1a; 在piflow高度抽象的流水线组件的支持下&#xff0c;我们可以…

2024第九届国际发酵培养基应用与发展技术论坛会议通知

会议简介 随着科技的不断发展,发酵技术已逐渐成为生物制造中的重要支撑&#xff0c;发酵技术应用领域更加广泛。发酵培养基是影响生物发酵产业技术水平、环境友好程度的重要因素之一&#xff0c;为进一步推动发酵培养基的科学应用&#xff0c;提升发酵培养基的高效、稳定应用&…

电商推荐系统

此篇博客主要记录一下商品推荐系统的主要实现过程。 一、获取用户对商品的偏好值 代码实现 package zb.grms;import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.Doub…

开发大佬为什么都不喜欢关电脑?

引言 在平时工作中&#xff0c;咱们程序员这一群体往往展现出一些特有的行为习惯&#xff0c;其中之一便是不喜欢频繁地关闭电脑、拒绝关机、长久待机、特别是苹果的机器。 下面从技术分析与用户行为研究的角度出发&#xff0c;将深入探讨程序员倾向于保持电脑开机状态的原因…

数字孪生网络攻防模拟与城市安全演练

在数字化浪潮的推动下&#xff0c;网络攻防模拟和城市安全演练成为维护社会稳定的不可或缺的环节。基于数字孪生技术我们能够在虚拟环境中进行高度真实的网络攻防模拟&#xff0c;为安全专业人员提供实战经验&#xff0c;从而提升应对网络威胁的能力。同时&#xff0c;在城市安…

P60_ib公式推导2

永磁无刷直流电机B相电流值推导过程&#xff08;t2过程&#xff09;

RabbitMQ-1.介绍与安装

介绍与安装 1.RabbitMQ1.0.技术选型1.1.安装1.2.收发消息1.2.1.交换机1.2.2.队列1.2.3.绑定关系1.2.4.发送消息 1.2.数据隔离1.2.1.用户管理1.2.3.virtual host 1.RabbitMQ 1.0.技术选型 消息Broker&#xff0c;目前常见的实现方案就是消息队列&#xff08;MessageQueue&…

springboot155基于JAVA语言的在线考试与学习交流网页平台

简介 【毕设源码推荐 javaweb 项目】基于springbootvue 的 适用于计算机类毕业设计&#xff0c;课程设计参考与学习用途。仅供学习参考&#xff0c; 不得用于商业或者非法用途&#xff0c;否则&#xff0c;一切后果请用户自负。 看运行截图看 第五章 第四章 获取资料方式 **项…

智能优化算法 | Matlab实现飞蛾扑火(MFO)(内含完整源码)

文章目录 效果一览文章概述源码设计参考资料效果一览 文章概述 智能优化算法 | Matlab实现飞蛾扑火(MFO)(内含完整源码) 源码设计 %%%% clear all clc SearchAgents_no=100; % Number of search ag

Photoshop 2023下载安装教程,免费直装版,2步搞定安装,附安装包

准备工作&#xff1a; 1、提前准备好photoshop 2023安装包 没有的可以参考下面方式获取 2、系统要求Windows 10 及以上 安装步骤 1.找到下载好的安装包&#xff0c;直接双击解压 2.双击运行【Set-up.exe】文件 3.点击文件夹图标&#xff0c;更改安装位置 4.点击【继续】&a…

服务攻防-端口协议桌面应用QQWPS等RCEhydra口令猜解未授权检测

知识点&#xff1a; 1、端口协议-弱口令&未授权&攻击方式等 2、桌面应用-社交类&文档类&工具类等 章节点&#xff1a; 1、目标判断-端口扫描&组合判断&信息来源 2、安全问题-配置不当&CVE漏洞&弱口令爆破 3、复现对象-数据库&中间件&…

【已解决】pt文件转onnx后再转rknn时得到推理图片出现大量锚框变花屏

前言 环境介绍&#xff1a; 1.编译环境 Ubuntu 18.04.5 LTS 2.RKNN版本 py3.8-rknn2-1.4.0 3.单板 迅为itop-3568开发板 一、现象 采用yolov5训练并将pt转换为onnx&#xff0c;再将onnx采用py3.8-rknn2-1.4.0推理转换为rknn&#xff0c;rknn模型能正常转换&#xff0c;…