forked from halo-dev/halo
-
Notifications
You must be signed in to change notification settings - Fork 38
/
EntityDropdownItems.vue
66 lines (63 loc) · 1.78 KB
/
EntityDropdownItems.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<script setup lang="ts" generic="T">
import type { EntityDropdownItem } from "@halo-dev/console-shared";
import { VDropdown } from "@halo-dev/components";
const props = withDefaults(
defineProps<{
dropdownItems: EntityDropdownItem<T>[];
item?: T;
}>(),
{
item: undefined,
}
);
function action(dropdownItem: EntityDropdownItem<T>) {
if (!dropdownItem.action) {
return;
}
dropdownItem.action(props.item);
}
</script>
<template>
<template v-for="(dropdownItem, index) in dropdownItems">
<template v-if="dropdownItem.visible">
<VDropdown
v-if="dropdownItem.children?.length"
:key="`dropdown-children-items-${index}`"
v-permission="dropdownItem.permissions"
:triggers="['click']"
>
<component
:is="dropdownItem.component"
v-bind="dropdownItem.props"
@click="action(dropdownItem)"
>
{{ dropdownItem.label }}
</component>
<template #popper>
<template v-for="(childItem, childIndex) in dropdownItem.children">
<component
:is="childItem.component"
v-if="childItem.visible"
v-bind="childItem.props"
:key="`dropdown-child-item-${childIndex}`"
v-permission="childItem.permissions"
@click="action(childItem)"
>
{{ childItem.label }}
</component>
</template>
</template>
</VDropdown>
<component
:is="dropdownItem.component"
v-else
v-bind="dropdownItem.props"
:key="`dropdown-item-${index}`"
v-permission="dropdownItem.permissions"
@click="action(dropdownItem)"
>
{{ dropdownItem.label }}
</component>
</template>
</template>
</template>