2021-12-30 00:44:43 +08:00
|
|
|
|
::: anchor
|
|
|
|
|
:::
|
|
|
|
|
|
2021-10-09 14:59:38 +08:00
|
|
|
|
::: demo
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<lay-tree
|
|
|
|
|
:data="data"
|
2021-10-11 18:09:38 +08:00
|
|
|
|
:onlyIconControl="iconCtrl"
|
|
|
|
|
:showLine="showLine"
|
2021-10-13 15:41:04 +08:00
|
|
|
|
:showCheckbox="showCheckbox"
|
2022-03-24 16:55:08 +08:00
|
|
|
|
accordion
|
2021-10-14 16:37:17 +08:00
|
|
|
|
v-model:checkedKeys="checkedKeys"
|
2021-10-11 18:09:38 +08:00
|
|
|
|
@node-click="handleClick"
|
2021-10-19 18:22:46 +08:00
|
|
|
|
:disabled="disabled"
|
2021-10-09 14:59:38 +08:00
|
|
|
|
>
|
|
|
|
|
</lay-tree>
|
2021-10-11 18:09:38 +08:00
|
|
|
|
<br/>
|
2021-10-13 15:41:04 +08:00
|
|
|
|
是否可开启选择框:
|
|
|
|
|
<br/>
|
|
|
|
|
<lay-switch v-model="showCheckbox"></lay-switch>
|
|
|
|
|
<br/>
|
2021-10-14 16:37:17 +08:00
|
|
|
|
checkedKeys:
|
|
|
|
|
<pre>
|
|
|
|
|
{{ checkedKeys }}
|
|
|
|
|
</pre>
|
2021-10-11 18:09:38 +08:00
|
|
|
|
只能通过节点左侧图标来展开收缩:
|
|
|
|
|
<br/>
|
|
|
|
|
<lay-switch v-model="iconCtrl"></lay-switch>
|
|
|
|
|
<br/>
|
2021-10-11 18:11:11 +08:00
|
|
|
|
是否开启连接线:
|
2021-10-11 18:09:38 +08:00
|
|
|
|
<br/>
|
|
|
|
|
<lay-switch v-model="showLine"></lay-switch>
|
|
|
|
|
<br/>
|
|
|
|
|
当前点击的节点:
|
|
|
|
|
<br/>
|
|
|
|
|
<pre>
|
2021-10-14 16:37:17 +08:00
|
|
|
|
{{ clickNode }}
|
2021-10-11 18:09:38 +08:00
|
|
|
|
</pre>
|
2021-10-19 18:22:46 +08:00
|
|
|
|
<br/>
|
2021-10-11 18:09:38 +08:00
|
|
|
|
</template>
|
2021-10-09 14:59:38 +08:00
|
|
|
|
|
|
|
|
|
<script setup>
|
2021-10-13 15:41:04 +08:00
|
|
|
|
import { ref } from 'vue';
|
2021-10-09 14:59:38 +08:00
|
|
|
|
|
2021-10-14 16:37:17 +08:00
|
|
|
|
const data = ref([{
|
|
|
|
|
title: '一级1',
|
|
|
|
|
id: 1,
|
|
|
|
|
field: 'name1',
|
|
|
|
|
checked: true,
|
|
|
|
|
spread: true,
|
|
|
|
|
children: [{
|
|
|
|
|
title: '二级1-1 可允许跳转',
|
|
|
|
|
id: 3,
|
|
|
|
|
field: 'name11',
|
|
|
|
|
href: 'https://www.layui.com/',
|
|
|
|
|
children: [{
|
|
|
|
|
title: '三级1-1-3',
|
|
|
|
|
id: 23,
|
|
|
|
|
field: '',
|
|
|
|
|
children: [{
|
|
|
|
|
title: '四级1-1-3-1',
|
|
|
|
|
id: 24,
|
|
|
|
|
field: '',
|
|
|
|
|
children: [{
|
|
|
|
|
title: '五级1-1-3-1-1',
|
|
|
|
|
id: 30,
|
|
|
|
|
field: ''
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '五级1-1-3-1-2',
|
|
|
|
|
id: 31,
|
|
|
|
|
field: ''
|
|
|
|
|
}]
|
|
|
|
|
}]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '三级1-1-1',
|
|
|
|
|
id: 7,
|
|
|
|
|
field: '',
|
|
|
|
|
children: [{
|
|
|
|
|
title: '四级1-1-1-1 可允许跳转',
|
|
|
|
|
id: 15,
|
|
|
|
|
field: '',
|
|
|
|
|
href: 'https://www.layui.com/doc/'
|
|
|
|
|
}]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '三级1-1-2',
|
|
|
|
|
id: 8,
|
|
|
|
|
field: '',
|
|
|
|
|
children: [{
|
|
|
|
|
title: '四级1-1-2-1',
|
|
|
|
|
id: 32,
|
|
|
|
|
field: ''
|
|
|
|
|
}]
|
|
|
|
|
}]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '二级1-2',
|
|
|
|
|
id: 4,
|
|
|
|
|
spread: true,
|
|
|
|
|
children: [{
|
|
|
|
|
title: '三级1-2-1',
|
|
|
|
|
id: 9,
|
|
|
|
|
field: '',
|
|
|
|
|
disabled: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '三级1-2-2',
|
|
|
|
|
id: 10,
|
|
|
|
|
field: ''
|
|
|
|
|
}]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '二级1-3',
|
|
|
|
|
id: 20,
|
|
|
|
|
field: '',
|
|
|
|
|
children: [{
|
|
|
|
|
title: '三级1-3-1',
|
|
|
|
|
id: 21,
|
|
|
|
|
field: ''
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '三级1-3-2',
|
|
|
|
|
id: 22,
|
|
|
|
|
field: ''
|
|
|
|
|
}]
|
|
|
|
|
}]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '一级2',
|
|
|
|
|
id: 2,
|
|
|
|
|
field: '',
|
|
|
|
|
spread: true,
|
|
|
|
|
children: [{
|
|
|
|
|
title: '二级2-1',
|
|
|
|
|
id: 5,
|
|
|
|
|
field: '',
|
|
|
|
|
spread: true,
|
|
|
|
|
children: [{
|
|
|
|
|
title: '三级2-1-1',
|
|
|
|
|
id: 11,
|
|
|
|
|
field: ''
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '三级2-1-2',
|
|
|
|
|
id: 12,
|
|
|
|
|
field: ''
|
|
|
|
|
}]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '二级2-2',
|
|
|
|
|
id: 6,
|
|
|
|
|
field: '',
|
|
|
|
|
children: [{
|
|
|
|
|
title: '三级2-2-1',
|
|
|
|
|
id: 13,
|
|
|
|
|
field: ''
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '三级2-2-2',
|
|
|
|
|
id: 14,
|
|
|
|
|
field: '',
|
|
|
|
|
disabled: true
|
|
|
|
|
}]
|
|
|
|
|
}]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '一级3',
|
|
|
|
|
id: 16,
|
|
|
|
|
field: '',
|
|
|
|
|
children: [{
|
|
|
|
|
title: '二级3-1',
|
|
|
|
|
id: 17,
|
|
|
|
|
field: '',
|
|
|
|
|
fixed: true,
|
|
|
|
|
children: [{
|
|
|
|
|
title: '三级3-1-1',
|
|
|
|
|
id: 18,
|
|
|
|
|
field: ''
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '三级3-1-2',
|
|
|
|
|
id: 19,
|
|
|
|
|
field: ''
|
|
|
|
|
}]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '二级3-2',
|
|
|
|
|
id: 27,
|
|
|
|
|
field: '',
|
|
|
|
|
children: [{
|
|
|
|
|
title: '三级3-2-1',
|
|
|
|
|
id: 28,
|
|
|
|
|
field: ''
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '三级3-2-2',
|
|
|
|
|
id: 29,
|
|
|
|
|
field: ''
|
|
|
|
|
}]
|
|
|
|
|
}]
|
|
|
|
|
}]);
|
2021-10-11 18:09:38 +08:00
|
|
|
|
|
2021-10-13 15:41:04 +08:00
|
|
|
|
const iconCtrl = ref(false);
|
|
|
|
|
const showLine = ref(true);
|
|
|
|
|
const clickNode = ref(null);
|
|
|
|
|
const showCheckbox = ref(true);
|
2021-10-18 00:55:58 +08:00
|
|
|
|
const checkedKeys = ref([1]);
|
2021-10-19 18:22:46 +08:00
|
|
|
|
const disabled = ref(false);
|
2021-10-11 18:09:38 +08:00
|
|
|
|
|
|
|
|
|
function handleClick(node) {
|
|
|
|
|
clickNode.value = node
|
|
|
|
|
}
|
2021-10-09 14:59:38 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
:::
|
2021-10-14 17:41:45 +08:00
|
|
|
|
|
2022-01-10 01:17:03 +08:00
|
|
|
|
::: title Tree 属性
|
2021-10-14 17:41:45 +08:00
|
|
|
|
:::
|
|
|
|
|
|
2021-11-07 15:55:08 +08:00
|
|
|
|
::: table
|
|
|
|
|
|
2021-10-19 18:23:36 +08:00
|
|
|
|
| Name | Description | Accepted Values |
|
|
|
|
|
| -------------------------------- | ---------------------------------------- | --------------- |
|
|
|
|
|
| data | 树型组件数据,类型 TreeData \| TreeData[] | null |
|
|
|
|
|
| showCheckbox | 是否显示复选框 | false |
|
|
|
|
|
| onlyIconControl | 是否仅允许节点左侧图标控制展开收缩 | false |
|
|
|
|
|
| showLine | 是否开启连接线 | true |
|
|
|
|
|
| checkedKeys(v-model:checkedKeys) | 开启 showCheckbox 后, 选中的节点 | [] |
|
2021-10-19 18:22:46 +08:00
|
|
|
|
|
2021-11-07 15:55:08 +08:00
|
|
|
|
:::
|
2021-10-19 18:22:46 +08:00
|
|
|
|
|
2022-01-10 01:17:03 +08:00
|
|
|
|
::: title Tree 数据
|
2021-10-19 18:22:46 +08:00
|
|
|
|
:::
|
2021-11-07 15:55:08 +08:00
|
|
|
|
|
|
|
|
|
::: table
|
|
|
|
|
|
2021-11-07 15:56:24 +08:00
|
|
|
|
| Name | Description | Accepted Values |
|
2021-11-07 21:50:38 +08:00
|
|
|
|
| -------- | -------------- | --------------- |
|
2021-11-07 15:56:24 +08:00
|
|
|
|
| id | 唯一值 | - |
|
|
|
|
|
| title | 节点名称 | - |
|
|
|
|
|
| children | 子节点 | [] |
|
|
|
|
|
| disabled | 该节点是否禁用 | false |
|
2021-11-07 21:50:38 +08:00
|
|
|
|
| spread | 该节点是否展开 | false |
|
2021-10-14 17:41:45 +08:00
|
|
|
|
|
2021-11-07 15:55:08 +08:00
|
|
|
|
:::
|
2021-10-14 17:41:45 +08:00
|
|
|
|
|
2022-01-10 01:17:03 +08:00
|
|
|
|
::: title Tree 事件
|
2021-10-14 17:41:45 +08:00
|
|
|
|
:::
|
|
|
|
|
|
2021-11-07 15:55:08 +08:00
|
|
|
|
::: table
|
|
|
|
|
|
2021-10-19 18:23:36 +08:00
|
|
|
|
| Name | Description | Accepted Params |
|
|
|
|
|
| ---------- | --------------- | --------------- |
|
|
|
|
|
| node-click | 节点 click 事件 | -- |
|
2021-11-07 15:55:08 +08:00
|
|
|
|
|
2021-11-07 15:56:24 +08:00
|
|
|
|
:::
|
2021-12-16 17:57:59 +08:00
|
|
|
|
|
|
|
|
|
::: comment
|
2022-01-12 14:19:06 +08:00
|
|
|
|
:::
|
|
|
|
|
|
|
|
|
|
::: previousNext tree
|
2022-03-24 16:55:08 +08:00
|
|
|
|
:::
|