2021-11-02 22:36:47 +08:00
|
|
|
<template>
|
|
|
|
<div class="custom-tree-node-container">
|
2022-02-06 09:18:11 +08:00
|
|
|
<el-tree
|
|
|
|
:data="data"
|
|
|
|
show-checkbox
|
|
|
|
node-key="id"
|
|
|
|
default-expand-all
|
|
|
|
:expand-on-click-node="false"
|
|
|
|
:props="{ class: customNodeClass }"
|
|
|
|
/>
|
2021-11-02 22:36:47 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2021-12-21 15:51:33 +08:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import type Node from 'element-plus/es/components/tree/src/model/node'
|
2021-11-02 22:36:47 +08:00
|
|
|
|
2021-12-21 15:51:33 +08:00
|
|
|
interface Tree {
|
|
|
|
id: number
|
|
|
|
label: string
|
|
|
|
isPenultimate?: boolean
|
|
|
|
children?: Tree[]
|
|
|
|
}
|
|
|
|
|
|
|
|
const customNodeClass = (data: Tree, node: Node) => {
|
|
|
|
if (data.isPenultimate) {
|
|
|
|
return 'is-penultimate'
|
|
|
|
}
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
const data: Tree[] = [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
label: 'Level one 1',
|
|
|
|
children: [
|
2021-11-02 22:36:47 +08:00
|
|
|
{
|
2021-12-21 15:51:33 +08:00
|
|
|
id: 4,
|
|
|
|
label: 'Level two 1-1',
|
2021-11-02 22:36:47 +08:00
|
|
|
isPenultimate: true,
|
|
|
|
children: [
|
|
|
|
{
|
2021-12-21 15:51:33 +08:00
|
|
|
id: 9,
|
|
|
|
label: 'Level three 1-1-1',
|
2021-11-02 22:36:47 +08:00
|
|
|
},
|
|
|
|
{
|
2021-12-21 15:51:33 +08:00
|
|
|
id: 10,
|
|
|
|
label: 'Level three 1-1-2',
|
2021-11-02 22:36:47 +08:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-12-21 15:51:33 +08:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 2,
|
|
|
|
label: 'Level one 2',
|
|
|
|
isPenultimate: true,
|
|
|
|
children: [
|
2021-11-02 22:36:47 +08:00
|
|
|
{
|
2021-12-21 15:51:33 +08:00
|
|
|
id: 5,
|
|
|
|
label: 'Level two 2-1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 6,
|
|
|
|
label: 'Level two 2-2',
|
2021-11-02 22:36:47 +08:00
|
|
|
},
|
2021-12-21 15:51:33 +08:00
|
|
|
],
|
2021-11-02 22:36:47 +08:00
|
|
|
},
|
2021-12-21 15:51:33 +08:00
|
|
|
{
|
|
|
|
id: 3,
|
|
|
|
label: 'Level one 3',
|
|
|
|
isPenultimate: true,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
id: 7,
|
|
|
|
label: 'Level two 3-1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 8,
|
|
|
|
label: 'Level two 3-2',
|
|
|
|
},
|
|
|
|
],
|
2021-11-02 22:36:47 +08:00
|
|
|
},
|
2021-12-21 15:51:33 +08:00
|
|
|
]
|
2021-11-02 22:36:47 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.is-penultimate > .el-tree-node__content {
|
2022-04-19 12:38:12 +08:00
|
|
|
color: #626aef;
|
2021-11-02 22:36:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
.el-tree-node.is-expanded.is-penultimate > .el-tree-node__children {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
}
|
|
|
|
.is-penultimate > .el-tree-node__children > div {
|
|
|
|
width: 25%;
|
|
|
|
}
|
|
|
|
</style>
|