首页 > 其他分享 >ant-table tree结构连线

ant-table tree结构连线

时间:2024-09-30 18:22:48浏览次数:1  
标签:return level tree ant record num table const

做一个类似这样的效果

template

                    <a-table class="custom-tree-table" rowKey="id" :dataSource="tableData1" :pagination="false"
                        :defaultExpandAllRows="true" :expandable="expandable" @expand='expandedRowsChange'>
                        <!-- 使用插槽自定义第一列的内容 -->
                        <a-table-column key="name" :title="i18nLanguage.global.t('user_permissions.table.locationName')"
                            data-index="name" :width="'70%'" style="height: 47px;">
                            <template #default="{ record }">
                                <div :style="getLineStyle(record)" v-if="!unexpandedRowKeys.includes(record.id)"></div>
                                <div :style="getLineStyle1(record)">
                                </div>
                                <span style="color: #0073bb;font-weight: bold; cursor: pointer;">
                                    {{ record.name }}
                                </span>
                            </template>
                        </a-table-column>
                        <a-table-column key="permission" data-index="permission">
                            <template #title>
                                {{ i18nLanguage.global.t('user_permissions.table.permission') }}
                                <EditOutlined class="ms-2" />
                            </template>
                            <template #default="{ record }">
                                <div class="flex justify-between my-permission p-3" v-show="!record.show"
                                    @click="record.show = true">
                                    {{ record.permission }}
                                    <EditOutlined class="ms-2 my-icon" />
                                </div>
                                <!-- <span > -->
                                <div class="flex justify-between items-center my-permission px-3" v-show="record.show"
                                    style="height: 44px;">
                                    <a-select style="width: 200px;" v-model:value="record.permission1"
                                        :allowClear="true">
                                        <a-select-option v-for="(item, key) in permissionList" :key="key"
                                            :value="item.value">{{
                                                item.label }}</a-select-option>
                                    </a-select>
                                    <div>
                                        <CloseOutlined class="mx-2" @click="record.show = false" />
                                        <CheckOutlined class="mx-2" @click="changPermission(record)" />
                                    </div>
                                </div>
                                <!-- </span> -->
                            </template>
                        </a-table-column>
                    </a-table>

methods

const getLineStyle = (record) => {
    // height: 100px; width: 1px; background-color: red; position: absolute; top:22px; left: 10px;
    const { level, num } = getNodeLevel(record);
    // if (level == 0) {
    //     console.log(num);
    // }
    return {
        height: level == 0 ? (num * 2 * 23) + num + 1 + 'px' : 0,
        width: '1px',
        backgroundColor: '#545b64',
        position: 'absolute',
        top: level == 0 ? '23px' : 0,
        left: '8px',
        zIndex: 1111
    };
}

const getLineStyle1 = (record) => {
    return {
        width: record.children ? (record.level * 20) - 16 + 'px' : record.level * 20 + 'px',
        height: '1px',
        backgroundColor: '#545b64',
        position: 'absolute',
        top: '23px',
        left: '9px',
    };
}

const countTreeSubsets = (tree) => {
    if (!tree) return 0; // 如果树为空,则子集数量为0
    if (unexpandedRowKeys.value.includes(tree.id)) return 1 // 这个没有展开就直算他一个
    let count = 1; // 初始化计数器,加上当前节点

    for (let child of tree.children || []) {
        // 对每个子节点递归调用并累加结果
        count += countTreeSubsets(child);
    }

    return count; // 返回总的子集数量
}



const getNodeLevel = (node, level = 0) => {
    // 递归计算树节点的深度
    if (node.children) {
        return { level, num: countTreeSubsets(node) - 1 };
    } else {
        level += 1
        return { level, num: 1 };
    }
}

 

标签:return,level,tree,ant,record,num,table,const
From: https://www.cnblogs.com/shuangzikun/p/18442309/a-table-line

相关文章

  • Qt项目中,在main.cpp中定义了一个自定义组件,但是在编译的时候报错`undefined reference
    1、问题描述我在测试Qt项目的main.cpp中编写了如下代码:classMyWidget1:publicQWidget{Q_OBJECT};//main程序入口argc命令行变量的数量argv命令行变量的数组intmain(intargc,char*argv[]){//应用程序对象,在Qt中应用程序对象有且仅有一个QAppl......
  • yunhantu绘制学习
    1. pymnet主页网址:https://mnets.github.io/pymnet/index.html Thelibraryisbasedonthegeneraldefinitionof multilayernetworks presentedina reviewarticle.Multilayernetworkscanbeusedtorepresentvarioustypesnetworkgeneralizationsfoun......
  • 红黑树(Red-Black Tree):原理、常见算法及其应用
    目录引言红黑树的基本概念常见算法插入节点查找节点删除节点红黑树的应用场景1.数据库索引2.符号表3.动态集合总结优势对比自平衡条件旋转次数操作效率应用场景实现复杂度引言红黑树(Red-BlackTree)是一种自平衡的二叉查找树,它的设计目的是为了在最坏的......
  • AVLTree【c++实现】
    目录AVL树1.AVL树的概念2.AVLTree节点的定义3.AVLTree的插入4.AVLTree的旋转4.1左单旋4.2右单旋4.3左右双旋4.4右左双旋5.AVLTree的验证6.AVLTree的性能AVL树AVLTree的代码实现连接:AVLTree代码链接1.AVL树的概念学习了二叉搜索树之后,我们知道二叉搜索树虽可以......
  • PlantSimulation的socket交互之TCP
    PlantSimulation的socket交互之TCP 1.python的socketTCP客户端建立其实可以任选python或plantsimulation作为客户端,博主因研究需要,将python设为客户端。plant设为服务器。1"""2CreatedonSatDecember1421:00:0020213@author:ZhangLitong-NanjingUniversity......
  • 生信机器学习入门4 - 构建决策树(Decision Tree)和随机森林(Random Forest)分类器
    机器学习文章回顾生信机器学习入门1-数据预处理与线性回归(Linearregression)预测生信机器学习入门2-机器学习基本概念生信机器学习入门3-Scikit-Learn训练机器学习分类感知器生信机器学习入门4-scikit-learn训练逻辑回归(LR)模型和支持向量机(SVM)模型1.决策树(Dec......
  • 1043 Is It a Binary Search Tree——PAT甲级
    ABinarySearchTree(BST)isrecursivelydefinedasabinarytreewhichhasthefollowingproperties:Theleftsubtreeofanodecontainsonlynodeswithkeyslessthanthenode'skey.Therightsubtreeofanodecontainsonlynodeswithkeysgreater......
  • 每天认识几个maven依赖(ant)
    二十一、ant1、是什么?Ant是一种用于构建和管理Java项目的工具,它在Maven出现之前就已经存在。虽然Maven和Ant都可以用于构建Java项目,但它们的设计理念和使用方式有所不同。构建工具:Ant是一个基于Java的构建工具,使用XML文件(build.xml)来定义构建过程。灵活......
  • COMP 412 Local Register Allocation Table of Contents
    COMP412,Fall2024Lab2:LocalRegisterAllocationTableofContentsCriticalDatesfortheProjectIntroductionCodeDueDate10/23/2024OverviewoftheProblemCodeCheck#1Due10/04/2024CodeSpecification3IntroductionInthisprogrammingass......
  • AI绘画爆款治愈系创作,你还不知道?Stable Diffusion 轻松复刻某书爆款动漫卡通治愈文案
    前言情感治愈类一直是受众群体很高非常火爆的赛道,老徐也关注到在某书平台上,漫画治愈类风格的内容也是非常的受欢迎。先来看看以下一些案例看看这几个账号内容的质量就可以看出该部分内容是很受欢迎的,结合平台的用户群体成分,老徐觉得这个是非常值得尝试的一个创作赛道。......