2020-09-28 20:19:10 +08:00
|
|
|
<template>
|
2021-01-05 21:45:05 +08:00
|
|
|
<PageWrapper title="Tree基础示例">
|
|
|
|
|
<div class="flex">
|
2021-05-29 00:48:56 +08:00
|
|
|
<BasicTree
|
|
|
|
|
:treeData="treeData"
|
|
|
|
|
title="基础示例,默认展开第一层"
|
|
|
|
|
defaultExpandLevel="1"
|
|
|
|
|
class="w-1/3"
|
|
|
|
|
/>
|
2020-09-28 20:19:10 +08:00
|
|
|
|
2021-05-22 22:36:19 +08:00
|
|
|
<BasicTree
|
|
|
|
|
:treeData="treeData"
|
2021-05-29 00:48:56 +08:00
|
|
|
title="可勾选,默认全部展开"
|
2021-05-22 22:36:19 +08:00
|
|
|
:checkable="true"
|
|
|
|
|
class="w-1/3 mx-4"
|
2021-05-29 23:08:10 +08:00
|
|
|
defaultExpandAll
|
2021-05-22 22:36:19 +08:00
|
|
|
@check="handleCheck"
|
|
|
|
|
/>
|
2020-09-28 20:19:10 +08:00
|
|
|
|
2021-03-03 23:35:30 +08:00
|
|
|
<BasicTree
|
2021-05-29 00:48:56 +08:00
|
|
|
title="指定默认展开/勾选示例"
|
2021-03-03 23:35:30 +08:00
|
|
|
:treeData="treeData"
|
|
|
|
|
:checkable="true"
|
|
|
|
|
:expandedKeys="['0-0']"
|
|
|
|
|
:checkedKeys="['0-0']"
|
|
|
|
|
class="w-1/3"
|
|
|
|
|
/>
|
2021-01-05 21:45:05 +08:00
|
|
|
</div>
|
2021-06-23 15:53:31 +08:00
|
|
|
<div class="flex">
|
2021-07-02 02:27:33 +08:00
|
|
|
<BasicTree
|
|
|
|
|
title="异步树"
|
|
|
|
|
ref="asyncTreeRef"
|
|
|
|
|
:treeData="tree"
|
|
|
|
|
class="w-1/3"
|
|
|
|
|
:load-data="onLoadData"
|
|
|
|
|
/>
|
2021-06-23 15:53:31 +08:00
|
|
|
</div>
|
2021-01-05 21:45:05 +08:00
|
|
|
</PageWrapper>
|
2020-09-28 20:19:10 +08:00
|
|
|
</template>
|
|
|
|
|
<script lang="ts">
|
2021-07-02 02:27:33 +08:00
|
|
|
import { defineComponent, ref, unref } from 'vue';
|
|
|
|
|
import { BasicTree, TreeActionType } from '/@/components/Tree/index';
|
2020-09-28 20:19:10 +08:00
|
|
|
import { treeData } from './data';
|
2021-01-05 21:45:05 +08:00
|
|
|
import { PageWrapper } from '/@/components/Page';
|
2020-09-28 20:19:10 +08:00
|
|
|
|
|
|
|
|
export default defineComponent({
|
2021-03-03 23:35:30 +08:00
|
|
|
components: { BasicTree, PageWrapper },
|
2020-09-28 20:19:10 +08:00
|
|
|
setup() {
|
2021-07-02 02:27:33 +08:00
|
|
|
const asyncTreeRef = ref<Nullable<TreeActionType>>(null);
|
2021-05-22 22:36:19 +08:00
|
|
|
function handleCheck(checkedKeys, e) {
|
|
|
|
|
console.log('onChecked', checkedKeys, e);
|
|
|
|
|
}
|
2021-06-23 15:53:31 +08:00
|
|
|
const tree = ref([
|
|
|
|
|
{
|
|
|
|
|
title: 'parent ',
|
|
|
|
|
key: '0-0',
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
function onLoadData(treeNode) {
|
|
|
|
|
return new Promise((resolve: (value?: unknown) => void) => {
|
|
|
|
|
if (!treeNode.children) {
|
|
|
|
|
resolve();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setTimeout(() => {
|
2021-07-02 02:27:33 +08:00
|
|
|
const asyncTreeAction: TreeActionType | null = unref(asyncTreeRef);
|
|
|
|
|
if (asyncTreeAction) {
|
|
|
|
|
const nodeChildren = [
|
|
|
|
|
{ title: `Child Node ${treeNode.eventKey}-0`, key: `${treeNode.eventKey}-0` },
|
|
|
|
|
{ title: `Child Node ${treeNode.eventKey}-1`, key: `${treeNode.eventKey}-1` },
|
|
|
|
|
];
|
|
|
|
|
asyncTreeAction.updateNodeByKey(treeNode.eventKey, { children: nodeChildren });
|
|
|
|
|
asyncTreeAction.setExpandedKeys([
|
|
|
|
|
treeNode.eventKey,
|
|
|
|
|
...asyncTreeAction.getExpandedKeys(),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-23 15:53:31 +08:00
|
|
|
resolve();
|
|
|
|
|
return;
|
|
|
|
|
}, 1000);
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-07-02 02:27:33 +08:00
|
|
|
return { treeData, handleCheck, tree, onLoadData, asyncTreeRef };
|
2020-09-28 20:19:10 +08:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
</script>
|