-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
203 additions
and
49 deletions.
There are no files selected for viewing
122 changes: 77 additions & 45 deletions
122
packages/effects/common-ui/src/components/table/table-tree/table-tree.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,87 @@ | ||
<script setup lang="ts"> | ||
import { ref } from 'vue'; | ||
import { DirectoryTree, type TreeProps } from 'ant-design-vue'; | ||
const expandedKeys = ref<string[]>(['0-0', '0-1']); | ||
const selectedKeys = ref<string[]>([]); | ||
const treeData: TreeProps['treeData'] = [ | ||
{ | ||
key: '0-0', | ||
title: 'parent 0', | ||
children: [ | ||
{ | ||
title: 'leaf 0-0', | ||
key: '0-0-0', | ||
isLeaf: true, | ||
}, | ||
{ | ||
title: 'leaf 0-1', | ||
key: '0-0-1', | ||
isLeaf: true, | ||
}, | ||
], | ||
}, | ||
{ | ||
key: '0-1', | ||
title: 'parent 1', | ||
children: [ | ||
{ | ||
title: 'leaf 1-0', | ||
key: '0-1-0', | ||
isLeaf: true, | ||
}, | ||
{ | ||
title: 'leaf 1-1', | ||
key: '0-1-1', | ||
isLeaf: true, | ||
}, | ||
], | ||
}, | ||
]; | ||
import type { EventDataNode } from 'ant-design-vue/es/tree'; | ||
import type { TableTreeProps } from './types'; | ||
import { computed, ref } from 'vue'; | ||
import { useForwardProps } from '@vben/hooks'; | ||
import { | ||
DirectoryTree, | ||
Dropdown, | ||
Menu, | ||
MenuItem, | ||
type TreeProps, | ||
} from 'ant-design-vue'; | ||
interface Props extends TableTreeProps {} | ||
const props = defineProps<Props>(); | ||
const emits = defineEmits<{ | ||
(event: 'contextMenu', treeKey: string, menuKey: number | string): void; | ||
(event: 'selectTree', node: EventDataNode): void; | ||
}>(); | ||
const expandedKeys = ref<TreeProps['expandedKeys']>([]); | ||
const selectedKeys = ref<TreeProps['selectedKeys']>([]); | ||
const delegatedProps = computed(() => { | ||
const { | ||
expandedKeys: _expandedKeys, | ||
nodeContextMenu: _nodeContextMenu, | ||
'onUpdate:checkedKeys': _updateCheckedKeys, | ||
'onUpdate:expandedKeys': _updateExpandedKeys, | ||
'onUpdate:selectedKeys': _updateSelectedKeys, | ||
selectedKeys: _selectedKeys, | ||
...delegated | ||
} = props; | ||
return delegated; | ||
}); | ||
const forwarded = useForwardProps(delegatedProps); | ||
function onContextMenu(treeKey: string, menuKey: number | string) { | ||
emits('contextMenu', treeKey, menuKey); | ||
} | ||
function selectTree(_: TreeProps['selectedKeys'], $event: any) { | ||
emits('selectTree', $event.node as EventDataNode); | ||
} | ||
</script> | ||
|
||
<template> | ||
<DirectoryTree | ||
v-bind="forwarded" | ||
v-model:expanded-keys="expandedKeys" | ||
v-model:selected-keys="selectedKeys" | ||
:style="{ lineHeight: '30px' }" | ||
:tree-data="treeData" | ||
class="min-w-[160px]" | ||
multiple | ||
/> | ||
show-line | ||
@select="selectTree" | ||
> | ||
<template #icon></template> | ||
<template #title="{ key: treeKey, title }"> | ||
<Dropdown | ||
v-if="nodeContextMenu && nodeContextMenu.length > 0" | ||
:trigger="['contextmenu']" | ||
> | ||
<div>{{ title }}</div> | ||
<template #overlay> | ||
<Menu @click="({ key: menuKey }) => onContextMenu(treeKey, menuKey)"> | ||
<MenuItem v-for="item in nodeContextMenu" :key="item.type"> | ||
{{ item.title }} | ||
</MenuItem> | ||
</Menu> | ||
</template> | ||
</Dropdown> | ||
<div v-else>{{ title }}</div> | ||
</template> | ||
</DirectoryTree> | ||
</template> | ||
|
||
<style lang="scss" scoped></style> | ||
<style scoped> | ||
.ant-tree-treenode-selected::before { | ||
border-radius: 6px; | ||
} | ||
</style> |
15 changes: 15 additions & 0 deletions
15
packages/effects/common-ui/src/components/table/table-tree/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { TreeProps } from 'ant-design-vue'; | ||
|
||
interface NodeContextMenuItem { | ||
title: string; | ||
type: string; | ||
} | ||
|
||
export interface TableTreeProps extends Omit<TreeProps, 'treeData'> { | ||
treeData?: any[]; | ||
nodeContextMenu?: NodeContextMenuItem[]; | ||
} | ||
|
||
export interface TableTreeMethods { | ||
onContextMenu?: (treeKey: string, menuKey: number | string) => void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters