Commit a6ef771fcce14c3644c965afaa69b3a17d0a7087
1 parent
4d8e3985
fix(pop-confirm): fix event working unexpected
Showing
2 changed files
with
19 additions
and
3 deletions
CHANGELOG.zh_CN.md
src/components/Dropdown/src/Dropdown.vue
@@ -11,7 +11,10 @@ | @@ -11,7 +11,10 @@ | ||
11 | @click="handleClickMenu(item)" | 11 | @click="handleClickMenu(item)" |
12 | :disabled="item.disabled" | 12 | :disabled="item.disabled" |
13 | > | 13 | > |
14 | - <Popconfirm v-if="popconfirm && item.popConfirm" v-bind="omit(item.popConfirm, 'icon')"> | 14 | + <Popconfirm |
15 | + v-if="popconfirm && item.popConfirm" | ||
16 | + v-bind="getPopConfirmAttrs(item.popConfirm)" | ||
17 | + > | ||
15 | <template #icon v-if="item.popConfirm.icon"> | 18 | <template #icon v-if="item.popConfirm.icon"> |
16 | <Icon :icon="item.popConfirm.icon" /> | 19 | <Icon :icon="item.popConfirm.icon" /> |
17 | </template> | 20 | </template> |
@@ -33,13 +36,14 @@ | @@ -33,13 +36,14 @@ | ||
33 | </template> | 36 | </template> |
34 | 37 | ||
35 | <script lang="ts"> | 38 | <script lang="ts"> |
36 | - import type { PropType } from 'vue'; | 39 | + import { computed, PropType } from 'vue'; |
37 | import type { DropMenu } from './typing'; | 40 | import type { DropMenu } from './typing'; |
38 | 41 | ||
39 | import { defineComponent } from 'vue'; | 42 | import { defineComponent } from 'vue'; |
40 | import { Dropdown, Menu, Popconfirm } from 'ant-design-vue'; | 43 | import { Dropdown, Menu, Popconfirm } from 'ant-design-vue'; |
41 | import { Icon } from '/@/components/Icon'; | 44 | import { Icon } from '/@/components/Icon'; |
42 | import { omit } from 'lodash-es'; | 45 | import { omit } from 'lodash-es'; |
46 | + import { isFunction } from '/@/utils/is'; | ||
43 | 47 | ||
44 | export default defineComponent({ | 48 | export default defineComponent({ |
45 | name: 'BasicDropdown', | 49 | name: 'BasicDropdown', |
@@ -82,9 +86,20 @@ | @@ -82,9 +86,20 @@ | ||
82 | item.onClick?.(); | 86 | item.onClick?.(); |
83 | } | 87 | } |
84 | 88 | ||
89 | + const getPopConfirmAttrs = computed(() => { | ||
90 | + return (attrs) => { | ||
91 | + const originAttrs = omit(attrs, ['confirm', 'cancel', 'icon']); | ||
92 | + if (!attrs.onConfirm && attrs.confirm && isFunction(attrs.confirm)) | ||
93 | + originAttrs['onConfirm'] = attrs.confirm; | ||
94 | + if (!attrs.onCancel && attrs.cancel && isFunction(attrs.cancel)) | ||
95 | + originAttrs['onCancel'] = attrs.cancel; | ||
96 | + return originAttrs; | ||
97 | + }; | ||
98 | + }); | ||
99 | + | ||
85 | return { | 100 | return { |
86 | handleClickMenu, | 101 | handleClickMenu, |
87 | - omit, | 102 | + getPopConfirmAttrs, |
88 | getAttr: (key: string | number) => ({ key }), | 103 | getAttr: (key: string | number) => ({ key }), |
89 | }; | 104 | }; |
90 | }, | 105 | }, |