feat: 添加BasicTree使用 fieldNames 后,actionList 和 插槽 会失效的示例代码

This commit is contained in:
zuihou 2021-12-10 22:19:43 +08:00
parent 8523afd512
commit 13d660bede
2 changed files with 140 additions and 30 deletions

View File

@ -1,22 +1,20 @@
<template>
<PageWrapper title="Tree函数操作示例">
<div class="flex">
<Row :gutter="[16, 16]">
<Col :span="8">
<BasicTree
class="w-1/3"
title="右侧操作按钮/自定义图标"
helpMessage="帮助信息"
:treeData="treeData"
:actionList="actionList"
:renderIcon="createIcon"
/>
</Col>
<Col :span="8">
<BasicTree title="右键菜单" :treeData="treeData" :beforeRightClick="getRightMenuList" />
</Col>
<Col :span="8">
<BasicTree
class="w-1/3 mx-4"
title="右键菜单"
:treeData="treeData"
:beforeRightClick="getRightMenuList"
/>
<BasicTree
class="w-1/3"
title="工具栏使用"
toolbar
checkable
@ -24,18 +22,44 @@
:treeData="treeData"
:beforeRightClick="getRightMenuList"
/>
</div>
</Col>
<Col :span="8">
<BasicTree title="没有fieldNames插槽有效" helpMessage="正确的示例" :treeData="treeData3">
<template #title="item"> 插槽{{ item.name }} </template>
</BasicTree>
</Col>
<Col :span="8">
<BasicTree
title="有fieldNames后插槽失效"
helpMessage="错误的示例, 应该显示插槽的内容才对"
:fieldNames="{ key: 'id', title: 'name' }"
:treeData="treeData2"
>
<template #title="item"> 插槽{{ item.title }} </template>
</BasicTree>
</Col>
<Col :span="8">
<BasicTree
title="有fieldNames后actionList失效"
helpMessage="错误的示例,应该在鼠标移上去时,显示新增和删除按钮才对"
:treeData="treeData3"
:actionList="actionList"
:fieldNames="{ key: 'key', title: 'name' }"
/>
</Col>
</Row>
</PageWrapper>
</template>
<script lang="ts">
import { defineComponent, h } from 'vue';
import { BasicTree, ActionItem, ContextMenuItem } from '/@/components/Tree/index';
import { treeData } from './data';
import { Row, Col } from 'ant-design-vue';
import { BasicTree, TreeActionItem, ContextMenuItem } from '/@/components/Tree/index';
import { treeData, treeData2, treeData3 } from './data';
import { PlusOutlined, DeleteOutlined } from '@ant-design/icons-vue';
import { PageWrapper } from '/@/components/Page';
export default defineComponent({
components: { BasicTree, PageWrapper },
components: { BasicTree, PageWrapper, Row, Col },
setup() {
function handlePlus(node: any) {
console.log(node);
@ -59,7 +83,7 @@
},
];
}
const actionList: ActionItem[] = [
const actionList: TreeActionItem[] = [
{
// show:()=>boolean;
render: (node) => {
@ -90,7 +114,7 @@
}
return '';
}
return { treeData, actionList, getRightMenuList, createIcon };
return { treeData, treeData2, treeData3, actionList, getRightMenuList, createIcon };
},
});
</script>

View File

@ -33,3 +33,89 @@ export const treeData: TreeItem[] = [
],
},
];
export const treeData2: any[] = [
{
name: 'parent ',
id: '0-0',
slots: { title: 'title' },
children: [
{ name: 'leaf', id: '0-0-0', slots: { title: 'title' } },
{
name: 'leaf',
id: '0-0-1',
slots: { title: 'title' },
children: [
{
name: 'leaf',
slots: { title: 'title' },
id: '0-0-0-0',
children: [{ name: 'leaf', id: '0-0-0-0-1', slots: { title: 'title' } }],
},
{ name: 'leaf', slots: { title: 'title' }, id: '0-0-0-1' },
],
},
],
},
{
name: 'parent 2',
id: '1-1',
slots: { title: 'title' },
children: [
{ name: 'leaf', slots: { title: 'title' }, id: '1-1-0' },
{ name: 'leaf', slots: { title: 'title' }, id: '1-1-1' },
],
},
{
name: 'parent 3',
id: '2-2',
slots: { title: 'title' },
children: [
{ name: 'leaf', slots: { title: 'title' }, id: '2-2-0' },
{ name: 'leaf', slots: { title: 'title' }, id: '2-2-1' },
],
},
];
export const treeData3: any[] = [
{
name: 'parent ',
key: '0-0',
slots: { title: 'title' },
children: [
{ name: 'leaf', key: '0-0-0', slots: { title: 'title' } },
{
name: 'leaf',
key: '0-0-1',
slots: { title: 'title' },
children: [
{
name: 'leaf',
slots: { title: 'title' },
key: '0-0-0-0',
children: [{ name: 'leaf', key: '0-0-0-0-1', slots: { title: 'title' } }],
},
{ name: 'leaf', slots: { title: 'title' }, key: '0-0-0-1' },
],
},
],
},
{
name: 'parent 2',
key: '1-1',
slots: { title: 'title' },
children: [
{ name: 'leaf', slots: { title: 'title' }, key: '1-1-0' },
{ name: 'leaf', slots: { title: 'title' }, key: '1-1-1' },
],
},
{
name: 'parent 3',
key: '2-2',
slots: { title: 'title' },
children: [
{ name: 'leaf', slots: { title: 'title' }, key: '2-2-0' },
{ name: 'leaf', slots: { title: 'title' }, key: '2-2-1' },
],
},
];