1
|
|
-<script lang="ts" setup>
|
2
|
|
- import { Dropdown, Menu, Popconfirm } from 'ant-design-vue';
|
3
|
|
- import { computed, useSlots } from 'vue';
|
4
|
|
- import Icon from '../Icon';
|
5
|
|
- import { usePermission } from '/@/hooks/web/usePermission';
|
6
|
|
-
|
7
|
|
- export interface AuthDropDownProps {
|
8
|
|
- dropMenuList: AuthDropMenuList[];
|
9
|
|
- trigger?: ('contextmenu' | 'click' | 'hover')[];
|
10
|
|
- }
|
11
|
|
-
|
12
|
|
- export interface AuthDropMenuList {
|
13
|
|
- icon?: string;
|
14
|
|
- event: string | number;
|
15
|
|
- text: string;
|
16
|
|
- disabled?: boolean;
|
17
|
|
- divider?: boolean;
|
18
|
|
- auth?: string;
|
19
|
|
- onClick?: Fn;
|
20
|
|
- popconfirm?: {
|
21
|
|
- cancelText?: string;
|
22
|
|
- okText?: string;
|
23
|
|
- okType?: string;
|
24
|
|
- title?: string;
|
25
|
|
- icon?: string;
|
26
|
|
- disabled?: boolean;
|
27
|
|
- onCancel?: Fn;
|
28
|
|
- onConfirm?: Fn;
|
29
|
|
- onVisibleChange?: Fn;
|
30
|
|
- };
|
31
|
|
- }
|
32
|
|
-
|
33
|
|
- const props = defineProps<AuthDropDownProps>();
|
34
|
|
-
|
35
|
|
- const slot = useSlots();
|
36
|
|
-
|
37
|
|
- const { hasPermission } = usePermission();
|
38
|
|
-
|
39
|
|
- const getMenuList = computed(() => {
|
40
|
|
- const { dropMenuList } = props;
|
41
|
|
- return dropMenuList.filter((menu) => (menu.auth ? hasPermission(menu.auth) : true));
|
42
|
|
- });
|
43
|
|
-
|
44
|
|
- const hasDefaultSlot = computed(() => {
|
45
|
|
- return !!slot.default;
|
46
|
|
- });
|
47
|
|
-</script>
|
48
|
|
-
|
49
|
|
-<template>
|
50
|
|
- <Dropdown :trigger="$props.trigger">
|
51
|
|
- <template #overlay>
|
52
|
|
- <Menu v-if="getMenuList.length">
|
53
|
|
- <template v-for="item in getMenuList" :key="item.event">
|
54
|
|
- <Menu.Divider v-if="item.divider" />
|
55
|
|
- <Menu.Item v-if="!item.popconfirm" @click="item.onClick">
|
56
|
|
- <span class="flex justify-center items-center">
|
57
|
|
- <Icon :icon="item.icon" />
|
58
|
|
- <span class="ml-2">{{ item.text }}</span>
|
59
|
|
- </span>
|
60
|
|
- </Menu.Item>
|
61
|
|
- <Menu.Item v-if="item.popconfirm">
|
62
|
|
- <Popconfirm v-bind="item.popconfirm">
|
63
|
|
- <template v-if="item.popconfirm.icon" #icon>
|
64
|
|
- <Icon :icon="item.popconfirm.icon" />
|
65
|
|
- </template>
|
66
|
|
- <span class="flex justify-center items-center">
|
67
|
|
- <Icon :icon="item.icon" />
|
68
|
|
- <span class="ml-2">{{ item.text }}</span>
|
69
|
|
- </span>
|
70
|
|
- </Popconfirm>
|
71
|
|
- </Menu.Item>
|
72
|
|
- </template>
|
73
|
|
- </Menu>
|
74
|
|
- </template>
|
75
|
|
- <Icon
|
76
|
|
- v-if="!hasDefaultSlot"
|
77
|
|
- class="items-center justify-center"
|
78
|
|
- icon="ant-design:ellipsis-outlined"
|
79
|
|
- :class="!getMenuList.length ? '!text-gray-200 !cursor-not-allowed' : ''"
|
80
|
|
- />
|
81
|
|
- <slot name="default"></slot>
|
82
|
|
- </Dropdown>
|
83
|
|
-</template> |
|
1
|
+<script lang="ts" setup>
|
|
2
|
+ import { Dropdown, Menu, Popconfirm } from 'ant-design-vue';
|
|
3
|
+ import { computed, useSlots } from 'vue';
|
|
4
|
+ import Icon from '../Icon';
|
|
5
|
+ import { usePermission } from '/@/hooks/web/usePermission';
|
|
6
|
+
|
|
7
|
+ export interface AuthDropDownProps {
|
|
8
|
+ dropMenuList: AuthDropMenuList[];
|
|
9
|
+ trigger?: ('contextmenu' | 'click' | 'hover')[];
|
|
10
|
+ }
|
|
11
|
+
|
|
12
|
+ export interface AuthDropMenuList {
|
|
13
|
+ icon?: string;
|
|
14
|
+ event: string | number;
|
|
15
|
+ text: string;
|
|
16
|
+ disabled?: boolean;
|
|
17
|
+ divider?: boolean;
|
|
18
|
+ auth?: string;
|
|
19
|
+ onClick?: Fn;
|
|
20
|
+ popconfirm?: {
|
|
21
|
+ cancelText?: string;
|
|
22
|
+ okText?: string;
|
|
23
|
+ okType?: string;
|
|
24
|
+ title?: string;
|
|
25
|
+ icon?: string;
|
|
26
|
+ disabled?: boolean;
|
|
27
|
+ onCancel?: Fn;
|
|
28
|
+ onConfirm?: Fn;
|
|
29
|
+ onVisibleChange?: Fn;
|
|
30
|
+ };
|
|
31
|
+ }
|
|
32
|
+
|
|
33
|
+ const props = defineProps<AuthDropDownProps>();
|
|
34
|
+
|
|
35
|
+ const slot = useSlots();
|
|
36
|
+
|
|
37
|
+ const { hasPermission } = usePermission();
|
|
38
|
+
|
|
39
|
+ const getMenuList = computed(() => {
|
|
40
|
+ const { dropMenuList } = props;
|
|
41
|
+ return dropMenuList.filter((menu) => (menu.auth ? hasPermission(menu.auth) : true));
|
|
42
|
+ });
|
|
43
|
+
|
|
44
|
+ const hasDefaultSlot = computed(() => {
|
|
45
|
+ return !!slot.default;
|
|
46
|
+ });
|
|
47
|
+</script>
|
|
48
|
+
|
|
49
|
+<template>
|
|
50
|
+ <Dropdown :trigger="$props.trigger">
|
|
51
|
+ <template #overlay>
|
|
52
|
+ <Menu v-if="getMenuList.length">
|
|
53
|
+ <template v-for="item in getMenuList" :key="item.event">
|
|
54
|
+ <Menu.Divider v-if="item.divider" />
|
|
55
|
+ <Menu.Item :disabled="item.disabled" v-if="!item.popconfirm" @click="item.onClick">
|
|
56
|
+ <span class="flex justify-center items-center">
|
|
57
|
+ <Icon :icon="item.icon" />
|
|
58
|
+ <span class="ml-2">{{ item.text }}</span>
|
|
59
|
+ </span>
|
|
60
|
+ </Menu.Item>
|
|
61
|
+ <Menu.Item :disabled="item.disabled" v-if="item.popconfirm">
|
|
62
|
+ <Popconfirm v-bind="item.popconfirm">
|
|
63
|
+ <template v-if="item.popconfirm.icon" #icon>
|
|
64
|
+ <Icon :icon="item.popconfirm.icon" />
|
|
65
|
+ </template>
|
|
66
|
+ <span class="flex justify-center items-center">
|
|
67
|
+ <Icon :icon="item.icon" />
|
|
68
|
+ <span class="ml-2">{{ item.text }}</span>
|
|
69
|
+ </span>
|
|
70
|
+ </Popconfirm>
|
|
71
|
+ </Menu.Item>
|
|
72
|
+ </template>
|
|
73
|
+ </Menu>
|
|
74
|
+ </template>
|
|
75
|
+ <Icon
|
|
76
|
+ v-if="!hasDefaultSlot"
|
|
77
|
+ class="items-center justify-center"
|
|
78
|
+ icon="ant-design:ellipsis-outlined"
|
|
79
|
+ :class="!getMenuList.length ? '!text-gray-200 !cursor-not-allowed' : ''"
|
|
80
|
+ />
|
|
81
|
+ <slot name="default"></slot>
|
|
82
|
+ </Dropdown>
|
|
83
|
+</template> |
...
|
...
|
|