树结构添加分组,向上向下添加同级,添加子级

server/2024/9/24 8:21:43/

树结构添加分组,向上向下添加同级,添加子级

  • 效果
  • 代码实现
    • 页面
    • js

效果

在这里插入图片描述

代码实现

页面

                <el-tree :data="treeData" :props="defaultProps" :expand-on-click-node="false":filter-node-method="filterNode" :ref="'tree_' + item.name" :id="'tree' + item.name" node-key="id":current-node-key="defaultKeys" default-expand-all highlight-current @node-click="handleNodeClick"><span class="custom-tree-node" slot-scope="{ node, data }"><el-input :key="data.id" autofocus size="mini" class=" w-75 text-left" :id="data.id"v-show="data.isEdit" v-model="form.serviceName" @keyup.enter.native="addApiGroup" @blur="addApiGroup"></el-input><el-tooltip :content="node.label" placement="right-start" transition="el-zoom-in-top" effect="light"><span v-if="!data.isEdit" class="textLine1 tree-label d-flex align-items-center"><img class="imgAlign-textBottom mr-1":src="data.isGroup == 1 ? require('../../../assets/images/folder.png') : require('../../../assets/images/code.png')"alt=""><span class=''> {{ node.label }}</span></span></el-tooltip><el-popover v-if="data.isGroup == 1" placement="bottom-start" width="100" trigger="click"id="myPopover"><div><el-link class="ml-0 mb-2" :underline="false" size="mini" type="info"@click="handleAdd('api', node, data)"><img src="../../../assets/images/code_line.png" alt="" class="mr-2" />新增接口</el-link><el-popover placement="right-start" width="100" trigger="click"><el-link class="d-block ml-0  mb-2" :underline="false" size="mini" type="info"@click="handleAdd('group', node, data, 'up', $event)">上方添加分组</el-link><el-link class="d-block mb-2 ml-0" :underline="false" size="mini" type="info"@click="handleAdd('group', node, data, 'down')">下方添加分组</el-link><el-link class="d-block ml-0" :underline="false" size="mini" type="info"@click="handleAdd('group', node, data, 'child')">添加子分组</el-link><el-link class="ml-0 mb-2 addGroup" :underline="false" size="mini" type="info"slot="reference"><span><img src="../../../assets/images/bulletpoint.png" alt="" class="mr-2" />新增分组</span><img src="../../../assets/images/chevron-right.png" alt="" class="mr-2" /></el-link></el-popover><el-link class="d-block ml-0  mb-2" :underline="false" size="mini" type="info"@click="handleEdit('group', node, data)"><img src="../../../assets/images/folder_line.png"alt="" class="mr-2" />编辑分组</el-link><el-link class="d-block ml-0" :underline="false" size="mini" type="info"@click="handleDelete(node, data)"><img src="../../../assets/images/delete.png" alt=""class="mr-2" />删除</el-link></div><el-button class="ml-2" size="mini" icon="el-icon-more" type="text" slot="reference"></el-button></el-popover></span></el-tree>

js

javascript">export default {name: 'AppCenterDetail',components: { apiList },data() {return {treeData: [],defaultProps: {children: 'children',label: 'label',},}},created() {this.form.id = this.$route.query.appIdthis.appId = this.$route.query.appIdthis.getAppDetail(this.$route.query.appId)},mounted() {},methods: {// 节点单击事件handleNodeClick(data, node) {this.form.serviceName = data.labelthis.queryParams.parentId = data.idthis.defaultKeys = data.idlet tree = {id: 0,children: this.treeData};// 调接口提交addApiGroup() {},handleAdd(node, data, pageType){const treeDOM = this.$refs['tree_' + this.activeName][0]const id = Math.ceil(Math.random() * 100);const newData = { id: id, parentId: data ? data.id : 0, label: '', isEdit: true, isNew: true, children: [] }this.$set(this.form, 'isGroup', 1)if (pageType == 'up') {this.$set(this.form, 'upOrder', data.orderNum)this.$set(this.form, 'isUp', 0)this.$set(this.form, 'orderNum', data.orderNum - 1)this.$set(this.form, 'parentId', data ? data.parentId : 0)this.$set(this.form, 'upId', data.id)treeDOM.insertBefore(newData, node)// 聚焦setTimeout(() => {document.getElementById(newData.id).focus()}, 500);} else if (pageType == 'down') {this.$set(this.form, 'upOrder', data.orderNum)this.$set(this.form, 'isUp', 1)this.$set(this.form, 'orderNum', data.orderNum + 1)this.$set(this.form, 'parentId', data ? data.parentId : 0)this.$set(this.form, 'upId', data.id)treeDOM.insertAfter(newData, node)// 聚焦setTimeout(() => {document.getElementById(newData.id).focus()}, 500);} else if (pageType == 'child') {if (this.currentNodeLevel >= 4) {this.$modal.msgWarning('当前树最多可加四级,已超出')} else {this.$set(this.form, 'upOrder', data.orderNum)this.$set(this.form, 'isUp', 2)this.$set(this.form, 'parentId', data.id)treeDOM.append(newData, node)treeDOM.store.nodesMap[data.id].expanded = true// 聚焦setTimeout(() => {document.getElementById(newData.id).focus()}, 500);}} else {this.addGroupVisible = truethis.$set(this.form, 'parentId', 0)this.$set(this.form, 'isUp', 2)}},},
}

http://www.ppmy.cn/server/62253.html

相关文章

初学SpringMVC之 JSON 篇

JSON&#xff08;JavaScript Object Notation&#xff0c;JS 对象标记&#xff09;是一种轻量级的数据交换格式 采用完全独立于编程语言的文本格式来存储和表示数据 JSON 键值对是用来保存 JavaScript 对象的一种方式 比如&#xff1a;{"name": "张三"}…

Python 列表及其常用操作详解

在Python编程中&#xff0c;列表&#xff08;List&#xff09;是一种非常常见且重要的数据结构。列表是一个有序的集合&#xff0c;可以包含任意类型的元素。列表是可变的&#xff0c;这意味着你可以在列表创建后对其进行修改&#xff0c;如添加、删除和更新元素。本文将详细介…

萝卜快跑的「悖论」

本文将探讨无人车带来的出行变革与现有交通生态之间的冲突&#xff0c;以及如何寻找技术创新与社会伦理之间的平衡点。 「做无人车的初衷&#xff0c;不是为了抢出租车网约车司机的生意&#xff0c;而是为了更好的服务老百姓&#xff0c;提供一种新的出行方式。」百度副总裁王云…

语音识别概述

语音识别概述 一.什么是语音&#xff1f; 语音是语言的声学表现形式&#xff0c;是人类自然的交流工具。 图片来源&#xff1a;https://www.shenlanxueyuan.com/course/381 二.语音识别的定义 语音识别&#xff08;Automatic Speech Recognition, ASR 或 Speech to Text, ST…

MySQL与Redis优化

MySQL优化策略&#xff1a; 查询优化&#xff1a;使用EXPLAIN分析查询语句&#xff0c;优化JOIN操作&#xff0c;减少子查询和复杂的WHERE条件。索引优化&#xff1a;合理创建索引以加快查询速度&#xff0c;同时避免过度索引导致写性能下降。数据类型优化&#xff1a;使用合适…

使用Apache服务部署静态网站

前言&#xff1a;本博客仅作记录学习使用&#xff0c;部分图片出自网络&#xff0c;如有侵犯您的权益&#xff0c;请联系删除 目录 一、网站服务程序 ​二、配置服务文件参数 ​三、SELinux安全子系统 四、个人用户主页功能 ​五、虚拟网站主机功能 六、Apache的访问控制…

【linux】【深度学习】fairseq框架安装踩坑

直接pip install fairseq发现跑代码时候老是容易崩&#xff0c;所以选择用源码编译安装。 python环境选择3.8以上都行&#xff0c;我选择3.10 首先安装torch&#xff0c; 我选择安装pip install torch1.13.1 torchaudio0.13.1以及cuda 11.7 &#xff08;具体cuda根据个人显卡进…

WEB前端03-CSS3基础

CSS3基础 1.CSS基本概念 CSS是Cascading Style Sheets&#xff08;层叠样式表&#xff09;的缩写&#xff0c;它是一种对Web文档添加样式的简单机制&#xff0c;是一种表现HTML或XML等文件外观样式的计算机语言&#xff0c;是一种网页排版和布局设计的技术。 CSS的特点 纯C…