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 | 11 | @click="handleClickMenu(item)" |
12 | 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 | 18 | <template #icon v-if="item.popConfirm.icon"> |
16 | 19 | <Icon :icon="item.popConfirm.icon" /> |
17 | 20 | </template> |
... | ... | @@ -33,13 +36,14 @@ |
33 | 36 | </template> |
34 | 37 | |
35 | 38 | <script lang="ts"> |
36 | - import type { PropType } from 'vue'; | |
39 | + import { computed, PropType } from 'vue'; | |
37 | 40 | import type { DropMenu } from './typing'; |
38 | 41 | |
39 | 42 | import { defineComponent } from 'vue'; |
40 | 43 | import { Dropdown, Menu, Popconfirm } from 'ant-design-vue'; |
41 | 44 | import { Icon } from '/@/components/Icon'; |
42 | 45 | import { omit } from 'lodash-es'; |
46 | + import { isFunction } from '/@/utils/is'; | |
43 | 47 | |
44 | 48 | export default defineComponent({ |
45 | 49 | name: 'BasicDropdown', |
... | ... | @@ -82,9 +86,20 @@ |
82 | 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 | 100 | return { |
86 | 101 | handleClickMenu, |
87 | - omit, | |
102 | + getPopConfirmAttrs, | |
88 | 103 | getAttr: (key: string | number) => ({ key }), |
89 | 104 | }; |
90 | 105 | }, | ... | ... |