ny
昨天 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
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
53
54
55
56
57
<script lang="ts">
import { computed, defineComponent, h, unref } from 'vue';
 
import { useAttrs } from '@jnpf/hooks';
import { extendSlots } from '@jnpf/utils';
 
import { $t } from '@vben/locales';
 
import { Popconfirm } from 'ant-design-vue';
import { omit } from 'lodash-es';
 
import BasicButton from './AButton.vue';
 
const props = {
  /**
   * Whether to enable the drop-down menu
   * @default: true
   */
  enable: {
    default: true,
    type: Boolean,
  },
};
 
export default defineComponent({
  inheritAttrs: false,
  name: 'PopButton',
  props,
  setup(props, { slots }) {
    const attrs = useAttrs();
 
    // get inherit binding value
    const getBindValues = computed(() => {
      return Object.assign(
        {
          cancelText: $t('common.cancelText'),
          okText: $t('common.okText'),
        },
        { ...props, ...unref(attrs) },
      );
    });
 
    return () => {
      const bindValues = omit(unref(getBindValues), 'icon');
      const btnBind = omit(bindValues, 'title') as Recordable;
      if (btnBind.disabled) btnBind.color = '';
      const Button = h(BasicButton, btnBind, extendSlots(slots));
 
      // If it is not enabled, it is a normal button
      if (!props.enable) {
        return Button;
      }
      return h(Popconfirm, bindValues, { default: () => Button });
    };
  },
});
</script>