2020-09-28 20:19:10 +08:00
|
|
|
<template>
|
2021-01-05 21:45:05 +08:00
|
|
|
<PageWrapper title="Tree函数操作示例">
|
|
|
|
|
<div class="flex">
|
2021-03-02 23:14:36 +08:00
|
|
|
<CollapseContainer title="右侧操作按钮/自定义图标" class="mr-4" :style="{ width: '33%' }">
|
|
|
|
|
<BasicTree :treeData="treeData" :actionList="actionList" :renderIcon="createIcon" />
|
2021-01-05 21:45:05 +08:00
|
|
|
</CollapseContainer>
|
2020-09-28 20:19:10 +08:00
|
|
|
|
2021-01-05 21:45:05 +08:00
|
|
|
<CollapseContainer title="右键菜单" class="mr-4" :style="{ width: '33%' }">
|
|
|
|
|
<BasicTree :treeData="treeData" :beforeRightClick="getRightMenuList" />
|
|
|
|
|
</CollapseContainer>
|
|
|
|
|
</div>
|
|
|
|
|
</PageWrapper>
|
2020-09-28 20:19:10 +08:00
|
|
|
</template>
|
|
|
|
|
<script lang="ts">
|
|
|
|
|
import { defineComponent, h } from 'vue';
|
|
|
|
|
import { BasicTree, ActionItem, ContextMenuItem } from '/@/components/Tree/index';
|
|
|
|
|
import { treeData } from './data';
|
|
|
|
|
import { CollapseContainer } from '/@/components/Container/index';
|
|
|
|
|
import { PlusOutlined, DeleteOutlined } from '@ant-design/icons-vue';
|
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-01-05 21:45:05 +08:00
|
|
|
components: { BasicTree, CollapseContainer, PageWrapper },
|
2020-09-28 20:19:10 +08:00
|
|
|
setup() {
|
|
|
|
|
function handlePlus(node: any) {
|
|
|
|
|
console.log(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getRightMenuList(node: any): ContextMenuItem[] {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
label: '新增',
|
|
|
|
|
handler: () => {
|
|
|
|
|
console.log('点击了新增', node);
|
|
|
|
|
},
|
2020-12-08 00:22:55 +08:00
|
|
|
icon: 'bi:plus',
|
2020-09-28 20:19:10 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: '删除',
|
|
|
|
|
handler: () => {
|
|
|
|
|
console.log('点击了删除', node);
|
|
|
|
|
},
|
2020-12-08 00:22:55 +08:00
|
|
|
icon: 'bx:bxs-folder-open',
|
2020-09-28 20:19:10 +08:00
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
const actionList: ActionItem[] = [
|
|
|
|
|
{
|
|
|
|
|
render: (node) => {
|
|
|
|
|
return h(PlusOutlined, {
|
|
|
|
|
class: 'ml-2',
|
|
|
|
|
onClick: () => {
|
|
|
|
|
handlePlus(node);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
render: () => {
|
|
|
|
|
return h(DeleteOutlined);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
];
|
2021-03-02 23:14:36 +08:00
|
|
|
|
|
|
|
|
function createIcon({ level }) {
|
|
|
|
|
if (level === 1) {
|
|
|
|
|
return 'ion:git-compare-outline';
|
|
|
|
|
}
|
|
|
|
|
if (level === 2) {
|
|
|
|
|
return 'ion:home';
|
|
|
|
|
}
|
|
|
|
|
if (level === 3) {
|
|
|
|
|
return 'ion:airplane';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return { treeData, actionList, getRightMenuList, createIcon };
|
2020-09-28 20:19:10 +08:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
</script>
|