|
1 | 1 | <script lang="ts"> |
2 | | - import { defineComponent, h, unref } from 'vue'; |
| 2 | + import { defineComponent, h, unref, computed } from 'vue'; |
3 | 3 |
|
4 | 4 | import { Popconfirm } from 'ant-design-vue'; |
5 | 5 | import BasicButton from './BasicButton.vue'; |
6 | 6 | import { propTypes } from '/@/utils/propTypes'; |
7 | 7 | import { useI18n } from '/@/hooks/web/useI18n'; |
8 | 8 | import { extendSlots } from '/@/utils/helper/tsxHelper'; |
9 | 9 | import { omit } from 'lodash-es'; |
10 | | - const { t } = useI18n(); |
11 | 10 |
|
12 | 11 | export default defineComponent({ |
13 | 12 | name: 'PopButton', |
14 | 13 | inheritAttrs: false, |
15 | 14 | components: { Popconfirm, BasicButton }, |
16 | 15 | props: { |
17 | 16 | enable: propTypes.bool.def(true), |
18 | | - okText: propTypes.string.def(t('component.drawer.okText')), |
19 | | - cancelText: propTypes.string.def(t('component.drawer.cancelText')), |
| 17 | + okText: propTypes.string, |
| 18 | + cancelText: propTypes.string, |
20 | 19 | }, |
21 | 20 | setup(props, { slots, attrs }) { |
22 | | - return () => { |
23 | | - const popValues = { ...props, ...unref(attrs) }; |
| 21 | + const { t } = useI18n(); |
24 | 22 |
|
| 23 | + const getBindValues = computed(() => { |
| 24 | + const popValues = Object.assign( |
| 25 | + { |
| 26 | + okText: t('common.okText'), |
| 27 | + cancelText: t('common.cancelText'), |
| 28 | + }, |
| 29 | + { ...props, ...unref(attrs) } |
| 30 | + ); |
| 31 | + return popValues; |
| 32 | + }); |
| 33 | + return () => { |
25 | 34 | const Button = h(BasicButton, omit(unref(attrs), 'icon'), extendSlots(slots)); |
26 | 35 | if (!props.enable) { |
27 | 36 | return Button; |
28 | 37 | } |
29 | 38 |
|
30 | | - return h(Popconfirm, omit(popValues, 'icon'), { default: () => Button }); |
| 39 | + return h(Popconfirm, omit(unref(getBindValues), 'icon'), { default: () => Button }); |
31 | 40 | }; |
32 | 41 | }, |
33 | 42 | }); |
|
0 commit comments