mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-05 04:37:47 +08:00
6256bde3a0
* docs(components): [tree-v2] add some disabled nodes * docs(components): [tree-v2] add some disabled nodes
49 lines
1.0 KiB
Vue
49 lines
1.0 KiB
Vue
<template>
|
|
<el-tree-v2 :data="data" :props="props" show-checkbox :height="208" />
|
|
</template>
|
|
<script lang="ts" setup>
|
|
interface Tree {
|
|
id: string
|
|
label: string
|
|
children?: Tree[]
|
|
disabled: boolean
|
|
}
|
|
|
|
const getKey = (prefix: string, id: number) => {
|
|
return `${prefix}-${id}`
|
|
}
|
|
|
|
const createData = (
|
|
maxDeep: number,
|
|
maxChildren: number,
|
|
minNodesNumber: number,
|
|
deep = 1,
|
|
key = 'node'
|
|
): Tree[] => {
|
|
let id = 0
|
|
return Array.from({ length: minNodesNumber })
|
|
.fill(deep)
|
|
.map(() => {
|
|
const childrenNumber =
|
|
deep === maxDeep ? 0 : Math.round(Math.random() * maxChildren)
|
|
const nodeKey = getKey(key, ++id)
|
|
return {
|
|
id: nodeKey,
|
|
label: nodeKey,
|
|
children: childrenNumber
|
|
? createData(maxDeep, maxChildren, childrenNumber, deep + 1, nodeKey)
|
|
: undefined,
|
|
disabled: nodeKey.includes('2'),
|
|
}
|
|
})
|
|
}
|
|
|
|
const props = {
|
|
value: 'id',
|
|
label: 'label',
|
|
children: 'children',
|
|
disabled: 'disabled',
|
|
}
|
|
const data = createData(4, 30, 40)
|
|
</script>
|