Vben
2021-04-05 3576d0b512d4962c6bad0d574fd1bc1800e01295
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
<script lang="ts">
  import { defineComponent, h, unref, computed } from 'vue';
 
  import { Popconfirm } from 'ant-design-vue';
 
  import BasicButton from './BasicButton.vue';
 
  import { propTypes } from '/@/utils/propTypes';
  import { extendSlots } from '/@/utils/helper/tsxHelper';
  import { omit } from 'lodash-es';
 
  import { useAttrs } from '/@/hooks/core/useAttrs';
  import { useI18n } from '/@/hooks/web/useI18n';
 
  export default defineComponent({
    name: 'PopButton',
    components: { Popconfirm, BasicButton },
    inheritAttrs: false,
    props: {
      size: propTypes.oneOf(['large', 'default', 'small']).def(),
      enable: propTypes.bool.def(true),
      okText: propTypes.string,
      cancelText: propTypes.string,
    },
    setup(props, { slots }) {
      const { t } = useI18n();
      const attrs = useAttrs();
 
      const getBindValues = computed(() => {
        const popValues = Object.assign(
          {
            okText: t('common.okText'),
            cancelText: t('common.cancelText'),
          },
          { ...props, ...unref(attrs) }
        );
        return popValues;
      });
 
      return () => {
        const values = omit(unref(getBindValues), 'icon');
        const Button = h(BasicButton, values, extendSlots(slots));
 
        if (!props.enable) {
          return Button;
        }
 
        return h(Popconfirm, values, { default: () => Button });
      };
    },
  });
</script>